Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

RuntimeError of 'T_out = y.size(1) if y is not None else None' #17

Open
ghost opened this issue Aug 27, 2017 · 5 comments
Open

RuntimeError of 'T_out = y.size(1) if y is not None else None' #17

ghost opened this issue Aug 27, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 27, 2017

Hi there, when I ran the scripts as instructed, I got the RuntimeError. Below are the details:

(PYENV) --- files/clevr-iep ‹master* M?› » python scripts/run_model.py \                                        1 ↵
  --program_generator models/CLEVR/program_generator_18k.pt \
  --execution_engine models/CLEVR/execution_engine_18k.pt \
  --image img/CLEVR_val_000013.png \
  --question "Does the small sphere have the same color as the cube left of the gray cube?"

Loading program generator from  models/CLEVR/program_generator_18k.pt
Loading execution engine from  models/CLEVR/execution_engine_18k.pt
Loading CNN for feature extraction
Running the model

y is: None
y is: Variable containing:
 1
[torch.cuda.LongTensor of size 1x1 (GPU 0)]

y is: Variable containing:
 5
[torch.cuda.LongTensor of size 1 (GPU 0)]

Traceback (most recent call last):
  File "scripts/run_model.py", line 301, in <module>
    main(args)
  File "scripts/run_model.py", line 85, in main
    run_single_example(args, model)
  File "scripts/run_model.py", line 159, in run_single_example
    argmax=(args.sample_argmax == 1))
  File "/u/home/downloads/files/clevr-iep/iep/models/seq2seq.py", line 171, in reinforce_sample
    logprobs, h, c = self.decoder(encoded, cur_input, h0=h, c0=c)
  File "/u/home/downloads/files/clevr-iep/iep/models/seq2seq.py", line 93, in decoder
    V_in, V_out, D, H, L, N, T_in, T_out = self.get_dims(y=y)
  File "/u/home/downloads/files/clevr-iep/iep/models/seq2seq.py", line 58, in get_dims
    T_out = y.size(1) if y is not None else None
RuntimeError: invalid argument 2: out of range at /opt/conda/conda-bld/pytorch_1502009910772/work/torch/lib/THC/generic/THCTensor.c:23

My python is of version 3.6, and the latest pytorch is installed.
I have printed the content of y, and it can be None, 1-by-1 torch.cuda.LongTensor, and 1 torch.cuda.LongTensor. So, when the size is 1, T_out = y.size(1) will lead to the RuntimeError.

@manoja328
Copy link

change seq2seq model line 173
if argmax:
_, cur_output = probs.max(1)
else:

to
if argmax:
_, cur_output = probs.max(1)
cur_output = cur_output.unsqueeze(0)
else:

@olivernina
Copy link

that worked for me thanks manoja328

@manoja328
Copy link

manoja328 commented Oct 21, 2017 via email

@manoja328
Copy link

manoja328 commented Oct 21, 2017 via email

@suddu22
Copy link

suddu22 commented May 3, 2019

Hi
Use the code in the repo with no modification. Setup the environment as given in the readme.
Just make sure that your torch version is the one specified in the requirements.txt, your torchvision version is 0.1.9 and your python version is 3.5.2.
Hope it helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants