Instructions to use jramduran/animals10-cnn-scratch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use jramduran/animals10-cnn-scratch with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://jramduran/animals10-cnn-scratch") - Notebooks
- Google Colab
- Kaggle
Animals-10 · CNN from scratch
Classifies a photo into one of 10 animals: butterfly, cat, chicken, cow, dog, elephant, horse, sheep, spider, squirrel.
A small convolutional network trained from scratch (no pre-trained weights): 6 conv layers, batch norm, dropout and global average pooling, ~0.76 M parameters, 90x90 input. It is the baseline the transfer-learning models are compared against.
| Metric (held-out test, n=2618) | Value |
|---|---|
| Accuracy | 0.885 |
| F1 macro | 0.875 |
| Precision (macro) | 0.876 |
| Recall (macro) | 0.875 |
Data: Animals-10, 26,177 photos, stratified split 80/10/10 (train / validation for early stopping / untouched test). The four models of the project share exactly the same split, so their scores are directly comparable.
Training: input 90x90, 41 epochs, on NVIDIA GeForce RTX 5060 Laptop GPU (9.0 min).
Code: https://github.com/JTiiz/CNN-project (training/).
Usage
import os
os.environ["KERAS_BACKEND"] = "torch" # the backend the model was trained and tested with
import json, keras, numpy as np
from huggingface_hub import snapshot_download
from PIL import Image
path = snapshot_download("jramduran/animals10-cnn-scratch")
info = json.load(open(f"{path}/model_info.json"))
model = keras.saving.load_model(f"{path}/model.keras")
size = info["input_size"]
img = Image.open("cat.jpg").convert("RGB").resize((size, size))
x = np.asarray(img, dtype="float32")[None] # raw pixels 0-255, no normalisation
probs = model.predict(x, verbose=0)[0]
print(info["labels"][probs.argmax()], probs.max())
- Downloads last month
- 3
