我正在通过caffe.NetSpec()函数定义网络,但我不是编程方面的专家。
我正在通过NetSpec定义一个函数来为网络创建Deconvolution层。下面是图层定义应该是:
layer {
name: "deconv1"
type: "Deconvolution"
bottom: "bottom1"
top: "top1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 512
kernel_size: 7
stride: 1
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}下面是函数定义:
def deconv_relu(bottom,nout,ks=3,stride=1,pad=1,std=0.01):
deconv=L.Deconvolution(bottom,
convolution_param=[dict(num_output=nout, kernel_size=ks, stride=stride, pad=pad),
param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]])
## weight_filler=dict(type= 'gaussian', std=std),
## bias_filler=dict(type= 'constant',value=0))
return deconv通过添加weight_filler和'bias_filler‘,它显示了以下错误:
File "./first_try.py", line 78
n.fc6-deconv=deconv_relu(n.fc7,512,ks=7)
SyntaxError: can't assign to operator在注释掉这两行之后,它显示了这个错误:
File "./first_try.py", line 18
param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]])
^
SyntaxError: invalid syntax有人能帮个忙吗?
非常感谢
发布于 2017-10-31 20:50:56
你的产品线
n.fc6-deconv=deconv_relu(n.fc7,512,ks=7)无论您的deconv_relu实现如何,都会显示一个错误,因为您正在尝试为n.fc6 - deconv赋值: python将层名称中的破折号(-)解释为减号运算符。您需要为图层选择一个新名称。
至于使用caffeNetSpec()定义"Deconvolution"层:
deconv=L.Deconvolution(bottom,
convolution_param=dict(num_output=nout,
kernel_size=ks,
stride=stride,
pad=pad,
weight_filler=dict(type='gaussian', std=std),
bias_filler=dict(type= 'constant',value=0)),
param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]])注意,convolution_param得到一个dict (而不是dict的列表),
weight_filler和bias_filler是传递给convolution_params的dict的一部分,并且
param是dict的列表。
https://stackoverflow.com/questions/47034809
复制相似问题