Instructions to use rossheaton/british-birds-vit-base-patch16-224 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use rossheaton/british-birds-vit-base-patch16-224 with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://rossheaton/british-birds-vit-base-patch16-224") - Notebooks
- Google Colab
- Kaggle
Commit ·
bab94c2
1
Parent(s): 00069d2
Update README with final paths
Browse files
README.md
CHANGED
|
@@ -1,81 +1,100 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
tags:
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
library_name: keras
|
| 12 |
metrics:
|
| 13 |
-
|
| 14 |
---
|
| 15 |
|
| 16 |
# British Birds Vision Transformer (ViT)
|
| 17 |
|
| 18 |
-
This repository contains a fine-tuned Vision Transformer (ViT) model designed to classify images of 224 common British bird species.
|
| 19 |
|
| 20 |
The model was fine-tuned from the `vit_base_patch16_224_imagenet21k` backbone using Keras 3.
|
| 21 |
|
| 22 |
## Dataset
|
| 23 |
-
|
| 24 |
-
The dataset comprises **224 classes** with exactly **500 image samples per class** (112,000 images total).
|
| 25 |
Images were sourced from [eBird](https://ebird.org/) on February 28, 2026, using the [Birdhouse](https://github.com/rossheat/birdhouse) CLI tool, strictly filtering for the Great Britain region (`--region=GB`), highly rated images (`--min-avg-rating=4`), and extensively reviewed images (`--min-reviews=2`).
|
| 26 |
|
| 27 |
The data was split:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
- **Test:** 10% (11,200 images)
|
| 32 |
|
| 33 |
## Model Performance
|
| 34 |
-
|
| 35 |
Evaluated on the 10% unseen Test Set:
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
- **Loss:** 0.5567
|
| 40 |
|
| 41 |
## Files included
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
- `model/224c_500i_GB_bird_vit_float32.tflite`: Float32 TFLite model for mobile/edge deployment.
|
| 45 |
-
- `model/224c_500i_GB_bird_vit_quantized.tflite`: INT8 Quantized TFLite model for highly optimized edge deployment.
|
| 46 |
-
- `model/224c_500i_GB_bird_classes.json`: Ordered list of the 224 eBird taxon codes representing the classes.
|
| 47 |
-
- `model/friendly_class_names.csv`: Mapping of taxon codes to friendly bird names.
|
| 48 |
-
- `training/british-birds-vit-training.ipynb`: The Jupyter Notebook used to train the model.
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
```python
|
| 53 |
import keras
|
| 54 |
import numpy as np
|
| 55 |
import json
|
|
|
|
| 56 |
from huggingface_hub import hf_hub_download
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
|
|
|
| 61 |
model = keras.models.load_model(model_path)
|
| 62 |
-
with open(labels_path, 'r') as f:
|
| 63 |
-
class_names = json.load(f)
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
image_path = "path/to/bird/image.jpg"
|
| 66 |
img = keras.utils.load_img(image_path, target_size=(224, 224))
|
| 67 |
img_array = keras.utils.img_to_array(img)
|
| 68 |
img_array = np.expand_dims(img_array, axis=0)
|
| 69 |
|
|
|
|
| 70 |
predictions = model.predict(img_array)
|
| 71 |
predicted_index = np.argmax(predictions)
|
| 72 |
confidence = predictions[0][predicted_index] * 100
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
```
|
| 76 |
|
| 77 |
## Training Details
|
| 78 |
-
|
| 79 |
- Optimiser: AdamW (Learning Rate: 1e-4, Weight Decay: 0.01)
|
| 80 |
- Loss: Sparse Categorical Crossentropy
|
| 81 |
- Epochs: 8 (Saved best weights based on Validation Accuracy from Epoch 7)
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
tags:
|
| 4 |
+
- vision
|
| 5 |
+
- image-classification
|
| 6 |
+
- keras
|
| 7 |
+
- tflite
|
| 8 |
+
- biology
|
| 9 |
+
- ornithology
|
| 10 |
+
- vit
|
| 11 |
library_name: keras
|
| 12 |
metrics:
|
| 13 |
+
- accuracy
|
| 14 |
---
|
| 15 |
|
| 16 |
# British Birds Vision Transformer (ViT)
|
| 17 |
|
| 18 |
+
This repository contains a fine-tuned Vision Transformer (ViT) model designed to classify images of 224 common British bird species.
|
| 19 |
|
| 20 |
The model was fine-tuned from the `vit_base_patch16_224_imagenet21k` backbone using Keras 3.
|
| 21 |
|
| 22 |
## Dataset
|
| 23 |
+
The dataset comprises **224 classes** with exactly **500 image samples per class** (112,000 images total).
|
|
|
|
| 24 |
Images were sourced from [eBird](https://ebird.org/) on February 28, 2026, using the [Birdhouse](https://github.com/rossheat/birdhouse) CLI tool, strictly filtering for the Great Britain region (`--region=GB`), highly rated images (`--min-avg-rating=4`), and extensively reviewed images (`--min-reviews=2`).
|
| 25 |
|
| 26 |
The data was split:
|
| 27 |
+
* **Training:** 80% (89,600 images)
|
| 28 |
+
* **Validation:** 10% (11,200 images)
|
| 29 |
+
* **Test:** 10% (11,200 images)
|
|
|
|
| 30 |
|
| 31 |
## Model Performance
|
|
|
|
| 32 |
Evaluated on the 10% unseen Test Set:
|
| 33 |
+
* **Final Test Accuracy:** 85.76%
|
| 34 |
+
* **Top-3 Accuracy:** 94.03%
|
| 35 |
+
* **Loss:** 0.5567
|
|
|
|
| 36 |
|
| 37 |
## Files included
|
| 38 |
+
* `model/final_224c_500i_GB_bird_vit.keras`: The full Keras 3 model.
|
| 39 |
+
* `model/224c_500i_GB_bird_vit_float32.tflite`: Float32 TFLite model for mobile/edge deployment.
|
| 40 |
+
* `model/224c_500i_GB_bird_vit_quantized.tflite`: INT8 Quantized TFLite model for optimized edge deployment.
|
| 41 |
+
* `model/224c_500i_GB_bird_classes.json`: Ordered list of the 224 eBird taxon codes representing the classes.
|
| 42 |
+
* `model/friendly_class_names.csv`: Mapping of taxon codes to friendly human-readable bird names.
|
| 43 |
+
* `training/british-birds-vit-training.ipynb`: The Jupyter Notebook used to train the model.
|
| 44 |
|
| 45 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
The following snippet demonstrates how to download the model, process an image, and use the included CSV file to output a human-readable English bird name (e.g., "Arctic Skua") rather than the raw eBird taxon code (e.g., "parjae").
|
| 48 |
|
| 49 |
```python
|
| 50 |
import keras
|
| 51 |
import numpy as np
|
| 52 |
import json
|
| 53 |
+
import csv
|
| 54 |
from huggingface_hub import hf_hub_download
|
| 55 |
|
| 56 |
+
REPO_ID = "rossheaton/british-birds-vit-base-patch16-224"
|
| 57 |
+
|
| 58 |
+
# Download model, class codes, and the friendly names CSV
|
| 59 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename="model/final_224c_500i_GB_bird_vit.keras")
|
| 60 |
+
labels_path = hf_hub_download(repo_id=REPO_ID, filename="model/224c_500i_GB_bird_classes.json")
|
| 61 |
+
csv_path = hf_hub_download(repo_id=REPO_ID, filename="model/friendly_class_names.csv")
|
| 62 |
|
| 63 |
+
# Load the Keras model
|
| 64 |
model = keras.models.load_model(model_path)
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
# Load taxon codes (the raw array of classes)
|
| 67 |
+
with open(labels_path, 'r') as f:
|
| 68 |
+
taxon_codes = json.load(f)
|
| 69 |
+
|
| 70 |
+
# Build a dictionary mapping taxon codes to friendly names
|
| 71 |
+
taxon_to_friendly = {}
|
| 72 |
+
with open(csv_path, mode='r', encoding='utf-8') as f:
|
| 73 |
+
reader = csv.DictReader(f)
|
| 74 |
+
for row in reader:
|
| 75 |
+
# Maps e.g. "parjae" -> "Arctic Skua - Stercorarius parasiticus"
|
| 76 |
+
# Note: Change 'ebird_search_term' to 'rspb_name' if you prefer just the short English name
|
| 77 |
+
taxon_to_friendly[row['ebird_taxon_code']] = row['ebird_search_term']
|
| 78 |
+
|
| 79 |
+
# Load and preprocess a local image
|
| 80 |
image_path = "path/to/bird/image.jpg"
|
| 81 |
img = keras.utils.load_img(image_path, target_size=(224, 224))
|
| 82 |
img_array = keras.utils.img_to_array(img)
|
| 83 |
img_array = np.expand_dims(img_array, axis=0)
|
| 84 |
|
| 85 |
+
# Predict
|
| 86 |
predictions = model.predict(img_array)
|
| 87 |
predicted_index = np.argmax(predictions)
|
| 88 |
confidence = predictions[0][predicted_index] * 100
|
| 89 |
|
| 90 |
+
# Get the raw taxon code, then look up the friendly name
|
| 91 |
+
predicted_taxon = taxon_codes[predicted_index]
|
| 92 |
+
friendly_name = taxon_to_friendly.get(predicted_taxon, predicted_taxon) # Fallback to taxon code if missing
|
| 93 |
+
|
| 94 |
+
print(f"Prediction: {friendly_name} ({confidence:.2f}% confidence)")
|
| 95 |
```
|
| 96 |
|
| 97 |
## Training Details
|
|
|
|
| 98 |
- Optimiser: AdamW (Learning Rate: 1e-4, Weight Decay: 0.01)
|
| 99 |
- Loss: Sparse Categorical Crossentropy
|
| 100 |
- Epochs: 8 (Saved best weights based on Validation Accuracy from Epoch 7)
|