如何将 .caffemodels 导出到其他应用程序?
How do you export .caffemodels to other applications?
是否可以翻译 .caffemodel 文件中的信息,以便(例如)Matlab 可以读取它。也就是说,有没有办法使用其他东西编写模型,prototxt 并导入使用 Caffe 训练的权重?
如果答案是 "Nope, it's a binary file and will always remain that way",是否有一些关于文件结构的文档,以便可以以某种方式提取重要信息?
如您所知,.caffemodel
由权重和偏差组成。
给定 prototxt 读取 caffe 模型的权重和偏差的一种简单方法是仅在 Python 中加载网络并读取权重。
您可以使用:
import caffe
net = caffe.Net(<prototxt-file>,<model-file>,<phase>);
并从 net.params
访问参数
我以VGG为例
from caffe.proto import caffe_pb2
net = caffe_pb2.NetParameter()
caffemodel = sys.argv[1]
with open(caffemodel, 'rb') as f:
net.ParseFromString(f.read())
for i in net.layer:
print i.ListFields()[0][-1]
#conv1
#relu1
#norm1
#pool1
#conv2
#relu2
#norm2
#pool2
#conv3
#relu3
#conv4
#relu4
#conv5
#relu5
#pool5
#fc6
#relu6
#drop6
#fc7
#relu7
#drop7
#fc8
#prob
是否可以翻译 .caffemodel 文件中的信息,以便(例如)Matlab 可以读取它。也就是说,有没有办法使用其他东西编写模型,prototxt 并导入使用 Caffe 训练的权重?
如果答案是 "Nope, it's a binary file and will always remain that way",是否有一些关于文件结构的文档,以便可以以某种方式提取重要信息?
如您所知,.caffemodel
由权重和偏差组成。
给定 prototxt 读取 caffe 模型的权重和偏差的一种简单方法是仅在 Python 中加载网络并读取权重。
您可以使用:
import caffe
net = caffe.Net(<prototxt-file>,<model-file>,<phase>);
并从 net.params
我以VGG为例
from caffe.proto import caffe_pb2
net = caffe_pb2.NetParameter()
caffemodel = sys.argv[1]
with open(caffemodel, 'rb') as f:
net.ParseFromString(f.read())
for i in net.layer:
print i.ListFields()[0][-1]
#conv1
#relu1
#norm1
#pool1
#conv2
#relu2
#norm2
#pool2
#conv3
#relu3
#conv4
#relu4
#conv5
#relu5
#pool5
#fc6
#relu6
#drop6
#fc7
#relu7
#drop7
#fc8
#prob