As of today, I am getting a similar error where I did not previously get any errors:
Torch version is 1.13.1, torchvision 0.14.1
from torchvision import models
models.resnet34(weights='DEFAULT')
raises:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/var/folders/d8/265wdp1n0bn_r85dh3pp95fh0000gq/T/ipykernel_64242/3473222446.py in <cell line: 2>()
1 from torchvision import models
----> 2 models.resnet34(weights='DEFAULT')
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torchvision/models/_utils.py in wrapper(*args, **kwargs)
140 kwargs.update(keyword_only_kwargs)
141
--> 142 return fn(*args, **kwargs)
143
144 return wrapper
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torchvision/models/_utils.py in inner_wrapper(*args, **kwargs)
226 kwargs[weights_param] = default_weights_arg
227
--> 228 return builder(*args, **kwargs)
229
230 return inner_wrapper
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torchvision/models/resnet.py in resnet34(weights, progress, **kwargs)
695 weights = ResNet34_Weights.verify(weights)
696
--> 697 return _resnet(BasicBlock, [3, 4, 6, 3], weights, progress, **kwargs)
698
699
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torchvision/models/resnet.py in _resnet(block, layers, weights, progress, **kwargs)
299
300 if weights is not None:
--> 301 model.load_state_dict(weights.get_state_dict(progress=progress))
302
303 return model
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torchvision/models/_api.py in get_state_dict(self, progress)
64
65 def get_state_dict(self, progress: bool) -> Mapping[str, Any]:
---> 66 return load_state_dict_from_url(self.url, progress=progress)
67
68 def __repr__(self) -> str:
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torch/hub.py in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash, file_name)
733 if _is_legacy_zip_format(cached_file):
734 return _legacy_zip_load(cached_file, model_dir, map_location)
--> 735 return torch.load(cached_file, map_location=map_location)
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torch/serialization.py in load(f, map_location, pickle_module, weights_only, **pickle_load_args)
787 except RuntimeError as e:
788 raise pickle.UnpicklingError(UNSAFE_MESSAGE + str(e)) from None
--> 789 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
790 if weights_only:
791 try:
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torch/serialization.py in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
1129 unpickler = UnpicklerWrapper(data_file, **pickle_load_args)
1130 unpickler.persistent_load = persistent_load
-> 1131 result = unpickler.load()
1132
1133 torch._utils._validate_loaded_sparse_tensors()
~/miniconda3/envs/opso_dev/lib/python3.9/site-packages/torch/serialization.py in persistent_load(saved_id)
1098
1099 if key not in loaded_storages:
-> 1100 nbytes = numel * torch._utils._element_size(dtype)
1101 load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
1102
AttributeError: module 'torch' has no attribute '_utils'