caffe2 icon indicating copy to clipboard operation
caffe2 copied to clipboard

[Loading Pretrained Models tutorial] Runtime error while running "predictor.run([x])"

Open jiminHwa opened this issue 7 years ago • 1 comments

I'm trying the loading pretrained model tutorial. As issue #1559, #1836, I also get a similar runtime error. My code fragment is as follows:

workspace.FeedBlob("data", img)

with open(INIT_NET) as f:
    init_net = f.read()
with open(PREDICT_NET) as f:
    predict_net = f.read()
    
p = workspace.Predictor(init_net, predict_net)

The entire code is almost identical, except "workspace.FeedBlob("data", img)". The line is added because there was "no such blob: 'data'" error. The error is resolved by the line.

But new error comes up as follows:

RuntimeErrorTraceback (most recent call last)
<ipython-input-34-4b361f14ecae> in <module>()
      1 # run the net and return prediction
----> 2 results = p.run([img])

RuntimeError: [enforce fail at conv_op_impl.h:37] filter.dim32(i + 2) == kernel_[i].  Error from operator: 
input: "data" input: "conv1_w" input: "conv1_b" output: "conv1" type: "Conv" arg { name: "stride" i: 2 } arg { name: "pad" i: 0 } arg { name: "kernel" i: 3 } device_option { } engine: ""

The error message is a little bit different from #1559, #1836.

To test the "results = predictor.run([img]) " part, I ran the following code:

import numpy
import caffe2.python.workspace
from caffe2.proto import caffe2_pb2

x = numpy.ones([1, 784], dtype=numpy.float32)

caffe2.python.workspace.FeedBlob("data", x)

with open('/caffe2/caffe2/python/models/squeezenet/init_net.pb', 'rb') as f:
    init_net = f.read()
with open('/caffe2/caffe2/python/models/squeezenet/predict_net.pb', 'rb') as f:
    predict_net = f.read()

predictor = caffe2.python.workspace.Predictor(init_net, predict_net)

output = predictor.run([x])

And I got the following error message:

RuntimeErrorTraceback (most recent call last)
<ipython-input-31-6394631f3be1> in <module>()
     18 predictor = caffe2.python.workspace.Predictor(init_net, predict_net)
     19 
---> 20 output = predictor.run([x])

RuntimeError: [enforce fail at tensor.h:628] i < dims_.size(). 2 vs 2. Exceeding ndim limit Error from operator: 
input: "data" input: "conv1_w" input: "conv1_b" output: "conv1" type: "Conv" arg { name: "stride" i: 2 } arg { name: "pad" i: 0 } arg { name: "kernel" i: 3 } device_option { } engine: ""
** while accessing input: conv1_w

Almost similar with, but a little bit different from.

So I am stuck in this issue. If you have any insight, please help me. Thank you, guys.

jiminHwa avatar Feb 01 '18 06:02 jiminHwa

Hi @jiminHwa - it looks like the SqueezeNet model in Amazon S3 (where the model downloader gets files from) was corrupt. I've just updated with the one in GitHub. Can you confirm doing the following

python -m caffe2.python.models.download -i squeezenet

again and replacing the file allows you to run the tutorial? Thanks for your patience!

orionr avatar Feb 01 '18 18:02 orionr