Image Classification
Transformers
ONNX
Safetensors
English
efficientnet
biology
vision
Eval Results (legacy)
Instructions to use chriamue/bird-species-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use chriamue/bird-species-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="chriamue/bird-species-classifier") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("chriamue/bird-species-classifier") model = AutoModelForImageClassification.from_pretrained("chriamue/bird-species-classifier", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
| import torch | |
| import urllib.request | |
| from PIL import Image | |
| from datasets import load_dataset | |
| from transformers import EfficientNetImageProcessor, EfficientNetForImageClassification | |
| dataset = load_dataset("chriamue/bird-species-dataset") | |
| ##### | |
| labels = dataset["test"].features["label"].names | |
| label2id, id2label = dict(), dict() | |
| for i, label in enumerate(labels): | |
| label2id[label] = str(i) | |
| id2label[str(i)] = label | |
| preprocessor = EfficientNetImageProcessor.from_pretrained("google/efficientnet-b2") | |
| model = EfficientNetForImageClassification.from_pretrained("chriamue/bird-species-classifier", num_labels=len( | |
| labels), id2label=id2label, label2id=label2id, ignore_mismatched_sizes=True) | |
| image = dataset["validation"][0]["image"] | |
| url = 'https://upload.wikimedia.org/wikipedia/commons/a/a9/Common_Blackbird.jpg' | |
| image = Image.open(urllib.request.urlretrieve(url)[0]) | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| model = model.to(device) | |
| inputs = preprocessor(image, return_tensors="pt") | |
| inputs = {k: v.to(device) for k, v in inputs.items()} | |
| with torch.no_grad(): | |
| logits = model(**inputs).logits | |
| predicted_label = logits.argmax(-1).item() | |
| print(labels[predicted_label]) | |