3

Using caffe in python, I would like to access all the parameters specified in my prototxt.

With the following prototxt:

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
  }
}
...

I can do:

>>> 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

But attempts at accessing other parameters fail:

>>> 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'

How should I, say, access the first 2 dimensions (10 and 3) of the input_param.shape of the first layer, or conv1_1 num_output parameter?

Lolo
  • 3,935
  • 5
  • 40
  • 50
  • Perfect. This is indeed a duplicate question. The other SE answer works perfectly for what I was looking for. – Lolo Mar 14 '18 at 16:25

0 Answers0