【问题标题】:Creating Deconvolution layer by NetSpec(): SyntaxError通过 NetSpec() 创建反卷积层:SyntaxError
【发布时间】:2018-04-12 14:05:34
【问题描述】:

我正在逐步通过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

有人可以帮忙吗?

非常感谢

【问题讨论】:

    标签: neural-network computer-vision caffe conv-neural-network pycaffe


    【解决方案1】:

    你的线路

    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(而不是 dicts 的列表),
    weight_fillerbias_filler 是传递给 dict 的一部分 convolution_params
    paramdicts 的列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      • 2017-03-24
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多