A newer version of the Gradio SDK is available:
5.16.0
metadata
title: ResNetonImageNet
emoji: π’
colorFrom: blue
colorTo: blue
sdk: gradio
sdk_version: 5.9.1
app_file: app.py
pinned: false
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
ResNet50 Image Classifier
This is a Gradio web application that uses a trained ResNet50 model to classify images. The application provides real-time predictions with top-3 confidence scores for uploaded images.
Live Demo
Visit the application at [Hugging Face Spaces URL]
Features
- Real-time image classification
- Top-3 predictions with confidence scores
- Support for various image formats
- User-friendly interface
- Detailed prediction logging
- Example images for testing
Using the Application
Quick Start
- Visit the Hugging Face Space
- Upload an image using one of these methods:
- Click the "Upload Image" button
- Drag and drop an image into the input area
- Use the provided example images
Input Requirements
- Supported formats: JPG, PNG, BMP
- Both color and grayscale images accepted
- Images are automatically:
- Resized to 256 pixels
- Center cropped to 224x224
- Normalized using ImageNet statistics
Output Format
The model returns:
- Predicted Class: The most likely class
- Top 3 Predictions: Three most likely classes with confidence scores
Example output:
Predicted Class: dog
Top 3 Predictions:
dog: 95.32%
cat: 3.45%
fox: 1.23%
Technical Details
Model Architecture
- Base model: ResNet50
- Input size: 224x224 pixels
- Output: Class probabilities through softmax
- Model format: PyTorch (.pth)
Image Processing Pipeline
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]
)
])
File Structure
.
βββ app.py # Main application file
βββ requirements.txt # Dependencies
βββ README.md # Documentation
βββ src/
β βββ model_10.pth # Trained model weights
β βββ classes.txt # Class labels
βββ models/
β βββ model_n.pth # other models
βββ examples/ # Example images
βββ example1.jpg
βββ example2.jpg
Deployment Guide
Prerequisites
- Hugging Face account
- Trained ResNet50 model (.pth format)
- Class labels file (classes.txt)
- Example images (optional)
Deployment Steps
Create a new Space:
- Go to huggingface.co/spaces
- Click "Create new Space"
- Select "Gradio" as the SDK
- Use the provided space configuration from this README
Upload required files:
- All files from the File Structure section
- Ensure correct file paths in app.py
The Space will automatically build and deploy
Space Configuration
title: ResNetonImageNet - ResNet50 Image Classifier
emoji: π
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 5.9.1
app_file: app.py
pinned: false
Troubleshooting
Common Issues
Model Loading Errors
- Verify model path in app.py
- Check model format and class count
Image Upload Issues
- Verify supported formats
- Check image file size
Prediction Errors
- First prediction may be slower (model loading)
- Check input image quality
Performance Notes
- CPU inference by default
- GPU supported if available
- Batch processing not supported
- Real-time predictions
Development
Requirements
torch>=2.0.0
torchvision>=0.15.0
gradio>=4.19.2
Pillow>=9.0.0
numpy>=1.21.0
Local Development
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run locally:
python app.py