Background-Matting icon indicating copy to clipboard operation
Background-Matting copied to clipboard

error occured KeyError: 'CUDA_VISIBLE_DEVICES'

Open klutzpedro opened this issue 4 years ago • 3 comments

error occured when executed this command : python test_background-matting_image.py -m real-hand-held -i sample_video/input/ -o sample_video/output/ -tb sample_video/background/

Traceback (most recent call last): File "test_background-matting_image.py", line 20, in print('CUDA Device: ' + os.environ["CUDA_VISIBLE_DEVICES"]) File "/home/dwijayanto/anaconda3/envs/back-matting/lib/python3.6/os.py", line 669, in getitem raise KeyError(key) from None KeyError: 'CUDA_VISIBLE_DEVICES'

klutzpedro avatar May 20 '20 13:05 klutzpedro

@Klutz2904 You need to set CUDA_VISIBLE_DEVICES=0 in the environment.

To do this, you should either execute the command with !(running_ on ipython/jupyter)

!CUDA_VISIBLE_DEVICES=0 python test_background-matting_image.py -m real-hand-held -i sample_video/input/ -o sample_video/output/ -tb sample_video/background/

or on terminal without !

CUDA_VISIBLE_DEVICES=0 python test_background-matting_image.py -m real-hand-held -i sample_video/input/ -o sample_video/output/ -tb sample_video/background/

anurag-priyadarshi avatar May 20 '20 13:05 anurag-priyadarshi

Need more help, thanks

~/Background-Matting$ CUDA_VISIBLE_DEVICES=0 python test_background-matting_image.py -m real-hand-held -i sample_video/input/ -o sample_video/output/ -tb sample_video/background/ CUDA Device: 0 Using video mode Traceback (most recent call last): File "test_background-matting_image.py", line 57, in netM.load_state_dict(torch.load(model_name1)) File "/home/dwijayanto/anaconda3/envs/back-matting/lib/python3.6/site-packages/torch/serialization.py", line 593, in load return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args) File "/home/dwijayanto/anaconda3/envs/back-matting/lib/python3.6/site-packages/torch/serialization.py", line 773, in _legacy_load result = unpickler.load() File "/home/dwijayanto/anaconda3/envs/back-matting/lib/python3.6/site-packages/torch/serialization.py", line 729, in persistent_load deserialized_objects[root_key] = restore_location(obj, location) File "/home/dwijayanto/anaconda3/envs/back-matting/lib/python3.6/site-packages/torch/serialization.py", line 178, in default_restore_location result = fn(storage, location) File "/home/dwijayanto/anaconda3/envs/back-matting/lib/python3.6/site-packages/torch/serialization.py", line 154, in _cuda_deserialize device = validate_cuda_device(location) File "/home/dwijayanto/anaconda3/envs/back-matting/lib/python3.6/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.

klutzpedro avatar May 20 '20 15:05 klutzpedro

@Klutz2904 It seems that the machine on which you are trying to run this is not configured properly for using GPUs. It might be easier to run the code on google colab where authors have set up the system. Link to Colab

anurag-priyadarshi avatar May 20 '20 15:05 anurag-priyadarshi