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

IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number #3

Closed
PanZiwei opened this issue Jan 7, 2020 · 2 comments

Comments

@PanZiwei
Copy link

PanZiwei commented Jan 7, 2020

Hi Wangjuan,
When I tried HiCplus training process on GPU nodes, it shows an error after almost 24h. Here is the error message:

./Anaconda3/envs/plus/lib/python3.6/site-packages/torch/nn/modules/loss.py:431: UserWarning: Using a target size (torch.Size([80, 28, 28])) that is different to the input size (torch.Size([80, 1, 28, 28])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
  return F.mse_loss(input, target, reduction=self.reduction)
0:00:00.000020
HiC version:  7
dividing, filtering and downsampling files...
(1379920, 1, 40, 40)
(1379920, 1, 40, 40)
start training...
(1379920, 1, 40, 40) (1379920, 28, 28)
Traceback (most recent call last):
  File "./Anaconda3/envs/plus/bin/hicplus", line 4, in <module>
    __import__('pkg_resources').run_script('hicplus==1.1.0', 'hicplus')
  File "./Anaconda3/envs/plus/lib/python3.6/site-packages/pkg_resources/__init__.py", line 666, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "./envs/plus/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1462, in run_script
    exec(code, namespace, namespace)
  File "./Anaconda3/envs/plus/lib/python3.6/site-packages/hicplus-1.1.0-py3.6.egg/EGG-INFO/scripts/hicplus", line 70, in <module>
    run()
  File "./Anaconda3/envs/plus/lib/python3.6/site-packages/hicplus-1.1.0-py3.6.egg/EGG-INFO/scripts/hicplus", line 66, in run
    args.func(args)
  File "./Anaconda3/envs/plus/lib/python3.6/site-packages/hicplus-1.1.0-py3.6.egg/hicplus/train_models.py", line 38, in main
    trainConvNet.train(lowres_sub,highres_sub,args.outmodel)
  File "./Anaconda3/envs/plus/lib/python3.6/site-packages/hicplus-1.1.0-py3.6.egg/hicplus/trainConvNet.py", line 120, in train
    running_loss += loss.data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

It seems that it should be a problem with PyTorch version. And here is a similar case

Do you know how to solve the problem? What PyTorch version are you using for the HiCPlus package?

Thanks!

@PanZiwei PanZiwei changed the title Install module "straw" before using No GPU nodes available Jan 7, 2020
@PanZiwei PanZiwei closed this as completed Jan 9, 2020
@PanZiwei PanZiwei reopened this Jan 9, 2020
@PanZiwei PanZiwei changed the title No GPU nodes available IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number Jan 9, 2020
@PanZiwei
Copy link
Author

PanZiwei commented Jan 21, 2020

Finally fix the problem and my solution is below:
Change line 120 in File "./Anaconda3/envs/plus/lib/python3.6/site-packages/hicplus-1.1.0-py3.6.egg/hicplus/trainConvNet.py"

Change from
running_loss += loss.data[0]
to
running_loss += loss.data

The error reason: That's because in PyTorch>=0.5, the index of 0-dim tensor is invalid. The master branch is designed for PyTorch 0.4.1.

@PanZiwei PanZiwei reopened this Jan 21, 2020
@wangjuan001
Copy link
Owner

Thanks for the comment! I've changed that line

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