Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 谷歌深度梦:消息类型;caffe.NetParameter“;没有名为“的字段”;输入“U形”;_Python_Python 2.7_Deep Learning_Protocol Buffers_Caffe - Fatal编程技术网

Python 谷歌深度梦:消息类型;caffe.NetParameter“;没有名为“的字段”;输入“U形”;

Python 谷歌深度梦:消息类型;caffe.NetParameter“;没有名为“的字段”;输入“U形”;,python,python-2.7,deep-learning,protocol-buffers,caffe,Python,Python 2.7,Deep Learning,Protocol Buffers,Caffe,我想开始谷歌DeepDream IPython笔记本。我安装了笔记本中列出的依赖项(caffe和protobuf),并使用python的anaconda发行版启动了笔记本 model_path = '/home/dennis/caffe/models/bvlc_googlenet/' # substitute your path here net_fn = model_path + 'deploy.prototxt' param_fn = model_path + 'bvlc_googlen

我想开始谷歌DeepDream IPython笔记本。我安装了笔记本中列出的依赖项(caffe和protobuf),并使用python的anaconda发行版启动了笔记本

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".
---------------------------------------------------------------------------
ParseError回溯(上次最近的调用)
在()
7 model=caffe.io.caffe\u pb2.NetParameter()
8测试=打开(净)。读取()
---->9文本格式。合并(测试、模型)
10模型力_向后=真
11打开('tmp.prototxt','w')。写入(str(model))
/合并中的opt/anaconda/lib/python2.7/site-packages/google/protobuf/text_format.pyc(文本,消息)
263 ParseError:关于ASCII解析问题。
264   """
-->265返回合并行(text.split('\n'),消息)
266
267
/合并行(行、消息)中的opt/anaconda/lib/python2.7/site-packages/google/protobuf/text_format.pyc
296 ParseError:关于ASCII解析问题。
297   """
-->298_parsermerge(行、消息、真)
299返回消息
300
/opt/anaconda/lib/python2.7/site-packages/google/protobuf/text_format.pyc in_ParseOrMerge(行、消息、允许多个标量)
227标记器=_标记器(行)
228而不是标记器.AtEnd():
-->229 \u合并字段(标记器、消息、允许多个\u标量)
230
231
/opt/anaconda/lib/python2.7/site-packages/google/protobuf/text\u format.pyc in\u MergeField(标记器、消息、允许多个标量)
354 raise tokenizer.ParseErrorPreviousToken(
355'消息类型“%s”没有名为“%s”的字段。%(
-->356消息(描述符.全名,名称))
357
358如果field.cpp_type==descriptor.FieldDescriptor.cpp_消息:
ParseError:3:1:消息类型“caffe.NetParameter”没有名为“input\u shape”的字段。

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

在您的协议文本中,更改:

input_shape: {
dim: 1
dim: 3
dim: 224
dim: 224
}
表格至:

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

proto API在某些地方发生了变化。

这就是我使用Movidius neural compute sdk的解决方案。谢谢