Encrypt/Decrypt model files

171 Views Asked by At

I have a trained pytorch model that I export using torch.jit.trace(model,input). It saves as a model.pt file. I am able to load the model in c++ (libtorch) using jit::load(). I want to encrypt the model file and decrypt them in memory and load it. How can I do this? Dont really know where to begin or how to approach this. Do I need to read the model file in as a stream and decrypt the stream? I tried to follow this https://discuss.pytorch.org/t/in-c-exporting-and-loading-torch-module-as-iostream-fails/127264/2 but unable to make a prediction after loading the model file the second time.

torch::jit::script::Module module;

module = torch::jit::load(path+"\\"+"model.pt")

When I try to load the model using this bit of code, the code runs but my output tensor is wrong shape.

std::filebuf infb;
infb.open()
std::istream is(&indb)

try{
module = torch::jit::load(is)

}
0

There are 0 best solutions below