最近工作中需要对caffe的prototxt和model文件进行加密操作。翻看github,浏览到了一份不错的code。
进过调试,主体代码是没有问题。
1:自己需要的改动是使用二进制方式读取model。
2:还需要加入一下自己的明文,防止他人使用相同代码进行解密。
fprototxt.open(prototxtFile);
fmodel.open(caffemodelFile);
替换成
fprototxt.open(prototxtFile);
fmodel.open(caffemodelFile, std::ios::binary);
3:如何调试加解密调试
// **********************
std::ofstream test_proto;
test_proto.open(R"(I:\encryption_proto.txt)");
for (size_t i = 0; i < enc_prototxt_file_size; i++)
{
test_proto << prototxt_file_buffer[i];
}
test_proto.close();
// **********************
// **********************
std::ofstream test_proto;
test_proto.open(R"(I:\decryption_proto.txt)");
for (size_t i = 0; i < prototxt_string.size(); i++)
{
test_proto << prototxt_string[i];
}
test_proto.close();
// **********************
感兴趣的可以尝试一下。
https://github.com/xialuxi/encryptio_caffemodel
1、模型使用rc6算法加密
2、模型解密
3、在内存中加载网络
(๑•ᴗ•๑)觉得有用,赏个植发的小钱钱。(๑•ᴗ•๑)