File size: 3,953 Bytes
f830a43
 
 
 
 
 
 
 
 
 
 
 
d67c1ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
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
1. Visit the Hugging Face Space
2. 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:
1. **Predicted Class**: The most likely class
2. **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
```python
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
1. Hugging Face account
2. Trained ResNet50 model (.pth format)
3. Class labels file (classes.txt)
4. Example images (optional)

### Deployment Steps
1. 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

2. Upload required files:
   - All files from the File Structure section
   - Ensure correct file paths in app.py

3. The Space will automatically build and deploy


### Space Configuration
```yaml
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
1. **Model Loading Errors**
   - Verify model path in app.py
   - Check model format and class count

2. **Image Upload Issues**
   - Verify supported formats
   - Check image file size

3. **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
1. Clone the repository
2. Install dependencies:
   ```bash
   pip install -r requirements.txt
   ```
3. Run locally:
   ```bash
   python app.py
   ```

## Support

- GitHub Issues: [Repository URL]
- Hugging Face Forum: [Forum URL]
- Documentation: [Docs URL]