cfgpp commited on
Commit
13d4f73
·
verified ·
1 Parent(s): b516bb7

Update model_utils.py

Browse files
Files changed (1) hide show
  1. model_utils.py +13 -3
model_utils.py CHANGED
@@ -24,16 +24,26 @@ class CheXNet(nn.Module):
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(device):
31
  model_path = hf_hub_download(repo_id="cfgpp/danny_net", filename="dannynet.pth")
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))
 
24
  x = torch.flatten(x, 1)
25
  return self.classifier(x)
26
 
 
 
27
 
28
+
29
+ from huggingface_hub import hf_hub_download
30
  def load_model(device):
31
  model_path = hf_hub_download(repo_id="cfgpp/danny_net", filename="dannynet.pth")
32
+
33
+ # Rebuild model architecture
34
+ model = CheXNet(num_classes=14)
35
+
36
+ # Load state dict (just weights)
37
+ state_dict = torch.load(model_path, map_location=device)
38
+ model.load_state_dict(state_dict)
39
+
40
+ model.to(device)
41
  model.eval()
42
  return model
43
 
44
 
45
+
46
+
47
  def predict(model, img_tensor, device):
48
  with torch.no_grad():
49
  output = model(img_tensor.unsqueeze(0).to(device))