gpt4 book ai didi

python - 谷歌 DeepDream : Message type "caffe.NetParameter" has no field named "input_shape"

转载 作者:行者123 更新时间:2023-11-28 19:15:44 25 4
gpt4 key购买 nike

我想从 https://github.com/google/deepdream 启动 Google DeepDream IPython Notebook .我安装了笔记本中列出的依赖项(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".

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

最佳答案

在你的 prototxt 中,改变:

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

表格:

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

原型(prototype) API 在某处发生了变化。

关于python - 谷歌 DeepDream : Message type "caffe.NetParameter" has no field named "input_shape",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33732477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com