如何在Caffe库中用C ++或Python中的H5训练模型读取NetParameter?

时间:2017-03-15 02:52:11

标签: neural-network deep-learning caffe pycaffe

我喜欢加载训练有素的二进制文件并打印到文本文件中。

我们可以在C++ from caffemodel normally in binary protobuf format中阅读训练过的参数。

我是怎么做的,

net_.reset(new Net<float>(model_file, TEST));
    NetParameter param;

ReadNetParamsFromBinaryFileOrDie(trained_file_protobuf, &param);
WriteProtoToTextFile(param, "model_protobuf.txt");

但是一些经过训练的模型以h5格式出现,以及如何加载文件并使用C ++或Python打印到文本文件。

net.cpp中,我无法找到h5格式为ReadNetParamsFromBinaryFileOrDieReadNetParamsFromBinaryFileOrDie适用于binary protobuf format

如何从训练有素的H5模型中读取NetParameter并打印到文本文件?

1 个答案:

答案 0 :(得分:0)

您是否看过CopyTrainedLayersFromHDF5Net的方法)? 应该是这样的:

net_.reset(new Net<float>(model_file, TEST));
net_.CopyTrainedLayersFromHDF5(trained_file_h5);