seungjunlee96 / emergency-triage-of-brain-computed-tomography-via-anomaly-detection-with-a-deep-generative-model

8 stars 2 forks source link

RuntimeError: memory format option is only supported by strided tensors #5

Closed anantpal07 closed 5 months ago

anantpal07 commented 5 months ago

I am encountering a RuntimeError with the message "memory format option is only supported by strided tensors" in my PyTorch code. This issue seems related to memory layout and occurs during the execution of the projector.py script.

ubuntu@c0f2685c32d4:/workspace/easiofy$ python projector.py --query_save_path=./demos Setting up Perceptual loss from device [0] /opt/conda/lib/python3.8/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead. warnings.warn( /opt/conda/lib/python3.8/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing weights=VGG16_Weights.IMAGENET1K_V1. You can also use weights=VGG16_Weights.DEFAULT to get the most up-to-date weights. warnings.warn(msg) Loading model from: /workspace/easiofy/lpips/weights/v0.1/vgg.pth

test_results [INFO] query images = ./demos/tumor_edema /opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py:558: UserWarning: This DataLoader will create 12 worker processes in total. Our suggested max number of worker in current system is 8, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary. warnings.warn(_create_warning_msg( Traceback (most recent call last): File "projector.py", line 297, in project(args) File "projector.py", line 169, in project latent_e = encoder(img_reals) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, *kwargs) File "/workspace/easiofy/model.py", line 717, in forward out = self.convs(input) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/container.py", line 217, in forward input = module(input) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(args, kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/container.py", line 217, in forward input = module(input) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, *kwargs) File "/workspace/easiofy/op/fused_act.py", line 83, in forward return fused_leaky_relu(input, self.bias, self.negative_slope, self.scale) File "/workspace/easiofy/op/fused_act.py", line 97, in fused_leaky_relu return FusedLeakyReLUFunction.apply(input, bias, negative_slope, scale) File "/opt/conda/lib/python3.8/site-packages/torch/autograd/function.py", line 553, in apply return super().apply(args, kwargs) # type: ignore[misc] File "/workspace/easiofy/op/fused_act.py", line 56, in forward out = fused.fused_bias_act(input, bias, empty, 3, 0, negative_slope, scale) RuntimeError: memory format option is only supported by strided tensors.

seungjunlee96 commented 5 months ago

Hello,

Thank you for reaching out with this issue. It looks like the error is due to a PyTorch version mismatch. Here’s a quick guide to get things aligned:

  1. Remove the current PyTorch and related libraries:

    pip uninstall torch torchvision torchaudio
  2. Install the correct version of PyTorch (we used torch == 1.13.1 for this project):

    pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1

If you're encountering system dependencies or compiler issues, these commands might be necessary:

sudo apt update && sudo apt install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update && sudo apt install gcc-9 g++-9
  1. Try running your script again:
    python projector.py --query_save_path=./demos

I hope this helps! Additionally, I've updated the Dockerfile accordingly.