maudzung / Complex-YOLOv4-Pytorch

The PyTorch Implementation based on YOLOv4 of the paper: "Complex-YOLO: Real-time 3D Object Detection on Point Clouds"
https://arxiv.org/pdf/1803.06199.pdf
GNU General Public License v3.0
1.21k stars 260 forks source link

test.py Runtime Error #38

Open ChaejinE opened 2 years ago

ChaejinE commented 2 years ago
Traceback (most recent call last):
  File "test.py", line 98, in <module>
    model.load_state_dict(torch.load(configs.pretrained_path))
  File "/home/chaejin/anaconda3/envs/complex-yolov4/lib/python3.8/site-packages/torch/serialization.py", line 593, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/home/chaejin/anaconda3/envs/complex-yolov4/lib/python3.8/site-packages/torch/serialization.py", line 773, in _legacy_load
    result = unpickler.load()
  File "/home/chaejin/anaconda3/envs/complex-yolov4/lib/python3.8/site-packages/torch/serialization.py", line 729, in persistent_load
    deserialized_objects[root_key] = restore_location(obj, location)
  File "/home/chaejin/anaconda3/envs/complex-yolov4/lib/python3.8/site-packages/torch/serialization.py", line 178, in default_restore_location
    result = fn(storage, location)
  File "/home/chaejin/anaconda3/envs/complex-yolov4/lib/python3.8/site-packages/torch/serialization.py", line 154, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "/home/chaejin/anaconda3/envs/complex-yolov4/lib/python3.8/site-packages/torch/serialization.py", line 144, in validate_cuda_device
    raise RuntimeError('Attempting to deserialize object on CUDA device '
RuntimeError: Attempting to deserialize object on CUDA device 2 but torch.cuda.device_count() is 1. Please use torch.load with map_location to map your storages to an existing device.

I got this Runtime Error.

image Nvidia GPU was operating well,, I don't know why this program was not operated Ofcourse, i gave arg map_location = "cuda:0". result was same Please test or review this program..

image

ChaejinE commented 2 years ago

Well, Should I use multi gpu ?

ChaejinE commented 2 years ago

8

This issue helps me know execute test.py but, i didn't execute yolov4 version. Don't it execute yet?

SinDongHwan commented 2 years ago

Hi, @ChaejinE. When call torch.load(), use a parameter(map_location). example code

configs.device = torch.device('cpu' if configs.no_cuda else 'cuda:{}'.format(configs.gpu_idx))
model.load_state_dict(torch.load(configs.pretrained_path, map_location=configs.device))

Good Luck.

torch.load 함수 호출하실 때, map_location 파라미터를 사용하세요. map_location 파라미터를 사용하지 않을 경우, device 정보를 pre-trained model에 적힌 것을 읽어옵니다.

해당 부분을 수정해서 pull request 요청한 상태라 곧 적용이 될 것 같습니다.