dongkwonjin / Eigenlanes

Official code for "Eigenlanes: Data-Driven Lane Descriptors for Structurally Diverse Lanes", CVPR2022
Apache License 2.0
127 stars 16 forks source link

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. #1

Closed zdddw closed 2 years ago

zdddw commented 2 years ago

@dongkwonjin First I'd like to thank you for your great work and your open source. I download the code today and want to test the performance on CULane, here is my command

python main.py --run_mode test_paper --pre_dir ../../../preprocessed/culane/ --paper_weight_dir ../../../pretrained/culane/ --dataset_dir /media/zdw/disc/dataset/CULane/extract/

But I got the error

Traceback (most recent call last):
  File "main.py", line 45, in <module>
    main()
  File "main.py", line 29, in main
    dict_DB = prepare_visualization(cfg, dict_DB)
  File "/media/zdw/disc/whu_selfdriving/drivable_area/eigen/Eigenlanes-main/Modeling/culane/code/libs/prepare.py", line 53, in prepare_visualization
    dict_DB['visualize'] = Visualize_cv(cfg=cfg)
  File "/media/zdw/disc/whu_selfdriving/drivable_area/eigen/Eigenlanes-main/Modeling/culane/code/visualizes/visualize.py", line 25, in __init__
    self.candidates = load_pickle(self.cfg.dir['pre3'] + 'lane_candidates_' + str(self.cfg.n_clusters))
  File "/media/zdw/disc/whu_selfdriving/drivable_area/eigen/Eigenlanes-main/Modeling/culane/code/libs/utils.py", line 77, in load_pickle
    data = pickle.load(f)
  File "/home/zdw/anaconda3/envs/eigen/lib/python3.7/site-packages/torch/storage.py", line 181, in _load_from_bytes
    return torch.load(io.BytesIO(b))
  File "/home/zdw/anaconda3/envs/eigen/lib/python3.7/site-packages/torch/serialization.py", line 713, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/home/zdw/anaconda3/envs/eigen/lib/python3.7/site-packages/torch/serialization.py", line 930, in _legacy_load
    result = unpickler.load()
  File "/home/zdw/anaconda3/envs/eigen/lib/python3.7/site-packages/torch/serialization.py", line 876, in persistent_load
    wrap_storage=restore_location(obj, location),
  File "/home/zdw/anaconda3/envs/eigen/lib/python3.7/site-packages/torch/serialization.py", line 176, in default_restore_location
    result = fn(storage, location)
  File "/home/zdw/anaconda3/envs/eigen/lib/python3.7/site-packages/torch/serialization.py", line 152, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "/home/zdw/anaconda3/envs/eigen/lib/python3.7/site-packages/torch/serialization.py", line 136, 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.

It shows that torch.cuda.is_available() is False, but when i run this line in terminal, it outputs True:

Python 3.7.13 (default, Mar 29 2022, 02:18:16) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True

Could you help me with this? Thanks very much.

zdddw commented 2 years ago

Well I found out what's going on. If you have only one gpu, just set self.gpu_id = "0" in config.py file, line 30. I ran the test on my own computer which has only 1 gpu, in the original code the self.gpu_id is 2.