Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretrained densenet does not work on CPU #220

Closed
lopuhin opened this issue Aug 6, 2017 · 6 comments
Closed

pretrained densenet does not work on CPU #220

lopuhin opened this issue Aug 6, 2017 · 6 comments

Comments

@lopuhin
Copy link
Contributor

lopuhin commented Aug 6, 2017

When I try to initialise pretrained densenet121, I get the error AssertionError: Torch not compiled with CUDA enabled (while other networks work). Using http://download.pytorch.org/whl/torch-0.2.0.post1-cp36-cp36m-macosx_10_7_x86_64.whl and torchvision-0.1.9 on CPython 3.6.2 on OS X 10.12.6.

Here is the full traceback:

In [2]: for m in [resnet50, inception_v3, densenet121]:
   ...:     m(pretrained=True)
   ...:
venv/lib/python3.6/site-packages/torchvision/models/inception.py:65: UserWarning: src is not broadcastable to dst, but they have the same number of elements.  Falling back to deprecated pointwise behavior.
  m.weight.data.copy_(values)
Downloading: "https://download.pytorch.org/models/densenet121-241335ed.pth" to /Users/kostia/.torch/models/densenet121-241335ed.pth
100.0%
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-2-28619da1d19b> in <module>()
      1 for m in [resnet50, inception_v3, densenet121]:
----> 2     m(pretrained=True)
      3

venv/lib/python3.6/site-packages/torchvision/models/densenet.py in densenet121(pretrained, **kwargs)
     26                      **kwargs)
     27     if pretrained:
---> 28         model.load_state_dict(model_zoo.load_url(model_urls['densenet121']))
     29     return model
     30

venv/lib/python3.6/site-packages/torch/utils/model_zoo.py in load_url(url, model_dir, map_location)
     56         hash_prefix = HASH_REGEX.search(filename).group(1)
     57         _download_url_to_file(url, cached_file, hash_prefix)
---> 58     return torch.load(cached_file, map_location=map_location)
     59
     60

venv/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module)
    229         f = open(f, 'rb')
    230     try:
--> 231         return _load(f, map_location, pickle_module)
    232     finally:
    233         if new_fd:

venv/lib/python3.6/site-packages/torch/serialization.py in _load(f, map_location, pickle_module)
    377     unpickler = pickle_module.Unpickler(f)
    378     unpickler.persistent_load = persistent_load
--> 379     result = unpickler.load()
    380
    381     deserialized_storage_keys = pickle_module.load(f)

venv/lib/python3.6/site-packages/torch/cuda/__init__.py in _lazy_new(cls, *args, **kwargs)
    264 @staticmethod
    265 def _lazy_new(cls, *args, **kwargs):
--> 266     _lazy_init()
    267     # We need this method only for lazy init, so we can remove it
    268     del _CudaBase.__new__

venv/lib/python3.6/site-packages/torch/cuda/__init__.py in _lazy_init()
     82         raise RuntimeError(
     83             "Cannot re-initialize CUDA in forked subprocess. " + msg)
---> 84     _check_driver()
     85     torch._C._cuda_init()
     86     torch._C._cuda_sparse_init()

venv/lib/python3.6/site-packages/torch/cuda/__init__.py in _check_driver()
     49 def _check_driver():
     50     if not hasattr(torch._C, '_cuda_isDriverSufficient'):
---> 51         raise AssertionError("Torch not compiled with CUDA enabled")
     52     if not torch._C._cuda_isDriverSufficient():
     53         if torch._C._cuda_getDriverVersion() == 0:

AssertionError: Torch not compiled with CUDA enabled
@lopuhin lopuhin changed the title densenet does not work on CPU pretrained densenet does not work on CPU Aug 6, 2017
@alykhantejani
Copy link
Contributor

I think the files we're serialized with the old method and now can't be properly read with the new serialization. I've tried loading, saving and re-loading on a CUDA enabled machine - which seems to work.

I will try to upload these new files somewhere sensible tomorrow so that the pre-trained locations can be updated.

cc: @fmassa

@alykhantejani
Copy link
Contributor

I will re-generate the models with the new serialization today and then update the URLs in torchvision.

@soumith
Copy link
Member

soumith commented Sep 10, 2017

fixed in master by @alykhantejani

@soumith soumith closed this as completed Sep 10, 2017
@hassanshallal
Copy link

Hi Folks, I am facing the same exact issue/error whenever I try to load any densenet modeL. I don't have any issue loading any other pre-trained model. I tried to download the densenet models manually from 489d6e7 and load them using torch.load, but I still get the error: AssertionError: (AssertionError('Torch not compiled with CUDA enabled',), <class 'torch.cuda.FloatTensor'>, ()). I am using macOS Sierra version 10.12.6.

I would really appreciate any help resolving this issue. Here is the full traceback:

`---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
in ()
----> 1 torch.load('densenet121-241335ed.pth')

/Users/hassanshallal/anaconda/lib/python2.7/site-packages/torch/serialization.pyc in load(f, map_location, pickle_module)
229 f = open(f, 'rb')
230 try:
--> 231 return _load(f, map_location, pickle_module)
232 finally:
233 if new_fd:

/Users/hassanshallal/anaconda/lib/python2.7/site-packages/torch/serialization.pyc in _load(f, map_location, pickle_module)
377 unpickler = pickle_module.Unpickler(f)
378 unpickler.persistent_load = persistent_load
--> 379 result = unpickler.load()
380
381 deserialized_storage_keys = pickle_module.load(f)

/Users/hassanshallal/anaconda/lib/python2.7/site-packages/torch/cuda/init.pyc in _lazy_new(cls, *args, **kwargs)
264 @staticmethod
265 def _lazy_new(cls, *args, **kwargs):
--> 266 _lazy_init()
267 # We need this method only for lazy init, so we can remove it
268 del _CudaBase.new

/Users/hassanshallal/anaconda/lib/python2.7/site-packages/torch/cuda/init.pyc in _lazy_init()
82 raise RuntimeError(
83 "Cannot re-initialize CUDA in forked subprocess. " + msg)
---> 84 _check_driver()
85 torch._C._cuda_init()
86 torch._C._cuda_sparse_init()

/Users/hassanshallal/anaconda/lib/python2.7/site-packages/torch/cuda/init.pyc in _check_driver()
49 def _check_driver():
50 if not hasattr(torch._C, '_cuda_isDriverSufficient'):
---> 51 raise AssertionError("Torch not compiled with CUDA enabled")
52 if not torch._C._cuda_isDriverSufficient():
53 if torch._C._cuda_getDriverVersion() == 0:

AssertionError: (AssertionError('Torch not compiled with CUDA enabled',), <class 'torch.cuda.FloatTensor'>, ())
`

Thanks

@soumith
Copy link
Member

soumith commented Dec 18, 2017

@hassanshallal update your torchvision with: pip install -U torchvision

@hassanshallal
Copy link

Thanks a lot for the feedback, I can now upload and use the densenet pre-trained models.

rajveerb pushed a commit to rajveerb/vision that referenced this issue Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants