Zero-Shot Image Classification
Transformers
PyTorch
Safetensors
English
clip
vision
language
fashion
ecommerce
Run this model with HF Jobs
Run risedev/test on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/risedev/test. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/risedev/test on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use risedev/test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use risedev/test with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-image-classification", model="risedev/test") pipe( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png", candidate_labels=["animals", "humans", "landscape"], )# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForZeroShotImageClassification processor = AutoProcessor.from_pretrained("risedev/test") model = AutoModelForZeroShotImageClassification.from_pretrained("risedev/test", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from risedev/test: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/risedev/test/resolve/main/handler.py
- Command line
-
hf download hf://risedev/test/handler.py
-
curl -L -o handler.py https://huggingface.co/risedev/test/resolve/main/handler.py
1 kB
| from typing import Dict, List, Any | |
| from PIL import Image | |
| from io import BytesIO | |
| from transformers import pipeline | |
| import base64 | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| self.pipeline=pipeline("zero-shot-image-classification",model=path) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| data args: | |
| parameters: { | |
| candidate_labels: List[str] | |
| } | |
| inputs: str | |
| Return: | |
| A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82} | |
| """ | |
| parameters = data.get("parameters", {}) | |
| inputs = data.get("inputs", "") | |
| # decode base64 image to PIL | |
| image = Image.open(BytesIO(base64.b64decode(inputs))) | |
| # run prediction one image wit provided candiates | |
| prediction = self.pipeline(images=[image], candidate_labels=parameters.get("candidate_labels", [])) | |
| return prediction[0] |