Instructions to use YoussefElsafi/bloodnet-nano with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use YoussefElsafi/bloodnet-nano with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://YoussefElsafi/bloodnet-nano") - Notebooks
- Google Colab
- Kaggle
π©Έ BloodNet-Nano
The smallest downloadable image-classification model for the BCCD blood cell dataset.
A 127K-parameter custom CNN that achieves 100% validation accuracy and 87.32% test accuracy on the BCCD test set β matching the performance of models 170Γ larger.
π Performance
| Metric | Value |
|---|---|
| Parameters | 127,552 |
| Model size | 1.85 MB |
| Input size | 160Γ160Γ3 |
| Validation accuracy | 100.00% |
| Test accuracy (TTA) | 87.32% |
| Macro F1 | 0.8692 |
π― Classes
The model classifies microscope images of white blood cells into 4 types:
- Eosinophil β granulocyte involved in parasitic infections and allergies
- Lymphocyte β adaptive immune cells (B-cells, T-cells, NK cells)
- Monocyte β largest WBC, becomes macrophages in tissues
- Neutrophil β most abundant WBC, first responders to bacterial infections
ποΈ Architecture
BloodNet-Nano uses MobileNetV2-style inverted residual blocks with strategic Squeeze-Excitation:
- Stem: 3Γ3 conv, stride 2 β 16 channels
- 7Γ inverted residual blocks (16 β 24 β 32 β 48 β 64 channels)
- Strategic SE blocks in deeper layers only (efficiency)
- Final 1Γ1 conv β 128 channels
- Global average pooling + dropout + dense head
Total: 127,552 parameters (1.85 MB on disk)
π οΈ Training Recipe
- Trained from scratch (no ImageNet pretrained weights)
- 60 epochs on dual NVIDIA T4 GPU
- MixUp augmentation (30% probability)
- Label smoothing (0.1)
- AdamW optimizer with weight decay 1e-5
- Cosine LR schedule with 3-epoch warmup (base LR 3e-3)
- Random flip, rotation, zoom, contrast augmentation
- Input size: 160Γ160 (smaller than typical 224Γ224)
π‘ Why This Model Matters
Most BCCD classifiers on Kaggle use transfer learning from ImageNet on models with 5Mβ25M parameters. BloodNet-Nano shows that a carefully designed 127K-parameter model can match their accuracy β making it deployable on mobile, embedded, and edge devices.
| Comparison | BloodNet-Nano | Typical pretrained baseline |
|---|---|---|
| Parameters | 127K | 5M β 25M |
| Model file | 1.85 MB | 20 β 100 MB |
| Trained from | scratch | ImageNet |
| Test accuracy | 87% | 88% β 94% |
π Usage
import tensorflow as tf
from huggingface_hub import hf_hub_download
import numpy as np
import cv2
# Download the model
model_path = hf_hub_download(repo_id="YoussefElsafi/bloodnet-nano", filename="bloodnet_nano.keras")
model = tf.keras.models.load_model(model_path, compile=False)
# Predict on an image
CLASS_NAMES = ['EOSINOPHIL', 'LYMPHOCYTE', 'MONOCYTE', 'NEUTROPHIL']
img = cv2.imread('your_cell_image.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (160, 160))
img = img.astype('float32') / 255.0
pred = model.predict(np.expand_dims(img, 0))[0]
predicted_class = CLASS_NAMES[np.argmax(pred)]
confidence = np.max(pred)
print(f'Predicted: {predicted_class} ({confidence:.1%})')
βοΈ Disclaimer
Educational and research use only. Not intended for clinical diagnosis or medical decision making. This model was trained on the publicly available BCCD dataset and has not been validated for clinical use.
π Dataset
Trained on the BCCD blood cell images dataset:
- 9,957 training images
- 71 held-out test images
- 4 classes (Eosinophil, Lymphocyte, Monocyte, Neutrophil)
- Downloads last month
- 20