Google DeepDream:消息类型“caffe.NetParameter”没有名为“input_shape”的字段

时间:2015-11-16 09:52:57

标签: python python-2.7 deep-learning protocol-buffers caffe

我想从https://github.com/google/deepdream启动Google DeepDream IPython Notebook。我安装了笔记本中列出的依赖项(caffe和protobuf),并使用anaconda发布的python启动了笔记本。

model_path = '/home/dennis/caffe/models/bvlc_googlenet/' # substitute your path here
net_fn   = model_path + 'deploy.prototxt'
param_fn = model_path + 'bvlc_googlenet.caffemodel'

# Patching model to be able to compute gradients.
# Note that you can also manually add "force_backward: true" line to "deploy.prototxt".
model = caffe.io.caffe_pb2.NetParameter()
text_format.Merge(open(net_fn).read(), model)
model.force_backward = True
open('tmp.prototxt', 'w').write(str(model))

net = caffe.Classifier('tmp.prototxt', param_fn,
                       mean = np.float32([104.0, 116.0, 122.0]), # ImageNet mean, training set dependent
                       channel_swap = (2,1,0)) # the reference model has channels in BGR order instead of RGB

# a couple of utility functions for converting to and from Caffe's input image layout
def preprocess(net, img):
    return np.float32(np.rollaxis(img, 2)[::-1]) - net.transformer.mean['data']
def deprocess(net, img):
    return np.dstack((img + net.transformer.mean['data'])[::-1])

运行此代码单元时会引发错误:

ParseError: 3:1 : Message type "caffe.NetParameter" has no field named "input_shape".

这是完整的堆栈跟踪:

---------------------------------------------------------------------------
ParseError                                Traceback (most recent call last)
<ipython-input-9-200e4a0e8ca1> in <module>()
      7 model = caffe.io.caffe_pb2.NetParameter()
      8 test = open(net_fn).read()
----> 9 text_format.Merge(test, model)
     10 model.force_backward = True
     11 open('tmp.prototxt', 'w').write(str(model))

/opt/anaconda/lib/python2.7/site-packages/google/protobuf/text_format.pyc in Merge(text, message)
    263     ParseError: On ASCII parsing problems.
    264   """
--> 265   return MergeLines(text.split('\n'), message)
    266 
    267 

/opt/anaconda/lib/python2.7/site-packages/google/protobuf/text_format.pyc in MergeLines(lines, message)
    296     ParseError: On ASCII parsing problems.
    297   """
--> 298   _ParseOrMerge(lines, message, True)
    299   return message
    300 

/opt/anaconda/lib/python2.7/site-packages/google/protobuf/text_format.pyc in _ParseOrMerge(lines, message, allow_multiple_scalars)
    227   tokenizer = _Tokenizer(lines)
    228   while not tokenizer.AtEnd():
--> 229     _MergeField(tokenizer, message, allow_multiple_scalars)
    230 
    231 

/opt/anaconda/lib/python2.7/site-packages/google/protobuf/text_format.pyc in _MergeField(tokenizer, message, allow_multiple_scalars)
    354       raise tokenizer.ParseErrorPreviousToken(
    355           'Message type "%s" has no field named "%s".' % (
--> 356               message_descriptor.full_name, name))
    357 
    358   if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:

ParseError: 3:1 : Message type "caffe.NetParameter" has no field named "input_shape".

真的不知道如何修复此错误。我希望你们能帮助我。

1 个答案:

答案 0 :(得分:0)

在原型文件中,更改:

input_shape: {
dim: 1
dim: 3
dim: 224
dim: 224
}

表格:

input_dim: 1
input_dim: 3
input_dim: 224
input_dim: 224

proto API在某处发生了变化。