关于机器学习:你能从网络的前 3 层复制权重吗?不完全微调,但几乎重塑 | 珊瑚贝

Can you copy the weights from just the first 3 layers of a network? Not exactly finetuning, but almost reshaping


在 caffe 中,我希望仅将预训练的权重用于使用 ImageNet 数据集训练的 alexnet 架构,仅用于前两层,并且我想在这两层之后添加一个 softmax 分类器。我想知道如何才能从包含更大网络结构(真正的”深度”Alexnet 结构)的权重文件中仅提取前两层的权重。


补充 Shai 的答案-
如果您不想要完整的权重文件,
为了提取所需层的权重,请使用网络手术:

1
2
3
4
5
6
7
8
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)


Caffe 使用层的 “name” 将权重分配给层的 blobs。
如果您更改顶层的 “name”,则 caffe 不会从原始 .caffemodel 文件中复制权重。


来源:https://www.codenong.com/46420040/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9459.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?