Image Classification
Transformers
TensorBoard
Safetensors
vit
Generated from Trainer
Eval Results (legacy)
Instructions to use Schram03/fruits-classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Schram03/fruits-classification with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="Schram03/fruits-classification") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("Schram03/fruits-classification") model = AutoModelForImageClassification.from_pretrained("Schram03/fruits-classification", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download app.py from Schram03/fruits-classification: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/Schram03/fruits-classification/resolve/main/app.py
- Command line
-
hf download hf://Schram03/fruits-classification/app.py
-
curl -L -o app.py https://huggingface.co/Schram03/fruits-classification/resolve/main/app.py
1.6 kB
| import gradio as gr | |
| from transformers import pipeline | |
| # Load models | |
| vit_classifier = pipeline("image-classification", model="Schram03/fruits-classification") | |
| clip_detector = pipeline(model="openai/clip-vit-large-patch14", task="zero-shot-image-classification") | |
| labels_fruits = [ | |
| 'Apple', 'Apricot', 'Avocado', 'Banana', 'Blackberry', 'Blueberry', 'Cactus fruit', 'Cherry', 'Clementine', 'Cocos', 'Grape', 'Grapefruit', 'Guava', 'Kaki', 'Kiwi', 'Lemon', 'Limes', 'Lychee', 'Mandarine', 'Mango', 'Maracuja', 'Nectarine', 'Orange', 'Papaya', 'Passion Fruit', 'Peach', 'Pear', 'Pineapple', 'Plum', 'Pomegranate', 'Quince', 'Strawberry', 'Watermelon' | |
| ] | |
| def classify_fruit(image): | |
| vit_results = vit_classifier(image) | |
| vit_output = {result['label']: result['score'] for result in vit_results} | |
| clip_results = clip_detector(image, candidate_labels=labels_fruits) | |
| clip_output = {result['label']: result['score'] for result in clip_results} | |
| return {"ViT Classification": vit_output, "CLIP Zero-Shot Classification": clip_output} | |
| example_images = [ | |
| ["example_images/apple.jpg"], | |
| ["example_images/blueberry.jpg"], | |
| ["example_images/lemon.jpg"], | |
| ["example_images/pear.jpg"], | |
| ["example_images/plum.jpg"], | |
| ["example_images/watermelon.jpg"] | |
| ] | |
| iface = gr.Interface( | |
| fn=classify_fruit, | |
| inputs=gr.Image(type="filepath"), | |
| outputs=gr.JSON(), | |
| title="Fruit Classification Comparison", | |
| description="Upload an image of a fruit, and compare results from a trained ViT model and a zero-shot CLIP model.", | |
| examples=example_images | |
| ) | |
| iface.launch() |