torralba-lab / im2recipe

Code supporting the CVPR 2017 paper "Learning Cross-modal Embeddings for Cooking Recipes and Food Images"
MIT License
377 stars 89 forks source link

Testing model: attempt to call method 'double' (a nil value) #17

Closed marielvanstav closed 6 years ago

marielvanstav commented 6 years ago

Hi there! I'm trying to test my own dataset on the pre-trained model, by running: th main.lua -ngpus 1 -test 1 -dataset path/to/data.h5 -ingrW2V /path/to/vocab.bin -semantic 0 -loadsnap im2recipe_model.t7

I get the following output:

{ resnet_model : "/var/scratch/mvstaver/im2recipe_code/data/vision/resnet-50.t7" extract : "test" dispfreq : 1000 batchSize : 150 maxImgs : 5 stDim : 1024 imstore : 256 imfeatDim : 2048 niters : -1 valfreq : 10000 gpu : 1 loadsnap : "im2recipe_model.t7" test : 1 numClasses : 1048 patience : 3 net : "resnet" nworkers : 4 caffemodel : "/var/scratch/mvstaver/im2recipe_code/data/vision/VGG_ILSVRC_16_layers.caffemodel" irnnDim : 300 embDim : 1024 cosw : 0.98 seed : 4242 semantic : 0 maxIngrs : 20 ingrW2VDim : 300 clsw : 0.01 dec_lr : 1 imsize : 224 n_layer_trijoint : 7 iter_swap : -1 mismatchFreq : 0.8 remove : 2 dataset : "/var/scratch/mvstaver/data/jamie_oliver/data.h5" proto : "/var/scratch/mvstaver/im2recipe_code/data/vision/VGG_ILSVRC_16_layers_deploy.prototxt" ngpus : 1 freeze_first : "vision" lr : 0.0001 ingrW2V : "/var/scratch/mvstaver/data/recipe1m/vocab.bin" maxSeqlen : 20 optim : "adam" srnnDim : 1024 snapfile : "snaps/resnet_reg" backend : "cudnn" rundesc : "" nRNNs : 1 } Loading model from im2recipe_model.t7
loading data
data loaded Testing model
3000
/home/mvstaver/torch/install/bin/luajit: ...mvstaver/torch/install/share/lua/5.1/threads/threads.lua:179: [thread 1 endcallback] /var/scratch/mvstaver/im2recipe_code/drivers/test.lua:80: attempt to call method 'double' (a nil value) stack traceback: /var/scratch/mvstaver/im2recipe_code/drivers/test.lua:80: in function </var/scratch/mvstaver/im2recipe_code/drivers/test.lua:40> [C]: in function 'xpcall' ...mvstaver/torch/install/share/lua/5.1/threads/threads.lua:174: in function 'dojob' ...mvstaver/torch/install/share/lua/5.1/threads/threads.lua:223: in function 'addjob' /var/scratch/mvstaver/im2recipe_code/drivers/test.lua:38: in function </var/scratch/mvstaver/im2recipe_code/drivers/test.lua:24> /var/scratch/mvstaver/im2recipe_code/drivers/init.lua:47: in function </var/scratch/mvstaver/im2recipe_code/drivers/init.lua:45> /var/scratch/mvstaver/im2recipe_code/drivers/init.lua:43: in function 'test' main.lua:50: in main chunk [C]: in function 'dofile' ...aver/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x004064f0 stack traceback: [C]: in function 'error' ...mvstaver/torch/install/share/lua/5.1/threads/threads.lua:179: in function 'dojob' ...mvstaver/torch/install/share/lua/5.1/threads/threads.lua:223: in function 'addjob' /var/scratch/mvstaver/im2recipe_code/drivers/test.lua:38: in function </var/scratch/mvstaver/im2recipe_code/drivers/test.lua:24> /var/scratch/mvstaver/im2recipe_code/drivers/init.lua:47: in function </var/scratch/mvstaver/im2recipe_code/drivers/init.lua:45> /var/scratch/mvstaver/im2recipe_code/drivers/init.lua:43: in function 'test' main.lua:50: in main chunk [C]: in function 'dofile' ...aver/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x004064f0

Does anyone have any idea what could cause this error?

Thanks!

nhynes commented 6 years ago

According to the second line of the stack trace, it looks like batchImgEmbs isn't a Tensor because it's nil. You should ensure that your data are formatted in the same way as the original data.

marielvanstav commented 6 years ago

Thanks for the quick reply! You are right, torch.type(embs) returns table instead of Tensor. When I run in with the default -semantic 1, it does work. Is it possible to test the pre-trained model with -semantic 0 (even though it has been trained with -semantic 1)?

nhynes commented 6 years ago

possible to test the pre-trained model with -semantic 0

It is, but you'd have to do some model surgery to remove the semantic branch and extract just the RNN and CNN.

marielvanstav commented 6 years ago

Okay, thanks! One more question: I want to test other datasets on the pre-trained model. When making the HDF5 files for these datasets, am I right to assume that I should use the word2vec model (and the corresponding vocabulary in vocab.txt) that has been trained on the Recipe1M data, or do I need to train a new word2vec model for each dataset? Thanks for sharing your great work!

nhynes commented 6 years ago

do I need to train a new word2vec model for each dataset?

If you want to use the pre-trained model, you'll have to use the pre-trained word2vec since that's what the later layers of the model expect. Of course, if your test dataset is sufficiently large and different from Recipe1M, you can always try fine tuning the pre-trained model.

marielvanstav commented 6 years ago

Clear! Thanks again!