2017-09-07 8 views
1

.prototxtで定義されたCaffeネットワークのネットワークパラメータをPythonのレイヤオブジェクトとして読んでみたいと思います。layer_dictのみ教えてください。その "畳み込み"層ですが、.prototxtファイルではよく定義されているkernel_sizestridesなどのようなものではありません。Pythonのcaffe .prototxtモデル定義からネットワークパラメータを読み取る

だから私はそうのようなmodel.prototxtを持って言うことができます:

name: "Model" 
layer { 
    name: "data" 
    type: "Input" 
    top: "data" 
    input_param { 
    shape: { 
     dim: 64 
     dim: 1 
     dim: 28 
     dim: 28 
    } 
    } 
} 
layer { 
    name: "conv2d_1" 
    type: "Convolution" 
    bottom: "data" 
    top: "conv2d_1" 
    convolution_param { 
    num_output: 32 
    kernel_size: 3 
    stride: 1 
    weight_filler { 
     type: "gaussian" # initialize the filters from a Gaussian 
     std: 0.01  # distribution with stdev 0.01 (default mean: 0) 
    } 
    bias_filler { 
     type: "constant" 
     value: 0 
    } 
    } 
} 

layer { 
    name: "dense_1" 
    type: "InnerProduct" 
    bottom: "conv2d_1" 
    top: "out" 
    inner_product_param { 
    num_output: 1024 
    weight_filler { 
     type: "gaussian" 
     std: 0.01 
    } 
    bias_filler { 
     type: "constant" 
     value: 0 
    } 
    } 
} 

私は1つはそうのようなモデルを解析できることを見出した:

from caffe.proto import caffe_pb2 
import google.protobuf.text_format 
net = caffe_pb2.NetParameter() 
f = open('model.prototxt', 'r') 
net = google.protobuf.text_format.Merge(str(f.read()), net) 
f.close() 

が、私はフィールドを取得する方法が分かりません結果オブジェクトからprotobufメッセージを取り出します。

答えて

1

あなたが適切な* _paramタイプは、たとえば、caffe.protoで見つけることができる層を反復処理し、例えば、それらに対応するのparamについて尋ねる:

for i in range(0, len(net.layer)): 
    if net.layer[i].type == 'Convolution': 
     net.layer[i].convolution_param.bias_term = True # bias term, for example 

をすることができます

optional ConvolutionParameter convolution_param = 106 
関連する問題