从python访问caffe图层参数

时间:2018-03-13 19:53:56

标签: python caffe

在python中使用caffe,我想访问我的原型文件中指定的所有参数。

使用以下原型文字:

name: "VGG_ILSVRC_16_layers"
layer {
  name: "input"
  type: "Input"
  top: "data"
  input_param {
    shape {
      dim: 10
      dim: 3
      dim: 224
      dim: 224
    }
  }
}
layer {
  name: "conv1_1"
  type: "Convolution"
  bottom: "data"
  top: "conv1_1"
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
  }
}
...

我能做到:

>>> import sys, os
>>> import argparse
>>> import caffe
>>> caffenet = caffe.Net(str(deploy), str(cmodel), caffe.TEST)
>>> print caffenet.layers[1].type
Convolution
>>> print caffenet.layers[0].type
Input

但尝试访问其他参数失败:

>>> print caffenet.layers[0].top
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Layer' object has no attribute 'top'
>>> print caffenet.layers[0].input_param.shape
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Layer' object has no attribute 'input_param'

我应该如何访问第一层input_param.shape的前2个维度(10和3),或者conv1_1 num_output参数?

0 个答案:

没有答案
相关问题