CoolFace
Modelpublic

sanjeevan7/emnist-letters-eng-resnet18-v2

sourceHugging Faceupdated 1y agoView on Hugging Face
1likes7downloads
Model Card

๐Ÿ“– ResNet-18 Fine-Tuned on EMNIST Letters

This repository contains a ResNet-18 model fine-tuned on the EMNIST Letters dataset for handwritten character recognition (a-z).


๐Ÿ“ Model Details

  • โ€”Architecture: ResNet-18 (pretrained on ImageNet)
  • โ€”Dataset: EMNIST Letters (https://www.nist.gov/itl/products-and-services/emnist-dataset)
  • โ€”Input Size: 224x224 (grayscale, converted to 3 channels)
  • โ€”Classes: 26 lowercase letters (a to z)
  • โ€”Transformations:
  • โ€”Resize to 224x224
  • โ€”Convert to grayscale with 3 channels
  • โ€”Rotate 90ยฐ clockwise
  • โ€”Flip vertically
  • โ€”Normalize with ImageNet mean & std

๐Ÿ› ๏ธ Usage

1๏ธโƒฃ Install Required Libraries

bash
pip install torch torchvision huggingface_hub

2๏ธโƒฃ Load the Model

python
import torch
from torchvision import models
from huggingface_hub import hf_hub_download

# Download model weights
model_path = hf_hub_download("sanjeevan7/emnist-letters-eng-resnet18-v2", filename="pytorch_model.bin")

# Load model architecture
model = models.resnet18()
model.fc = torch.nn.Linear(model.fc.in_features, 26)  # 26 letters

# Load weights
model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')))
model.eval()

๐ŸŽจ Input Preprocessing

python
import torchvision.transforms as transforms
import torchvision.transforms.functional as TF

transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.Grayscale(3),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

๐Ÿงช Inference Example

python
from PIL import Image

# Load and preprocess image
image = Image.open("your_image.png").convert('L')  # Grayscale
input_tensor = transform(image).unsqueeze(0)

# Predict
with torch.no_grad():
    outputs = model(input_tensor)
    _, predicted = torch.max(outputs, 1)

predicted_class = predicted.item()
predicted_char = chr(predicted_class + 97)  # 0->a, 1->b, ...

print(f"Predicted Character: {predicted_char}")

๐Ÿ“Š Performance

  • โ€”Accuracy: \~94% on EMNIST Letters test set
  • โ€”Known Limitations:
  • โ€”Requires correct image orientation (preprocessing handles this)

๐Ÿ“ฅ Files

FileDescription
pytorch_model.binModel weights
config.jsonModel metadata (architecture info)

๐Ÿ“ง Contact

For any questions, please contact Sanjeevan.