Instructions to use Maximaxou2/french-trees-vit-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use Maximaxou2/french-trees-vit-small with timm:
import timm model = timm.create_model("hf-hub:Maximaxou2/french-trees-vit-small", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Download example.py from Maximaxou2/french-trees-vit-small: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/Maximaxou2/french-trees-vit-small/resolve/main/example.py
- Command line
-
hf download hf://Maximaxou2/french-trees-vit-small/example.py
-
curl -L -o example.py https://huggingface.co/Maximaxou2/french-trees-vit-small/resolve/main/example.py
1 kB
| """Identify a tree from a photo. | |
| pip install timm torch pillow huggingface_hub | |
| python example.py photo.jpg | |
| """ | |
| import json | |
| import sys | |
| import timm | |
| import torch | |
| from huggingface_hub import hf_hub_download | |
| from PIL import Image | |
| REPO_ID = "Maximaxou2/french-trees-vit-small" | |
| model = timm.create_model(f"hf-hub:{REPO_ID}", pretrained=True).eval() | |
| transform = timm.data.create_transform(**timm.data.resolve_data_config({}, model=model)) | |
| labels = json.load(open(hf_hub_download(REPO_ID, "labels.json"), encoding="utf8")) | |
| # Calibrated temperature: makes the percentages honest (fitted on the validation split). | |
| temperature = json.load(open(hf_hub_download(REPO_ID, "config.json"))).get("temperature", 1.0) | |
| image = Image.open(sys.argv[1]).convert("RGB") | |
| with torch.no_grad(): | |
| probs = (model(transform(image).unsqueeze(0)) / temperature).softmax(-1)[0] | |
| for p, i in zip(*probs.topk(3)): | |
| label = labels[i] | |
| print(f"{p:6.1%} {label['latin']:28} {label['fr']}") | |