autonomousvision / differentiable_volumetric_rendering

This repository contains the code for the CVPR 2020 paper "Differentiable Volumetric Rendering: Learning Implicit 3D Representations without 3D Supervision"
http://www.cvlibs.net/publications/Niemeyer2020CVPR.pdf
MIT License
801 stars 91 forks source link

Fixed CPU/CUDA compatibility issue #30

Closed nitish11 closed 4 years ago

nitish11 commented 4 years ago

Fixed the below error in loading the trained model on CPU.

(dvr) PS ~\differentiable_volumetric_rendering> python generate.py configs/demo/demo_combined.yaml --no-cuda
https://s3.eu-central-1.amazonaws.com/avg-projects/differentiable_volumetric_rendering/models/single_view_reconstruction/multi-view-supervision/ours_combined-af2bce07.pt
=> Loading checkpoint from url...
Traceback (most recent call last):
  File "generate.py", line 63, in <module>
    checkpoint_io.load(cfg['test']['model_file'])
  File "differentiable_volumetric_rendering\im2mesh\checkpoints.py", line 62, in load
    return self.load_url(filename)
  File "differentiable_volumetric_rendering\im2mesh\checkpoints.py", line 93, in load_url
    state_dict = model_zoo.load_url(url, progress=True)
  File "anaconda3\envs\dvr\lib\site-packages\torch\hub.py", line 509, in load_state_dict_from_url
    return torch.load(cached_file, map_location=map_location)
  File "anaconda3\en\dvr\lib\site-packages\torch\serialization.py", line 593, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "anaconda3\envs\dvr\lib\site-packages\torch\serialization.py", line 773, in _legacy_load
    result = unpickler.load()
  File "anaconda3\envs\dvr\lib\site-packages\torch\serialization.py", line 729, in persistent_load
    deserialized_objects[root_key] = restore_location(obj, location)
  File "anaconda3\envs\dvr\lib\site-packages\torch\serialization.py", line 178, in default_restore_location
    result = fn(storage, location)
  File "anaconda3\envs\dvr\lib\site-packages\torch\serialization.py", line 154, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "anaconda3\envs\dvr\lib\site-packages\torch\serialization.py", line 138, in validate_cuda_device
    raise RuntimeError('Attempting to deserialize object on a CUDA '
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.
m-niemeyer commented 4 years ago

@nitish11 that's great, thanks a lot! I didn't test it, but the code looks good so I assume it works for CPU and GPU.

Thanks a lot again for your great help!