Zero-Shot Image Classification
OpenCLIP
Safetensors
English
biology
CV
images
imageomics
clip
species-classification
biological visual task
multimodal
animals
plants
fungi
species
taxonomy
rare species
endangered species
evolutionary biology
knowledge-guided
Instructions to use skram/bioclip-2-endpoint with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- OpenCLIP
How to use skram/bioclip-2-endpoint with OpenCLIP:
import open_clip model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:skram/bioclip-2-endpoint') tokenizer = open_clip.get_tokenizer('hf-hub:skram/bioclip-2-endpoint') - Notebooks
- Google Colab
- Kaggle
Add build/push/deploy instructions for the OpenAI-compatible container
Browse files- container/README.md +49 -0
container/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# BioCLIP-2 OpenAI-compatible custom container
|
| 2 |
+
|
| 3 |
+
Serves BioCLIP 2 (open_clip ViT-L/14, 768-dim) behind OpenAI-style routes so
|
| 4 |
+
`OpenAI(base_url=..., api_key=HF_TOKEN).embeddings.create(...)` works. The
|
| 5 |
+
playground "OpenAI API" toggle may stay greyed (it is engine-driven UI), but
|
| 6 |
+
programmatic OpenAI clients do not need it.
|
| 7 |
+
|
| 8 |
+
Routes:
|
| 9 |
+
- `GET /health` — readiness probe (503 until weights are loaded)
|
| 10 |
+
- `POST /v1/embeddings` (alias `/embeddings`) — OpenAI embeddings schema;
|
| 11 |
+
`input` entries: text, `https://` image URLs, `data:image/...;base64`
|
| 12 |
+
URIs, `{"text": ...}` / `{"image": ...}` dicts; `encoding_format` float|base64
|
| 13 |
+
- `POST /v1/classify` (alias `/classify`) — `{"inputs": {"image": ..., "candidate_labels": [...]}}`
|
| 14 |
+
|
| 15 |
+
The inference logic in `handler.py` is byte-identical to the validated
|
| 16 |
+
handler at the repo root (CPU + GPU fp16 + OpenAI-shim tests all pass).
|
| 17 |
+
|
| 18 |
+
## Build and push (Docker Hub, ECR, ACR, or GCR all work)
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
docker build --platform linux/amd64 -t <dockerhub-user>/bioclip-2-openai:v0.1.0 .
|
| 22 |
+
docker push <dockerhub-user>/bioclip-2-openai:v0.1.0
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
(`--platform linux/amd64` is required if building on an ARM Mac.)
|
| 26 |
+
|
| 27 |
+
## Deploy
|
| 28 |
+
|
| 29 |
+
Inference Endpoints -> Deploy -> select `skram/bioclip-2-endpoint` as the model
|
| 30 |
+
repository (mounted at `/repository`) -> **Custom Container** -> image
|
| 31 |
+
`<dockerhub-user>/bioclip-2-openai:v0.1.0` -> serving port **8000** -> L4 x1
|
| 32 |
+
recommended -> scale to zero -> Deploy.
|
| 33 |
+
|
| 34 |
+
## Client
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from openai import OpenAI
|
| 38 |
+
import os
|
| 39 |
+
|
| 40 |
+
client = OpenAI(
|
| 41 |
+
base_url="https://<endpoint-name>.endpoints.huggingface.cloud/v1/",
|
| 42 |
+
api_key=os.environ["HF_TOKEN"],
|
| 43 |
+
)
|
| 44 |
+
r = client.embeddings.create(model="bioclip-2", input=["a photo of a moth"])
|
| 45 |
+
vec = r.data[0].embedding # 768 floats
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
Images: `input` accepts `{"image": "<url or data-uri>"}` entries (no OpenAI
|
| 49 |
+
standard for image embeddings — this mirrors the vLLM/Jina conventions).
|