sam-hq icon indicating copy to clipboard operation
sam-hq copied to clipboard

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

Open askie opened this issue 1 year ago • 5 comments

Traceback (most recent call last): File "E:\sam-hq\demo\demo_hqsam.py", line 63, in sam = sam_model_registrymodel_type ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\sam-hq\segment_anything\build_sam.py", line 28, in build_sam_vit_l return _build_sam( ^^^^^^^^^^^ File "E:\sam-hq\segment_anything\build_sam.py", line 106, in _build_sam state_dict = torch.load(f) ^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\torch\serialization.py", line 809, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\torch\serialization.py", line 1172, in _load result = unpickler.load() ^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\torch\serialization.py", line 1142, in persistent_load typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\torch\serialization.py", line 1116, in load_tensor wrap_storage=restore_location(storage, location), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\torch\serialization.py", line 217, in default_restore_location result = fn(storage, location) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\torch\serialization.py", line 182, in _cuda_deserialize device = validate_cuda_device(location) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\torch\serialization.py", line 166, 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.

askie avatar Jun 23 '23 01:06 askie

This pull request suggestion may help.

lkeab avatar Jun 26 '23 08:06 lkeab

Hello, Where do we need to specify "cpu"?

shersoni610 avatar Jul 07 '23 03:07 shersoni610

Hello, The answer from "lkeab" solved my problem. I was able to run the code on CPU.

shersoni610 avatar Jul 07 '23 15:07 shersoni610

Will this be added to the pip-package?

FerusAndBeyond avatar Aug 11 '23 08:08 FerusAndBeyond

@FerusAndBeyond related: https://github.com/SysCV/sam-hq/pull/25#issuecomment-1774205933

Until it is, we can use:

pip install git+https://github.com/SysCV/sam-hq@61ea10f

At time of writing, this also requires modifying the import name to be segment_anything instead of segment_anything_hq (see https://github.com/SysCV/sam-hq/pull/83).

abrichr avatar Dec 10 '23 07:12 abrichr