Spaces:
Sleeping
Sleeping
Docs: Updated documentation
Browse files
README.md
CHANGED
@@ -11,16 +11,79 @@ pinned: false
|
|
11 |
|
12 |
# ResNet50 trained on ImageNet-1K
|
13 |
|
14 |
-
|
15 |
|
16 |
-
## Model
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
##
|
21 |
|
22 |
-
1.
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
```python
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# ResNet50 trained on ImageNet-1K
|
13 |
|
14 |
+
This is a ResNet50 model trained on ImageNet-1K dataset with 1000 classes. The model can classify a wide variety of images into 1000 different categories.
|
15 |
|
16 |
+
## Model Details
|
17 |
|
18 |
+
- Architecture: ResNet50
|
19 |
+
- Dataset: ImageNet-1K
|
20 |
+
- Classes: 1000
|
21 |
+
- Input Size: 224x224 pixels
|
22 |
+
- Model File: `resnet50_imagenet1k.pth`
|
23 |
+
- Training Repository: [Link](https://github.com/pradeep6kumar/ImageNet_v4)
|
24 |
|
25 |
+
## Quick Start
|
26 |
|
27 |
+
1. Clone the repository:
|
28 |
+
```bash
|
29 |
+
git clone https://huggingface.co/spaces/Shilpaj/ImageNet
|
30 |
+
cd ImageNet
|
31 |
+
```
|
32 |
+
|
33 |
+
2. Download the model:
|
34 |
+
```bash
|
35 |
+
# Option 1: Using wget
|
36 |
+
wget https://huggingface.co/spaces/Shilpaj/ImageNet/blob/main/resnet50_imagenet1k.pth
|
37 |
+
|
38 |
+
# Option 2: Manual download
|
39 |
+
Download from: https://huggingface.co/spaces/Shilpaj/ImageNet/tree/main/resnet50_imagenet1k.pth
|
40 |
+
```
|
41 |
+
|
42 |
+
3. Install requirements:
|
43 |
+
```bash
|
44 |
+
pip install -r requirements.txt
|
45 |
+
```
|
46 |
+
|
47 |
+
4. Run the demo:
|
48 |
+
```bash
|
49 |
+
python app.py
|
50 |
+
```
|
51 |
+
|
52 |
+
## Usage in Your Project
|
53 |
|
54 |
```python
|
55 |
+
from inference import ImageNetClassifier
|
56 |
+
|
57 |
+
# Initialize the classifier
|
58 |
+
classifier = ImageNetClassifier('resnet50_imagenet1k.pth')
|
59 |
+
|
60 |
+
# Classify an image
|
61 |
+
image_path = 'path/to/your/image.jpg'
|
62 |
+
prediction, confidence = classifier.predict(image_path)
|
63 |
+
print(f"Prediction: {prediction}")
|
64 |
+
print(f"Confidence: {confidence:.2f}%")
|
65 |
+
```
|
66 |
+
|
67 |
+
## Example Images
|
68 |
+
|
69 |
+
The `assets/examples` directory contains sample images for testing:
|
70 |
+
- Bird
|
71 |
+
- Car
|
72 |
+
- Cat
|
73 |
+
- Dog
|
74 |
+
- Frog
|
75 |
+
- Horse
|
76 |
+
- Plane
|
77 |
+
- Ship
|
78 |
+
- Truck
|
79 |
+
|
80 |
+
## Repository Structure
|
81 |
+
|
82 |
+
```
|
83 |
+
.
|
84 |
+
βββ app.py # Gradio web interface
|
85 |
+
βββ inference.py # Model inference code
|
86 |
+
βββ requirements.txt # Python dependencies
|
87 |
+
βββ assets/
|
88 |
+
βββ examples/ # Example images for testing
|
89 |
+
```
|
app.py
CHANGED
@@ -114,14 +114,26 @@ def main():
|
|
114 |
with gr.Blocks() as demo:
|
115 |
gr.Markdown(
|
116 |
"""
|
117 |
-
#
|
|
|
118 |
"""
|
119 |
)
|
120 |
|
121 |
-
with gr.Tab("
|
122 |
gr.Markdown(
|
123 |
"""
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
"""
|
126 |
)
|
127 |
|
@@ -183,12 +195,6 @@ def main():
|
|
183 |
|
184 |
# Examples section for Gradio 5.x
|
185 |
examples = [
|
186 |
-
# [
|
187 |
-
# "assets/examples/dog.jpg",
|
188 |
-
# 0.5, # alpha slider
|
189 |
-
# 3, # top_k slider
|
190 |
-
# 4 # target_layer slider
|
191 |
-
# ],
|
192 |
[
|
193 |
"assets/examples/cat.jpg",
|
194 |
0.5,
|
@@ -207,12 +213,6 @@ def main():
|
|
207 |
3,
|
208 |
4
|
209 |
],
|
210 |
-
# [
|
211 |
-
# "assets/examples/shark-plane.jpg",
|
212 |
-
# 0.5,
|
213 |
-
# 3,
|
214 |
-
# 4
|
215 |
-
# ],
|
216 |
[
|
217 |
"assets/examples/car.jpg",
|
218 |
0.5,
|
|
|
114 |
with gr.Blocks() as demo:
|
115 |
gr.Markdown(
|
116 |
"""
|
117 |
+
# ResNet50 trained on ImageNet-1K
|
118 |
+
A large-scale image classification dataset with 1.2 million training images across 1,000 object categories.
|
119 |
"""
|
120 |
)
|
121 |
|
122 |
+
with gr.Tab("Predictions & GradCAM"):
|
123 |
gr.Markdown(
|
124 |
"""
|
125 |
+
View model predictions and visualize where the model is looking using GradCAM.
|
126 |
+
|
127 |
+
## Steps to use:
|
128 |
+
1. Upload an image or select one from the examples below
|
129 |
+
2. Adjust the sliders (optional):
|
130 |
+
- Activation Map Transparency: Controls the blend between original image and activation map
|
131 |
+
- Number of Top Predictions: How many top class predictions to show
|
132 |
+
- Target Layer Number: Which network layer to visualize (deeper layers show higher-level features)
|
133 |
+
3. Click "Generate GradCAM" to run the model
|
134 |
+
4. View the results:
|
135 |
+
- Left: Original uploaded image
|
136 |
+
- Right: Model predictions and GradCAM visualization showing where the model focused
|
137 |
"""
|
138 |
)
|
139 |
|
|
|
195 |
|
196 |
# Examples section for Gradio 5.x
|
197 |
examples = [
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
[
|
199 |
"assets/examples/cat.jpg",
|
200 |
0.5,
|
|
|
213 |
3,
|
214 |
4
|
215 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
[
|
217 |
"assets/examples/car.jpg",
|
218 |
0.5,
|