Skip to content

RuntimeError in eval_split() in eval_utils.py  #21

Open

Description

@aeonlin

When I run the eval.py given trained model results in the following form:
python2 ./eval.py --model_path ./save/model.pth --infos_path ./save/infos_st.pkl --cnn_model_path ./save/model-cnn.pth --image_folder ./data/images/val --num_images 10
I got the runtime error like the following:

Traceback (most recent call last):
  File "./eval.py", line 121, in <module>
    vars(opt))
  File "/home/student51/lab2/code/eval_utils.py", line 158, in eval_split
    alp_curr = alph[k,t,:].view(7,7).data.cpu().numpy()
  File "/usr/local/lib/python2.7/dist-packages/torch/tensor.py", line 374, in data
    raise RuntimeError('cannot call .data on a torch.Tensor: did you intend to use autograd.Variable?')
RuntimeError: cannot call .data on a torch.Tensor: did you intend to use autograd.Variable?

I then changed the code in eval_utils.py line 158 into
alp_curr = alph[k,t,:].view(7,7).numpy()

Then the evaluation completed without any errors, output caption-image pairs in the vis folder (meta information in vis/vis.json & images in vis/images/) and attention images in the code folder, as well as the evaluation loss shown in stdout.

My question is: should we do such modification in eval_utils.py line 158? Or am I breaking something else without receiving explicit error messages?

Activity

  1. connie980149 commented on Nov 19, 2017

    @connie980149
    Contributor

    In my case I need to change alph from GPU mode to CPU mode, so it needs to do .cpu().
    Maybe your return type of alph is different from mine, so you need to modify the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions