回答

1

爲了增加Shai的答案 -
如果你不想全部權重文件,
爲了提取所需層的權重,使用net surgery

net = caffe.Net(prototxt, caffemodel, caffe.TRAIN) 
outnet = caffe.Net(predefined_prototxt_with_desired_layers_only, caffe.TRAIN) 
layers_to_copy = ['conv1', 'conv2', 'conv3'] 
for layer in layers_to_copy: 
    for i in range(0, len(net.params[layer])): #this is for copying both weights and bias, in case bias exists 
     outnet.params[layer][i].data[...]=np.copy(net.params[layer][i].data[...]) 

outnet.save(new_caffemodel_name) 
0

Caffe使用圖層的"name"爲圖層的blobs分配權重。 如果您更改頂層'"name"',則caffe將不會複製原始.caffemodel文件中的權重。

相關問題