Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Add CPU-only in serialization.py #69

Open
changbaishan opened this issue Mar 13, 2021 · 0 comments
Open

Add CPU-only in serialization.py #69

changbaishan opened this issue Mar 13, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@changbaishan
Copy link

RuntimeError Traceback (most recent call last)
in
9 models = dict()
10 for key,fun in six.iteritems(model_inits):
---> 11 net = fun(n_classes, pretrained=True).eval()
12 if has_cuda:
13 net = net.cuda()

~/Documents/sandbox/torch/light-weight-refinenet/models/resnet.py in rf_lw50(num_classes, imagenet, pretrained, **kwargs)
246 key = "rf_lw" + bname
247 url = models_urls[bname]
--> 248 model.load_state_dict(maybe_download(key, url), strict=False)
249 return model
250

~/Documents/sandbox/torch/light-weight-refinenet/utils/helpers.py in maybe_download(model_name, model_url, model_dir, map_location)
23 sys.stderr.write('Downloading: "{}" to {}\n'.format(url, cached_file))
24 urllib.request.urlretrieve(url, cached_file)
---> 25 return torch.load(cached_file, map_location=map_location)
26
27

~/.local/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
593 return torch.jit.load(opened_file)
594 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
--> 595 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
596
597

~/.local/lib/python3.6/site-packages/torch/serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
772 unpickler = pickle_module.Unpickler(f, **pickle_load_args)
773 unpickler.persistent_load = persistent_load
--> 774 result = unpickler.load()
775
776 deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)

~/.local/lib/python3.6/site-packages/torch/serialization.py in persistent_load(saved_id)
728 obj = data_type(size)
729 obj._torch_load_uninitialized = True
--> 730 deserialized_objects[root_key] = restore_location(obj, location)
731 storage = deserialized_objects[root_key]
732 if view_metadata is not None:

~/.local/lib/python3.6/site-packages/torch/serialization.py in default_restore_location(storage, location)
173 def default_restore_location(storage, location):
174 for _, _, fn in _package_registry:
--> 175 result = fn(storage, location)
176 if result is not None:
177 return result

~/.local/lib/python3.6/site-packages/torch/serialization.py in _cuda_deserialize(obj, location)
149 def _cuda_deserialize(obj, location):
150 if location.startswith('cuda'):
--> 151 device = validate_cuda_device(location)
152 if getattr(obj, "_torch_load_uninitialized", False):
153 storage_type = getattr(torch.cuda, type(obj).name)

~/.local/lib/python3.6/site-packages/torch/serialization.py in validate_cuda_device(location)
133
134 if not torch.cuda.is_available():
--> 135 raise RuntimeError('Attempting to deserialize object on a CUDA '
136 'device but torch.cuda.is_available() is False. '
137 '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=torch.device('cpu') to map your storages to the CPU.

@DrSleep DrSleep added the bug Something isn't working label May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants