Update model_utils.py
Browse files- model_utils.py +7 -4
model_utils.py
CHANGED
|
@@ -24,13 +24,16 @@ class CheXNet(nn.Module):
|
|
| 24 |
x = torch.flatten(x, 1)
|
| 25 |
return self.classifier(x)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
model.eval()
|
| 32 |
return model
|
| 33 |
|
|
|
|
| 34 |
def predict(model, img_tensor, device):
|
| 35 |
with torch.no_grad():
|
| 36 |
output = model(img_tensor.unsqueeze(0).to(device))
|
|
|
|
| 24 |
x = torch.flatten(x, 1)
|
| 25 |
return self.classifier(x)
|
| 26 |
|
| 27 |
+
from huggingface_hub import hf_hub_download
|
| 28 |
+
import torch
|
| 29 |
+
|
| 30 |
+
def load_model(repo_id, filename, device):
|
| 31 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 32 |
+
model = torch.load(model_path, map_location=device)
|
| 33 |
model.eval()
|
| 34 |
return model
|
| 35 |
|
| 36 |
+
|
| 37 |
def predict(model, img_tensor, device):
|
| 38 |
with torch.no_grad():
|
| 39 |
output = model(img_tensor.unsqueeze(0).to(device))
|