Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad argument #1 to 'insert' (table expected, got nil) #62

Open
BGrasnick opened this issue Oct 20, 2015 · 10 comments
Open

bad argument #1 to 'insert' (table expected, got nil) #62

BGrasnick opened this issue Oct 20, 2015 · 10 comments

Comments

@BGrasnick
Copy link

Hey,

first of all awesome work, I really want to try it out myself but the results in the README.md look amazing!
Unfortunately after installing protobuf, torch and loadcaffe, I always get the following error when trying th neural_style.lua -gpu -1 -print_iter -1:

[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message. If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 574671192
Successfully loaded models/VGG_ILSVRC_19_layers.caffemodel
/usr/local/bin/luajit: models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:2: bad argument #1 to 'insert' (table expected, got nil)
stack traceback:
[C]: in function 'insert'
models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:2: in main chunk
[C]: in function 'dofile'
./loadcaffe_wrapper.lua:48: in function 'load'
neural_style.lua:65: in function 'main'
neural_style.lua:454: in main chunk
[C]: in function 'dofile'
/usr/local/lib/luarocks/rocks/trepl/scm-1/bin/th:133: in main chunk
[C]: at 0x00405610

Do you know what is going wrong? Here are my system specs:

OS: Manjaro 15.09 Bellatrix
Kernel: x86_64 Linux 4.1.10-1-MANJARO
CPU: Intel Core i5-4200U CPU @ 2.6GHz
GPU: GeForce GT 730M

Thanks for your awesome work!

@jcjohnson
Copy link
Owner

Can you post your /usr/local/bin/luajit: models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua file?

@BGrasnick
Copy link
Author

Thanks for the quick answer!

Sure here it is:

require 'nn'
table.insert(model, {'conv1_1', nn.SpatialConvolutionMM(3, 64, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'conv1_2', nn.SpatialConvolutionMM(64, 64, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu1_2', nn.ReLU(true)})
table.insert(model, {'pool1', nn.SpatialMaxPooling(2, 2, 2, 2, 0, 0):ceil()})
table.insert(model, {'conv2_1', nn.SpatialConvolutionMM(64, 128, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu2_1', nn.ReLU(true)})
table.insert(model, {'conv2_2', nn.SpatialConvolutionMM(128, 128, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu2_2', nn.ReLU(true)})
table.insert(model, {'pool2', nn.SpatialMaxPooling(2, 2, 2, 2, 0, 0):ceil()})
table.insert(model, {'conv3_1', nn.SpatialConvolutionMM(128, 256, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu3_1', nn.ReLU(true)})
table.insert(model, {'conv3_2', nn.SpatialConvolutionMM(256, 256, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu3_2', nn.ReLU(true)})
table.insert(model, {'conv3_3', nn.SpatialConvolutionMM(256, 256, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu3_3', nn.ReLU(true)})
table.insert(model, {'conv3_4', nn.SpatialConvolutionMM(256, 256, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu3_4', nn.ReLU(true)})
table.insert(model, {'pool3', nn.SpatialMaxPooling(2, 2, 2, 2, 0, 0):ceil()})
table.insert(model, {'conv4_1', nn.SpatialConvolutionMM(256, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu4_1', nn.ReLU(true)})
table.insert(model, {'conv4_2', nn.SpatialConvolutionMM(512, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu4_2', nn.ReLU(true)})
table.insert(model, {'conv4_3', nn.SpatialConvolutionMM(512, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu4_3', nn.ReLU(true)})
table.insert(model, {'conv4_4', nn.SpatialConvolutionMM(512, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu4_4', nn.ReLU(true)})
table.insert(model, {'pool4', nn.SpatialMaxPooling(2, 2, 2, 2, 0, 0):ceil()})
table.insert(model, {'conv5_1', nn.SpatialConvolutionMM(512, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu5_1', nn.ReLU(true)})
table.insert(model, {'conv5_2', nn.SpatialConvolutionMM(512, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu5_2', nn.ReLU(true)})
table.insert(model, {'conv5_3', nn.SpatialConvolutionMM(512, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu5_3', nn.ReLU(true)})
table.insert(model, {'conv5_4', nn.SpatialConvolutionMM(512, 512, 3, 3, 1, 1, 1, 1)})
table.insert(model, {'relu5_4', nn.ReLU(true)})
table.insert(model, {'pool5', nn.SpatialMaxPooling(2, 2, 2, 2, 0, 0):ceil()})
table.insert(model, {'torch_view', nn.View(-1):setNumInputDims(3)})
table.insert(model, {'fc6', nn.Linear(25088, 4096)})
table.insert(model, {'relu6', nn.ReLU(true)})
table.insert(model, {'drop6', nn.Dropout(0.500000)})
table.insert(model, {'fc7', nn.Linear(4096, 4096)})
table.insert(model, {'relu7', nn.ReLU(true)})
table.insert(model, {'drop7', nn.Dropout(0.500000)})
table.insert(model, {'fc8', nn.Linear(4096, 1000)})
table.insert(model, {'prob', nn.SoftMax()})
return model

@jcjohnson
Copy link
Owner

Aha, looks like loadcaffe changed a bit here:

szagoruyko/loadcaffe@62f6ea2

I was using a dirty dirty hack to allow neural-style to work with loadcaffe on CPU; looks like they have improved their CPU support, hopefully making my hack unnecessary.

I don't have time right now to fix this, but for a quick workaround you can try installing the version of loadcaffe right before the commit I posted above.

@cjrd
Copy link

cjrd commented Oct 23, 2015

I seem to be running into the same issue.
I tried installing the suggested version of loadcaffe, but I encounter the same error.

models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:2: bad argument #1 to 'insert' (table expected, got nil)

@akkikiki
Copy link

For my case, by removing https://github.com/jcjohnson/neural-style/blob/master/loadcaffe_wrapper.lua#L41 and https://github.com/jcjohnson/neural-style/blob/master/loadcaffe_wrapper.lua#L43, it worked.
These lines cause to skip copying the table initialization local model = {}.

@lploom
Copy link

lploom commented Oct 25, 2015

@akkikiki solution worked for me as well

@cjrd
Copy link

cjrd commented Oct 26, 2015

@akkikiki solution also worked for me (now I just need some more RAM =\ )

@bduerst
Copy link

bduerst commented Oct 27, 2015

For those doing akkikiki's workaround and not that fluent with lua like me, make sure you don't delete line 42. Thanks akkikiki - it works.

@jcjohnson
Copy link
Owner

@akkikiki Thanks for looking into this! I implemented your fix in 8795bbf.

Interestingly, the reason I originally added the loadcaffe_wrapper (instead of just calling loadcaffe) was to make it work in CPU mode; now we don't need that, since loadcaffe works just fine in CPU mode. However we still need loadcaffe_wrapper because it copies the names of the layers from prototxt over to lua, which we need to set the layers to use for content and style targets.

@akkikiki
Copy link

@jcjohnson Cool! Thanks for the work! I am glad to hear that my comment helped many people.

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

No branches or pull requests

6 participants