txie-93 / cgcnn

Crystal graph convolutional neural networks for predicting material properties.
MIT License
651 stars 309 forks source link

Error raised while testing the code in README #9

Closed Cloudac7 closed 5 years ago

Cloudac7 commented 5 years ago

I configured the code in both docker and real environment, and there was not any error duIring excuting the training part. But for the predicting part, it raised the following error:

root@ef1b695a4d41:/workspace/cgcnn# python predict.py pre-trained/formation-energy-per-atom.pth.tar data/sample-regression
=> loading model params 'pre-trained/formation-energy-per-atom.pth.tar'
=> loaded model params 'pre-trained/formation-energy-per-atom.pth.tar' 
=> loading model 'pre-trained/formation-energy-per-atom.pth.tar'
=> loaded model 'pre-trained/formation-energy-per-atom.pth.tar' (epoch 968, validation 0.03972001800748568)
/opt/conda/lib/python3.6/site-packages/pymatgen/io/cif.py:1107: UserWarning: Issues encountered while parsing CIF:
  warnings.warn("Issues encountered while parsing CIF:")
/opt/conda/lib/python3.6/site-packages/pymatgen/io/cif.py:1109: UserWarning: Some fractional co-ordinates rounded to ideal values to avoid finite precision errors.
  warnings.warn(error)
predict.py:131: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  input_var = (Variable(input[0].cuda(non_blocking=True), volatile=True),
predict.py:132: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  Variable(input[1].cuda(non_blocking=True), volatile=True),
predict.py:146: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  volatile=True)
Traceback (most recent call last):
  File "predict.py", line 302, in <module>
    main()
  File "predict.py", line 106, in main
    validate(test_loader, model, criterion, normalizer, test=True)
  File "predict.py", line 157, in validate
    losses.update(loss.data.cpu()[0], target.size(0))
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

I used PyTorch 1.1 with CUDA10 in docker, while PyTorch 1.0 with CUDA 9.0 in real environment. The error was raised in both environment. So how could I deal with it?

Thanks!

txie-93 commented 5 years ago

This is probably a bug in the code. When we update the code for pytorch 1.0, we forgot to update the predict.py. Thanks for pointing this out. We will fix it very soon.

TanyaAdams1 commented 5 years ago

See pull request #10 for possible fix.

txie-93 commented 5 years ago

Thanks @TanyaAdams1. @Cloudac7 Can you test if the fix solves the problem?

Cloudac7 commented 5 years ago

Thanks @TanyaAdams1. @Cloudac7 Can you test if the fix solves the problem?

=> loading model params 'pre-trained/formation-energy-per-atom.pth.tar'
=> loaded model params 'pre-trained/formation-energy-per-atom.pth.tar'
=> loading model 'pre-trained/formation-energy-per-atom.pth.tar'
=> loaded model 'pre-trained/formation-energy-per-atom.pth.tar' (epoch 968, validation 0.03972001800748568)
/opt/conda/lib/python3.6/site-packages/pymatgen/io/cif.py:1107: UserWarning: Issues encountered while parsing CIF
:
  warnings.warn("Issues encountered while parsing CIF:")
/opt/conda/lib/python3.6/site-packages/pymatgen/io/cif.py:1109: UserWarning: Some fractional co-ordinates rounded
 to ideal values to avoid finite precision errors.
  warnings.warn(error)
Traceback (most recent call last):
  File "predict.py", line 299, in <module>
    main()
  File "predict.py", line 102, in main
    validate(test_loader, model, criterion, normalizer, test=True)
  File "predict.py", line 154, in validate
    losses.update(loss.data.cpu()[0], target.size(0))
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

I just tested the modified code, but it seems that the bug still exists.

TanyaAdams1 commented 5 years ago

I forgot to fix both regression and classification. Should be OK now. Please refer to #11

txie-93 commented 5 years ago

Yes, that should be the problem. I have merged the pull request. @Cloudac7 You can sync to the HEAD to get the latest code.

Cloudac7 commented 5 years ago

Yes, that should be the problem. I have merged the pull request. @Cloudac7 You can sync to the HEAD to get the latest code.

It works for the code in README. Thanks a lot for fixing the bug.