Cadene / vqa.pytorch

Visual Question Answering in Pytorch
717 stars 178 forks source link

iteration over a 0-d tensor when trying to run the demo #35

Closed marcotcr closed 6 years ago

marcotcr commented 6 years ago

When trying to run the demo, model(visual, question) fails, yielding:

...
~/phd/vqa.pytorch/vqa/external/skip-thoughts.torch/pytorch/skipthoughts.py in _process_lengths(self, input)
    132     def _process_lengths(self, input):
    133         max_length = input.size(1)
--> 134         lengths = list(max_length - input.data.eq(0).sum(1).squeeze())
    135         return lengths
    136 

~/python3_env/lib/python3.5/site-packages/torch/tensor.py in __iter__(self)
    358         # map will interleave them.)
    359         if self.dim() == 0:
--> 360             raise TypeError('iteration over a 0-d tensor')
    361         return iter(imap(lambda i: self[i], range(self.size(0))))
    362 

TypeError: iteration over a 0-d tensor

If I change line 134 to: lengths = [max_length - input.data.eq(0).sum(1).squeeze())] I don't get the error anymore, but I only get nonsensical results with the pretrained model, for different images, I don't know if this is related or not.

Using torch 0.4.

Cadene commented 6 years ago

You should certainly try with torch 0.3

I did not try this code with torch 0.4

marcotcr commented 6 years ago

Thanks for the quick reply. I tried it with torch 0.3, and it works. However, the pretrained model answers 'yes' to pretty much any question for all of the images I tried.

Cadene commented 6 years ago

I think I messed with dictionnary.items() somewhere. I know that the order can change depending on your system.

I uploaded my preprocessed files. Please verify that my wid_to_word.pickle and ans_to_aid.pickle dictionaries are the same. If not, you these preprocessed data instead of yours.

wget http://data.lip6.fr/cadene/vqa.pytorch/vqa2/nans,2000_maxlength,26_minwcount,0_nlp,mcb_pad,right_trainsplit,train.tar.gz
wget http://data.lip6.fr/cadene/vqa.pytorch/vqa2/nans,2000_maxlength,26_minwcount,0_nlp,mcb_pad,right_trainsplit,trainval.tar.gz
marcotcr commented 6 years ago

To be clear, these are files that should be inside data/vqa2/processed, right? If so, they were different. Replacing them did not change much though - the model still answers Yes to most questions, sometimes it now answers No.

Cadene commented 6 years ago

Yes inside data/vqa2/processed.

Cadene commented 6 years ago

This behavior is not normal :/ You should certainly train your own model.

I am sorry but I can't help you with that. I am currently working on a better implementation. It should be out soon.

marcotcr commented 6 years ago

ok, thanks.