2017-07-19 63 views
3

我有一個caffemodel文件,其中包含ethereon的caffe-tensorflow轉換實用程序不支持的圖層。我想生成一個我caffemodel的代表性。如何加載caffe模型並轉換爲numpy數組?

我的問題是,如何將一個caffemodel文件(我也有prototxt,如果有用的話)轉換爲一個numpy文件?

附加信息:我有python,安裝了python接口等的caffe。我顯然沒有經歷過咖啡。

回答

6

這裏是一個不錯的功能,一個朱古力淨轉換成詞典的蟒列表,這樣就可以泡製它,反正讀它,你想:

import caffe 

def shai_net_to_py_readable(prototxt_filename, caffemodel_filename): 
    net = caffe.Net(prototxt_filename, caffemodel_filename, caffe.TEST) # read the net + weights 
    pynet_ = [] 
    for li in xrange(len(net.layers)): # for each layer in the net 
    layer = {} # store layer's information 
    layer['name'] = net._layer_names[li] 
    # for each input to the layer (aka "bottom") store its name and shape 
    layer['bottoms'] = [(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape) 
         for bi in list(net._bottom_ids(li))] 
    # for each output of the layer (aka "top") store its name and shape 
    layer['tops'] = [(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape) 
         for bi in list(net._top_ids(li))] 
    layer['type'] = net.layers[li].type # type of the layer 
    # the internal parameters of the layer. not all layers has weights. 
    layer['weights'] = [net.layers[li].blobs[bi].data[...] 
         for bi in xrange(len(net.layers[li].blobs))] 
    pynet_.append(layer) 
return pynet_ 
相關問題