gpt4 book ai didi

encryption - 通过字符串设置caffe net参数

转载 作者:行者123 更新时间:2023-12-04 17:50:50 24 4
gpt4 key购买 nike

我想做的是:

我加密了“.prototxt”和“.caffemodel”文件,所以文件不可读,参数不可见。在我的程序中,我解密文件并将结果存储为字符串。但现在我需要在我的 caffe 网络中设置层。

有没有一种方法可以使用我的字符串中的参数来设置 caffe 网络层?训练网络中的层也一样吗?与下面的源代码相当的东西(我知道这个源代码行不通)?

shared_ptr<Net<float> > net_;
string modelString;
string trainedString;

//Decryption stuff

net_.reset(new Net<float>(modelString, TEST));
net_->CopyTrainedLayersFrom(trainedString);

非常感谢。

最佳答案

您可以直接使用 NetParameter 类的 Protocol Buffer API 初始化 NetParameter 类(您需要包含 caffe/proto/caffe.pb.h):

bool ParseFromString(const string& data);

然后使用它通过以下构造函数初始化一个 Net 类:

explicit Net(const NetParameter& param, const Net* root_net = NULL);

以及复制权重:

void CopyTrainedLayersFrom(const NetParameter& param);

重要的是要注意,上述方法要求字符串变量包含二进制格式的 protobuffer 而不是文本格式。虽然 Caffe 输出的 caffemodel 已经是二进制格式,但您也必须将 prototxt 文件转换为二进制格式,但您可以使用 protoc 命令行程序结合 --encode 标志来完成此操作。

有关更多信息,我建议您查看 Protocol-Buffer 的网站:https://developers.google.com/protocol-buffers/

关于encryption - 通过字符串设置caffe net参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37159655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com