Commit
•
6e3c3b6
1
Parent(s):
f7a6d6c
expired pytorch hub cache bug fix #365
Browse files- hubconf.py +13 -9
hubconf.py
CHANGED
@@ -27,15 +27,19 @@ def create(name, pretrained, channels, classes):
|
|
27 |
Returns:
|
28 |
pytorch model
|
29 |
"""
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
|
40 |
|
41 |
def yolov5s(pretrained=False, channels=3, classes=80):
|
|
|
27 |
Returns:
|
28 |
pytorch model
|
29 |
"""
|
30 |
+
try:
|
31 |
+
config = os.path.join(os.path.dirname(__file__), 'models', '%s.yaml' % name) # model.yaml path
|
32 |
+
model = Model(config, channels, classes)
|
33 |
+
if pretrained:
|
34 |
+
ckpt = '%s.pt' % name # checkpoint filename
|
35 |
+
google_utils.attempt_download(ckpt) # download if not found locally
|
36 |
+
state_dict = torch.load(ckpt, map_location=torch.device('cpu'))['model'].float().state_dict() # to FP32
|
37 |
+
state_dict = {k: v for k, v in state_dict.items() if model.state_dict()[k].shape == v.shape} # filter
|
38 |
+
model.load_state_dict(state_dict, strict=False) # load
|
39 |
+
return model
|
40 |
+
except Exception as e:
|
41 |
+
help_url = 'https://github.com/ultralytics/yolov5/issues/36'
|
42 |
+
print('%s\nCache is out of date. Delete cache and retry. See %s for help.' % (e, help_url))
|
43 |
|
44 |
|
45 |
def yolov5s(pretrained=False, channels=3, classes=80):
|