horsepurve / DeepRTplus

Deep (Transfer) Learning for Peptide Retention Time Prediction
MIT License
50 stars 22 forks source link

Peptide Modification: RuntimeError: Dimension out of range (expected to be in range of [-1, 0], but got 1) #4

Open bfurtwa opened 5 years ago

bfurtwa commented 5 years ago

I used a dataset with modifications encoded as "1" and "2". data.txt

And the same data with all modified peptides removed. data_no_mods.txt

With the modified peptides, I got this error:

D:\Benni\Code\DeepRT\DeepRTplus>python capsule_network_emb_cpu.py
0 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
>> number of aa: 22
>> note: using seq mode.
>> note: using >>>embedding<<< method.
DeepRT: using max length defined by user: 50
Read training data done; source: data/MapAlignerIdentificationuRTdata_train_2.tx
t
Note: didn't load val data.
Read testing data done; source: data/MapAlignerIdentificationuRTdata_test_2.txt
0 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
# parameters: 2869704
D:\Programs\anaconda3\lib\site-packages\torch\nn\functional.py:52: UserWarning:
size_average and reduce args will be deprecated, please use reduction='sum' inst
ead.
  warnings.warn(warning.format(ret))
  0%|                                                  | 0/115 [00:00<?, ?it/s]0
 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
>> number of aa: 22
>> note: using seq mode.
capsule_network_emb_cpu.py:575: UserWarning: invalid index of a 0-dim tensor. Th
is will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor
to a Python number
  meter_loss.add(state['loss'].data[0])
100%|████████████████████████████████████████| 115/115 [06:23<00:00,  3.34s/it]
[Epoch 1] Training Loss: 0.0968 (MSE: 7.0000)
0 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
>> number of aa: 22
>> note: using seq mode.
[Epoch 1] Testing Loss: 0.0679 (MSE: 7.0000)
Traceback (most recent call last):
  File "capsule_network_emb_cpu.py", line 743, in <module>
    engine.train(processor, get_rt_iterator(True), maxepoch=NUM_EPOCHS, optimize
r=optimizer)
  File "D:\Programs\anaconda3\lib\site-packages\torchnet\engine\engine.py", line
 67, in train
    self.hook('on_end_epoch', state)
  File "D:\Programs\anaconda3\lib\site-packages\torchnet\engine\engine.py", line
 31, in hook
    self.hooks[name](state)
  File "capsule_network_emb_cpu.py", line 671, in on_end_epoch
    pred_batch = model(test_batch)
  File "D:\Programs\anaconda3\lib\site-packages\torch\nn\modules\module.py", lin
e 477, in __call__
    result = self.forward(*input, **kwargs)
  File "capsule_network_emb_cpu.py", line 257, in forward
    x = x.transpose(dim0=1, dim1=2) # -> [batch, dict, len]
RuntimeError: Dimension out of range (expected to be in range of [-1, 0], but go
t 1)
horsepurve commented 5 years ago

Hi, I still cannot reproduce this error. I used exactly the same datasets and command:

python capsule_network_emb_cpu.py

and got the result:

[Epoch 1] Testing Loss: 0.0661 (MSE: 7.0000)
>> Corr on 27464 testing samples: 0.94613 | 0.95537
[Epoch 2] Testing Loss: 0.0504 (MSE: 7.0000)
>> Corr on 27464 testing samples: 0.96649 | 0.97090

What's your PyTorch version?

bfurtwa commented 5 years ago

I tried pytorch-cpu 0.4.1 and pytorch 0.4.0 from conda install pytorch-cpu=0.x.0 -c pytorch With 0.4.0 and a new git clone it looks like that:

D:\Benni\Code\DeepRT\DeepRTplus>python capsule_network_emb_cpu.py
0 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
>> number of aa: 22
>> note: using seq mode.
>> note: using >>>embedding<<< method.
DeepRT: using max length defined by user: 50
Read training data done; source: data/MapAlignerIdentificationuRTdata_train_2.tx
t
Note: didn't load val data.
Read testing data done; source: data/MapAlignerIdentificationuRTdata_test_2.txt
0 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
# parameters: 2869704
  0%|                                                  | 0/115 [00:00<?, ?it/s]0
 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
>> number of aa: 22
>> note: using seq mode.
capsule_network_emb_cpu.py:575: UserWarning: invalid index of a 0-dim tensor. Th
is will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor
to a Python number
  meter_loss.add(state['loss'].data[0])
100%|████████████████████████████████████████| 115/115 [05:51<00:00,  3.06s/it]
[Epoch 1] Training Loss: 0.1141 (MSE: 7.0000)
0 -> *
1 -> 1
2 -> 2
3 -> A
4 -> D
5 -> E
6 -> F
7 -> G
8 -> H
9 -> I
10 -> K
11 -> L
12 -> M
13 -> N
14 -> P
15 -> Q
16 -> R
17 -> S
18 -> T
19 -> V
20 -> W
21 -> Y
>> number of aa: 22
>> note: using seq mode.
[Epoch 1] Testing Loss: 0.0767 (MSE: 7.0000)
Traceback (most recent call last):
  File "capsule_network_emb_cpu.py", line 743, in <module>
    engine.train(processor, get_rt_iterator(True), maxepoch=NUM_EPOCHS, optimize
r=optimizer)
  File "D:\Programs\anaconda3\lib\site-packages\torchnet\engine\engine.py", line
 67, in train
    self.hook('on_end_epoch', state)
  File "D:\Programs\anaconda3\lib\site-packages\torchnet\engine\engine.py", line
 31, in hook
    self.hooks[name](state)
  File "capsule_network_emb_cpu.py", line 664, in on_end_epoch
    test_batch = Variable(corpus.test[bi*PRED_BATCH:(bi+1)*PRED_BATCH,:])
RuntimeError: dimension out of range (expected to be in range of [-1, 0], but go
t 1)
bfurtwa commented 5 years ago

This is my minimal python environment


(DeepRT) D:\Benni\Code\DeepRT\DeepRTplus>conda list
# packages in environment at D:\Programs\anaconda3\envs\DeepRT:
#
# Name                    Version                   Build  Channel
blas                      1.0                         mkl
certifi                   2018.10.15               py36_0
cffi                      1.11.5           py36h74b6da3_1
chardet                   3.0.4                     <pip>
icc_rt                    2017.0.4             h97af966_0
idna                      2.7                       <pip>
intel-openmp              2019.0                      118
mkl                       2019.0                      118
mkl_fft                   1.0.6            py36hdbbee80_0
mkl_random                1.0.1            py36h77b88f5_1
numpy                     1.15.3           py36ha559c80_0
numpy-base                1.15.3           py36h8128ebf_0
pandas                    0.23.4           py36h830ac7b_0
Pillow                    5.3.0                     <pip>
pip                       10.0.1                   py36_0
pycparser                 2.19                     py36_0
python                    3.6.7                h33f27b4_1
python-dateutil           2.7.3                    py36_0
pytorch-cpu               0.4.0           py36_cpuhe774522_1    pytorch
pytz                      2018.5                   py36_0
pyzmq                     17.1.2                    <pip>
requests                  2.20.0                    <pip>
scipy                     1.1.0                     <pip>
setuptools                40.4.3                   py36_0
six                       1.11.0                   py36_1
six                       1.11.0                    <pip>
torchfile                 0.1.0                     <pip>
torchnet                  0.0.4                     <pip>
torchvision               0.2.1                     <pip>
tornado                   5.1.1                     <pip>
tqdm                      4.26.0           py36h28b3542_0
urllib3                   1.24                      <pip>
vc                        14.1                 h0510ff6_4
visdom                    0.1.8.5                   <pip>
vs2015_runtime            14.15.26706          h3a45250_0
websocket-client          0.53.0                    <pip>
wheel                     0.32.2                   py36_0
wincertstore              0.2              py36h7fe50ca_0
horsepurve commented 5 years ago

Hi!

Finally I can reproduce this error. This is due to an existing issue of PyTorch #5554.

To fix this, please modify line #632 in capsule_network_emb_cpu.py to be:

PRED_BATCH = 18

and this could be fixed.