CoolFace
Modelpublic

Rathnavelu/indian-currency-cnn-yolo

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
1likes7downloads
Model Card

๐Ÿ‡ฎ๐Ÿ‡ณ Indian Currency Detector (CNN + YOLO) โ€” Mobile Optimized

A lightweight, combined YOLOv8-nano + MobileNetV3-Small model for real-time Indian currency detection and denomination classification, optimized for mobile deployment.

๐Ÿ—๏ธ Architecture

Camera Frame โ†’ [YOLOv8-nano] โ†’ Detect & Localize Currency โ†’ [MobileNetV3-Small] โ†’ Classify Denomination
ComponentModelParamsONNX SizePurpose
๐Ÿ” DetectorYOLOv8-nano3.01M11.6 MBLocate currency in frame
๐Ÿท๏ธ ClassifierMobileNetV3-Small1.08M4.4 MBIdentify denomination
๐Ÿ“ฑ TotalCombined Pipeline~4.1M~16 MBEnd-to-end on mobile

๐Ÿ“Š Performance

MetricValue
CNN Classification Accuracy100.00% (all 7 classes)
YOLO mAP@5098.28%
YOLO mAP@50-9568.95%
Inference speed (mobile est.)~25-35ms per frame
Total model size (FP32)~16MB
Total model size (INT8 est.)~5-6MB

๐Ÿ’ฐ Supported Indian Denominations

Currency Notes
โ‚น10
โ‚น20
โ‚น50
โ‚น100
โ‚น200
โ‚น500
โ‚น2000

๐Ÿš€ Usage

Quick Start โ€” Classification Only

python
import torch
from torchvision import models, transforms
from PIL import Image

# Load model
model = models.mobilenet_v3_small()
model.classifier = torch.nn.Sequential(
    torch.nn.Linear(576, 256),
    torch.nn.Hardswish(),
    torch.nn.Dropout(0.3),
    torch.nn.Linear(256, 7)
)
checkpoint = torch.load("mobilenetv3_currency.pth", map_location="cpu")
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()

# Preprocess
transform = transforms.Compose([
    transforms.Resize(256),
    transforms.CenterCrop(224),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])

# Predict
img = Image.open("your_currency_photo.jpg").convert("RGB")
input_tensor = transform(img).unsqueeze(0)
with torch.no_grad():
    output = model(input_tensor)
    class_names = ["โ‚น10", "โ‚น100", "โ‚น20", "โ‚น200", "โ‚น2000", "โ‚น50", "โ‚น500"]
    prediction = class_names[output.argmax(1).item()]
    confidence = torch.softmax(output, 1).max().item()
    print(f"Detected: {prediction} ({confidence:.1%})")

YOLO Detection

python
from ultralytics import YOLO

model = YOLO("yolov8n_currency_best.pt")
results = model("currency_photo.jpg")
results[0].show()

ONNX Inference (Mobile/Edge)

python
import onnxruntime as ort
import numpy as np
from PIL import Image

# CNN Classifier
session = ort.InferenceSession("mobilenetv3_currency.onnx")
img = Image.open("currency.jpg").resize((224, 224))
img_array = np.array(img).astype(np.float32) / 255.0
img_array = (img_array - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
input_data = img_array.transpose(2, 0, 1)[np.newaxis, ...]
outputs = session.run(None, {"input": input_data})
class_names = ["โ‚น10", "โ‚น100", "โ‚น20", "โ‚น200", "โ‚น2000", "โ‚น50", "โ‚น500"]
print(f"Predicted: {class_names[np.argmax(outputs[0])]}")

๐Ÿ“ฑ Mobile Deployment

PlatformFormatCommand
AndroidTFLite INT8model.export(format="tflite", int8=True)
iOSCoreMLmodel.export(format="coreml")
Cross-platformONNXAlready included!
Edge devicesOpenVINOmodel.export(format="openvino")

๐Ÿ“ Files

FileDescriptionSize
mobilenetv3_currency.pthCNN classifier (PyTorch)4.2 MB
mobilenetv3_currency.onnxCNN classifier (ONNX)4.4 MB
yolov8n_currency_best.ptYOLO detector (PyTorch)5.9 MB
yolov8n_currency_best.onnxYOLO detector (ONNX)11.6 MB
config.jsonModel configurationโ€”

๐Ÿ”ฌ Training Details

  • โ€”Base Models: YOLOv8-nano (COCO pretrained) + MobileNetV3-Small (ImageNet pretrained)
  • โ€”Dataset: ViratGarg/currency + ViratGarg/currency2 โ€” 420 images, 7 balanced classes
  • โ€”CNN Training: 30 epochs, AdamW (lr=1e-3), CosineAnnealing LR, label smoothing=0.1
  • โ€”YOLO Training: 30 epochs, SGD (lr=0.01), mosaic augmentation, close_mosaic=10
  • โ€”Augmentation: RandomResizedCrop, ColorJitter, RandomPerspective, RandomErasing, HSV jitter
  • โ€”Hardware: CPU training (works on GPU too for faster training)

Training Recipe (Based on Published Research)

  • โ€”YOLOBench (arxiv:2307.13901): COCO pretrain โ†’ fine-tune strategy
  • โ€”HierLight-YOLO (arxiv:2509.22365): Lightweight detection architecture
  • โ€”Currency CNN paper (arxiv:2509.06331): Augmentation recipe for currency images

โš ๏ธ Limitations

  • โ€”Trained on Indian currency notes only (no coins in current dataset)
  • โ€”Small training set (420 images) โ€” accuracy may vary on edge cases
  • โ€”YOLO bounding boxes are pseudo-annotations (classification โ†’ detection conversion)
  • โ€”For production use, recommend collecting more diverse training data with real bounding box annotations

๐Ÿ“œ License

Apache 2.0