Add watermark in engine file?

I have trained my custom yolov4, and successfully able to run with deep-stream-app. Now, I want to encrypt model file by adding watermark (Ref: How to add the encryption and decryption model part of the program - #6 by mchi). but I have not found any sample, some example will be helpful. Thanks.

Hi @muhammadrizwanmunawar ,
We don’t have the sample for now.
But I think it’s not difficult to implement it by yourself.

Here is the rough idea.

  1. you give a TensorRT engine file encrypted with watermark or other encryption change to nvinfer with “model-engine-file” properity
  2. In nvinfer code - /opt/nvidia/deepstream/deepstream-6.0/sources/libs/nvdsinfer/nvdsinfer_model_builder.cpp
/* Deserialize engine from file */
std::unique_ptr<TrtEngine>
TrtModelBuilder::deserializeEngine(const std::string& path, int dla)
{
    std::ifstream fileIn(path, std::ios::binary);
    if (!fileIn.is_open())
    {
        dsInferError(
            "Deserialize engine failed because file path: %s open error",
            safeStr(path));
        return nullptr;
    }
    ....                       // **---> after file is opened, you can add your own code to remove the watermark or do some things others to 'decrypt' to TensorRT engine** 
    UniquePtrWDestroy<nvinfer1::ICudaEngine> engine =
        runtime->deserializeCudaEngine(data.data(), size, factory);           **// ---> TRT API to deserialize the decrypted TRT engine**
  ...
}

Thanks @mchi, I implemented my own code by followed steps you told in above answer. Now the issue is "How to compile that file (nvdsinfer_model_builder.cpp), I have seen make-file but when i tried, it throws library error. in general I directly install deep-stream-app and run sample apps. no make needed.
Thanks

what the error?

I’m closing this, since I saw you have filed Encryption and decryption not working in deep-stream-app(model file)? - #3 by mchi and didn’t get your response here.

1 Like