如何保存预训练的 caffe 模型的子集?

How a subset of pretrained caffe model can be saved?

我正在研究具有 3 层的预训练 caffe 模型(在 python 中)。我想分解这个 caffe 模型并创建一个与该模型的第一层相同的新模型。例如:

原始 Caffe 模型 数据 -> conv1_1 -> conv1_2 -> conv2_1 -> conv2_2 -> conv3_1 -> conv3_2

新的 Caffe 模型 数据 -> conv1_1 -> conv1_2

有人可以帮我吗?

Python 公开了 .caffemodel 文件中的数据。它可以作为数组访问。例如,

net = caffe.Net('path/to/conv.prototxt', 'path/to/conv.caffemodel', caffe.TEST)
W = net.params['con_1'][0].data[...]
b = net.params['con_1'][1].data[...]

您可以将此数据复制到一个新文件中,并将其另存为 .caffemodel 文件。看看 this and this.