Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,21 @@ import torch
|
|
| 3 |
from torch import nn
|
| 4 |
from torchvision import models, transforms
|
| 5 |
from PIL import Image
|
|
|
|
| 6 |
|
| 7 |
-
# Load the model
|
| 8 |
model_id = "KabeerAmjad/food_classification_model"
|
| 9 |
-
|
| 10 |
-
model
|
| 11 |
-
model.
|
|
|
|
|
|
|
|
|
|
| 12 |
model.eval()
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
# Define the same preprocessing used during training
|
| 15 |
transform = transforms.Compose([
|
| 16 |
transforms.Resize((224, 224)),
|
|
@@ -43,3 +50,4 @@ iface = gr.Interface(
|
|
| 43 |
|
| 44 |
# Launch the app
|
| 45 |
iface.launch()
|
|
|
|
|
|
| 3 |
from torch import nn
|
| 4 |
from torchvision import models, transforms
|
| 5 |
from PIL import Image
|
| 6 |
+
from transformers import AutoFeatureExtractor
|
| 7 |
|
| 8 |
+
# Load the model from Hugging Face model hub
|
| 9 |
model_id = "KabeerAmjad/food_classification_model"
|
| 10 |
+
# Load ResNet50 model and adjust the final layer
|
| 11 |
+
model = models.resnet50(pretrained=False)
|
| 12 |
+
model.fc = nn.Linear(model.fc.in_features, 11) # Adjust the output layer to match your number of classes
|
| 13 |
+
|
| 14 |
+
# Load the weights from the Hugging Face model hub
|
| 15 |
+
model.load_state_dict(torch.hub.load_state_dict_from_url(f"https://huggingface.co/{model_id}/resolve/main/food_classification_model.pth"))
|
| 16 |
model.eval()
|
| 17 |
|
| 18 |
+
# Load the feature extractor
|
| 19 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
|
| 20 |
+
|
| 21 |
# Define the same preprocessing used during training
|
| 22 |
transform = transforms.Compose([
|
| 23 |
transforms.Resize((224, 224)),
|
|
|
|
| 50 |
|
| 51 |
# Launch the app
|
| 52 |
iface.launch()
|
| 53 |
+
|