hub
hub copied to clipboard
HARDNET cannot load the model according to documentation
I run the code according to this:
import torch
model = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet68', pretrained=True)
# or any of these variants
# model = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet85', pretrained=True)
# model = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet68ds', pretrained=True)
# model = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet39ds', pretrained=True)
model.eval()
But I get this error:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-8-f03545ea41ea> in <module>()
17 return
18
---> 19 test()
<ipython-input-8-f03545ea41ea> in test()
5 model_name = "HarDNet"
6 ##
----> 7 model1 = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet68', pretrained=True)
8 # model2 = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet85', pretrained=True)
9 # model3 = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet68ds', pretrained=True)
~\Anaconda3\lib\site-packages\torch\hub.py in load(github, model, *args, **kwargs)
339 entry = _load_entry_from_hubconf(hub_module, model)
340
--> 341 model = entry(*args, **kwargs)
342
343 sys.path.remove(repo_dir)
~/.cache\torch\hub\PingoLH_Pytorch-HarDNet_master/hubconf.py in hardnet68(pretrained, **kwargs)
8 """
9 # Call the model, load pretrained weights
---> 10 model = hardnet.HarDNet(depth_wise=False, arch=68, pretrained=pretrained)
11 return model
12
~/.cache\torch\hub\PingoLH_Pytorch-HarDNet_master\hardnet.py in __init__(self, depth_wise, arch, pretrained, weight_path)
215 checkpoint = 'https://ping-chao.com/hardnet/hardnet39ds-0e6c6fa9.pth'
216
--> 217 self.load_state_dict(torch.hub.load_state_dict_from_url(checkpoint, progress=False))
218 else:
219 postfix = 'ds' if depth_wise else ''
~\Anaconda3\lib\site-packages\torch\hub.py in load_state_dict_from_url(url, model_dir, map_location, progress)
433 hash_prefix = HASH_REGEX.search(filename).group(1)
434 _download_url_to_file(url, cached_file, hash_prefix, progress=progress)
--> 435 return torch.load(cached_file, map_location=map_location)
~\Anaconda3\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
385 f = f.open('rb')
386 try:
--> 387 return _load(f, map_location, pickle_module, **pickle_load_args)
388 finally:
389 if new_fd:
~\Anaconda3\lib\site-packages\torch\serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
572 unpickler = pickle_module.Unpickler(f, **pickle_load_args)
573 unpickler.persistent_load = persistent_load
--> 574 result = unpickler.load()
575
576 deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)
~\Anaconda3\lib\site-packages\torch\serialization.py in persistent_load(saved_id)
535 obj = data_type(size)
536 obj._torch_load_uninitialized = True
--> 537 deserialized_objects[root_key] = restore_location(obj, location)
538 storage = deserialized_objects[root_key]
539 if view_metadata is not None:
~\Anaconda3\lib\site-packages\torch\serialization.py in default_restore_location(storage, location)
117 def default_restore_location(storage, location):
118 for _, _, fn in _package_registry:
--> 119 result = fn(storage, location)
120 if result is not None:
121 return result
~\Anaconda3\lib\site-packages\torch\serialization.py in _cuda_deserialize(obj, location)
93 def _cuda_deserialize(obj, location):
94 if location.startswith('cuda'):
---> 95 device = validate_cuda_device(location)
96 if getattr(obj, "_torch_load_uninitialized", False):
97 storage_type = getattr(torch.cuda, type(obj).__name__)
~\Anaconda3\lib\site-packages\torch\serialization.py in validate_cuda_device(location)
77
78 if not torch.cuda.is_available():
---> 79 raise RuntimeError('Attempting to deserialize object on a CUDA '
80 'device but torch.cuda.is_available() is False. '
81 'If you are running on a CPU-only machine, '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location='cpu' to map your storages to the CPU.
The code and model can be downloaded but cannot be loaded. So what is the problem here? Thanks.