JuliaWolleb / DeScarGAN

Official Pytorch implementation of the paper DeScarGAN
Apache License 2.0
30 stars 5 forks source link

IndexError: tuple index out of range #7

Open yobrepus opened 2 years ago

yobrepus commented 2 years ago

I found the error at this line (out_k, klasse_k) = netD(inputs[v_krank][:,0,:,:,:],k). Please suggest me how to fix this.

shape of inputs[v_krank][:,0,:,:,:] is [8, 1, 256, 256] shape of k is [1]

JuliaWolleb commented 2 years ago

Hi Well, you need to provide the error message so that I can help you.

The shapes seem to be correct. k should indicate the class label, so it should be 0 or 1.

yobrepus commented 2 years ago

Hi,

Please see the error message below. By the way, I run the code on colab.

Defaults for this optimization level are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic Processing user overrides (additional kwargs that are not None)... After processing overrides, optimization options are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic Warning: multi_tensor_applier fused unscale kernel is unavailable, possibly because apex was installed without --cuda_ext --cpp_ext. Using Python fallback. Original ImportError was: ModuleNotFoundError("No module named 'amp_C'") Selected optimization level O1: Insert automatic casts around Pytorch functions and Tensor methods.

Defaults for this optimization level are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic Processing user overrides (additional kwargs that are not None)... After processing overrides, optimization options are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic [Errno 99] Cannot assign requested address on_close() takes 1 positional argument but 3 were given [Errno 99] Cannot assign requested address on_close() takes 1 positional argument but 3 were given tensor([1, 1, 0, 0, 1, 1, 1, 1, 1, 1]) epoch 0 iter 0 torch.Size([10, 256, 256, 1]) torch.Size([8, 1, 256, 256]) torch.Size([1]) [Errno 99] Cannot assign requested address on_close() takes 1 positional argument but 3 were given [Errno 99] Cannot assign requested address on_close() takes 1 positional argument but 3 were given Traceback (most recent call last): File "main.py", line 56, in main(config) File "main.py", line 29, in main solver.train() File "/content/drive/MyDrive/Master Thesis OOD/Model/DeScarGAN/model/DeScarGAN.py", line 231, in train (out_k, klasse_k) = netD(inputs[v_krank][:,0,:,:,:],k) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, kwargs) File "/usr/local/lib/python3.7/dist-packages/torch/nn/parallel/data_parallel.py", line 166, in forward return self.module(*inputs[0], *kwargs[0]) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(input, kwargs) File "/content/drive/MyDrive/Master Thesis OOD/Model/DeScarGAN/model/generator_discrminator.py", line 227, in forward h = self.encoder(x) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, kwargs) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py", line 141, in forward input = module(input) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, *kwargs) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py", line 141, in forward input = module(input) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(input, kwargs) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/conv.py", line 447, in forward return self._conv_forward(input, self.weight, self.bias) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/conv.py", line 444, in _conv_forward self.padding, self.dilation, self.groups) File "/usr/local/lib/python3.7/dist-packages/apex/amp/wrap.py", line 21, in wrapper args[i] = utils.cached_cast(cast_fn, args[i], handle.cache) File "/usr/local/lib/python3.7/dist-packages/apex/amp/utils.py", line 97, in cached_cast if cached_x.grad_fn.next_functions[1][0].variable is not x: IndexError: tuple index out of range

JuliaWolleb commented 2 years ago

Hi

There seems to be a problem with apex. Did you install it correctly? You could try to set the optimization level to 'O0' instead of 'O1', or leave out the Automatic Mixed Precision (amp) in lines 135, 136, 282 and 393.

Let me know if this solves the problem.

yobrepus commented 2 years ago

Hi

Can you give me more detail about setting the optimization level to 'O0' instead of 'O1', or leave out the Automatic Mixed Precision (amp) in lines 135, 136, 282, and 393? Where can I find it?

JuliaWolleb commented 2 years ago

You can choose the optimization level 'O0' in lines 132 and 133 in the file model/DeScarGAN.py, as well as in lines 77 and 78 of the file _Evaluation/Evaluation_SyntheticDataset.py and in lines 81 and 82 of the file _Evaluation/EvaluationChexpert.py. If this does not work, you leave out those lines. Furthermore, in the file model/DeScarGAN.py you just run d_loss.backward() in line 270, and g_loss.backward() in line 370.