HimankJ commited on
Commit
b5b42e9
·
verified ·
1 Parent(s): d997b45

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. utils/model_loader.py +10 -1
utils/model_loader.py CHANGED
@@ -53,7 +53,16 @@ class ModelLoader:
53
  pretrained=False,
54
  num_classes=self.num_classes
55
  )
56
- model.load_state_dict(torch.load('model/latest_model.pt', map_location=self.device))
 
 
 
 
 
 
 
 
 
57
  model.eval()
58
  return model
59
 
 
53
  pretrained=False,
54
  num_classes=self.num_classes
55
  )
56
+
57
+ # Load state dict
58
+ state_dict = torch.load('model/latest_model.pt', map_location=self.device)
59
+
60
+ # Remove 'model.' prefix from state dict keys if present
61
+ if all(k.startswith('model.') for k in state_dict.keys()):
62
+ state_dict = {k.replace('model.', ''): v for k, v in state_dict.items()}
63
+
64
+ # Load the modified state dict
65
+ model.load_state_dict(state_dict)
66
  model.eval()
67
  return model
68