Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M1/2/3 Apple Silicon #4

Open
Pomierny opened this issue Nov 18, 2024 · 2 comments
Open

M1/2/3 Apple Silicon #4

Pomierny opened this issue Nov 18, 2024 · 2 comments

Comments

@Pomierny
Copy link

Pomierny commented Nov 18, 2024

Hi,
I m trying to run RSS on my MacBook M1, however I ve stuck on the very beginning. I ve installed CPU-only version, however when started the script to run I get such error:

Traceback (most recent call last): File "/opt/miniconda3/envs/rss2/bin/RS2_predict", line 33, in <module> sys.exit(load_entry_point('RS2==1.0', 'console_scripts', 'RS2_predict')()) File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/RS2-1.0-py3.9.egg/RS2/inference/predict.py", line 421, in predict_entry_point predict_from_raw_data(args.i, File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/RS2-1.0-py3.9.egg/RS2/inference/predict.py", line 134, in predict_from_raw_data load_what_we_need(checkpoint_name) File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/RS2-1.0-py3.9.egg/RS2/inference/predict.py", line 76, in load_what_we_need checkpoint = torch.load(checkpoint_name) File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/torch/serialization.py", line 809, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/torch/serialization.py", line 1172, in _load result = unpickler.load() File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/torch/serialization.py", line 1142, in persistent_load typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location)) File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/torch/serialization.py", line 1116, in load_tensor wrap_storage=restore_location(storage, location), File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/torch/serialization.py", line 217, in default_restore_location result = fn(storage, location) File "/opt/miniconda3/envs/rss2/lib/python3.9/site-packages/torch/serialization.py", line 182, in _cuda_deserialize device = validate_cuda_device(location) File "/opt/miniconda3/envs/rss2/lib/python3.9/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.

Not sure how can I resolve this... any suggestions?

Cheers,
Bartek

@VitoLin21
Copy link
Owner

I am sorry that I have not tested this code on a MAC.
you can try adding " -device 'cpu' " after the command
RS2_predict -i 'path/to/input' -o 'path/to/output' -m 'path/to/pretrained_model.pt'

like
RS2_predict -i 'path/to/input' -o 'path/to/output' -m 'path/to/pretrained_model.pt' -device 'cpu'

If there are same error, please modify line 76 of "Rodent-Skull-Stripping/RS2/inference/predict.py":
checkpoint = torch.load(checkpoint_name)
to:
checkpoint = torch.load(checkpoint_name, map_location=torch.device('cpu'))

Then run:
pip uninstall RS2

python setup.py install

to reinstall the framework and try RS2_predict XXX again(with -device 'cpu').

@VitoLin21
Copy link
Owner

You can also try specifying the device as -device 'mps'. I haven't tested this function, but PyTorch itself supports it (https://pytorch.org/docs/stable/notes/mps.html).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants