deploy the compressed model file
Browse files- README.md +27 -1
- predict.py +1 -1
README.md
CHANGED
@@ -12,5 +12,31 @@ pinned: false
|
|
12 |
|
13 |
# AML 16
|
14 |
|
15 |
-
This is a
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# AML 16
|
14 |
|
15 |
+
This is a demo application for the best-performing model (Swin-Large) created for the AML 16 project.
|
16 |
+
The app uses Gradio to provide an interactive interface where users can upload an image, view the top-1 predicted scene category, see a reference image from the predicted class, and explore the top-5 prediction probabilities in a bar chart.
|
17 |
|
18 |
+
The model was trained for scene classification and deployed using Hugging Face Spaces.
|
19 |
+
|
20 |
+
- predict.py
|
21 |
+
This file handles loading the trained Swin-Large model and making predictions.
|
22 |
+
It loads the model weights from Hugging Face Hub, applies the correct image preprocessing, and outputs:
|
23 |
+
|
24 |
+
The uploaded image,
|
25 |
+
|
26 |
+
A reference image from the predicted class,
|
27 |
+
|
28 |
+
The Top-5 prediction probabilities.
|
29 |
+
|
30 |
+
The model was customized with an updated classifier head, and class labels are loaded from a labels.json file. A random sample image from the predicted class folder is also shown for better visualization.
|
31 |
+
|
32 |
+
- app.py
|
33 |
+
This file builds the Gradio interface.
|
34 |
+
It lets users upload an image, runs the prediction using predict.py, and displays:
|
35 |
+
|
36 |
+
The uploaded image,
|
37 |
+
|
38 |
+
An image for the top-1 predicted class,
|
39 |
+
|
40 |
+
The predicted class label,
|
41 |
+
|
42 |
+
A bar chart showing the Top-5 prediction probabilities.
|
predict.py
CHANGED
@@ -36,7 +36,7 @@ class SwinCustom(nn.Module):
|
|
36 |
outputs = self.model(images)
|
37 |
return outputs.logits
|
38 |
|
39 |
-
model_path = hf_hub_download(repo_id="Noha90/AML_16", filename="
|
40 |
print("Model path:", model_path)
|
41 |
model = SwinCustom(model_name=MODEL_NAME, num_classes=40)
|
42 |
state_dict = torch.load(model_path, map_location="cpu")
|
|
|
36 |
outputs = self.model(images)
|
37 |
return outputs.logits
|
38 |
|
39 |
+
model_path = hf_hub_download(repo_id="Noha90/AML_16", filename="swin_large_quantised.pth")
|
40 |
print("Model path:", model_path)
|
41 |
model = SwinCustom(model_name=MODEL_NAME, num_classes=40)
|
42 |
state_dict = torch.load(model_path, map_location="cpu")
|