How can I access layer parametr as eg. convolution_param.num_output in python API

18 views
Skip to first unread message

Jan Pohanka

unread,
May 11, 2017, 9:25:57 AM5/11/17
to Caffe Users
Hi,
I cannot found how to access layer parameters from python

net = caffe.Net(model_filename, weight_filename, caffe.TEST)
net.layers[0]. ???

Is there such API?

thanks
Jan

Mark

unread,
May 11, 2017, 1:00:49 PM5/11/17
to Caffe Users
Here's one option if you are reading in a protobuf file and want to access the parameters.

import caffe
from google.protobuf import text_format

net_config
= caffe.proto.caffe_pb2.NetParameter()

train_file
= "/path/to/file/train.prototxt"

file
= open(train_file, "r")
text_format
.Merge(str(file.read()), net_config)
file
.close()

# At this point you can access the layer information from the net_config object
# For example get all the layers in the network with:
layer_list
= net_config.layer

# View all the layers with protobuf formatting:
for layer in layer_list:
   
print(layer)

# Assuming layer 5 is a convolution parameter you can access the num_output parameter with:
conv_num_out
= layer_list[5].convolution_param.num_output


You can access any parameter of the network this way.

    -Mark

Jan Pohanka

unread,
May 12, 2017, 2:11:45 AM5/12/17
to Caffe Users
Hi Mark,

thanks for suggestion. This might be a solution even if it not seems very elegant to me..

Dne čtvrtek 11. května 2017 19:00:49 UTC+2 Mark napsal(a):
Reply all
Reply to author
Forward
0 new messages