Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,25 @@ from efficientnet_pytorch import EfficientNet
|
|
4 |
from huggingface_hub import HfFileSystem
|
5 |
from PIL import Image
|
6 |
|
7 |
-
# Authenticate and download the
|
8 |
fs = HfFileSystem()
|
9 |
model_path = 'dhhd255/efficientnet_b3/efficientnet_b3.pt'
|
10 |
with fs.open(model_path, 'rb') as f:
|
11 |
model_content = f.read()
|
12 |
|
13 |
-
# Save the model file to disk
|
14 |
-
|
|
|
15 |
f.write(model_content)
|
16 |
|
17 |
-
# Load
|
18 |
model = EfficientNet.from_pretrained('efficientnet-b3')
|
19 |
-
model.load_state_dict(torch.load(
|
|
|
|
|
|
|
|
|
|
|
20 |
model.eval()
|
21 |
|
22 |
# Define a function that takes an image as input and uses the model for inference
|
|
|
4 |
from huggingface_hub import HfFileSystem
|
5 |
from PIL import Image
|
6 |
|
7 |
+
# Authenticate and download the EfficientNet model from Hugging Face Spaces
|
8 |
fs = HfFileSystem()
|
9 |
model_path = 'dhhd255/efficientnet_b3/efficientnet_b3.pt'
|
10 |
with fs.open(model_path, 'rb') as f:
|
11 |
model_content = f.read()
|
12 |
|
13 |
+
# Save the EfficientNet model file to disk
|
14 |
+
efficientnet_model_file = 'efficientnet_b3.pt'
|
15 |
+
with open(efficientnet_model_file, 'wb') as f:
|
16 |
f.write(model_content)
|
17 |
|
18 |
+
# Load the EfficientNet model onto the CPU
|
19 |
model = EfficientNet.from_pretrained('efficientnet-b3')
|
20 |
+
model.load_state_dict(torch.load(efficientnet_model_file, map_location=torch.device('cpu')))
|
21 |
+
|
22 |
+
# Load your custom model onto the CPU
|
23 |
+
custom_model_file = 'best_model.pth'
|
24 |
+
model.load_state_dict(torch.load(custom_model_file, map_location=torch.device('cpu')))
|
25 |
+
|
26 |
model.eval()
|
27 |
|
28 |
# Define a function that takes an image as input and uses the model for inference
|