'ai.djl.engine.EngineException: PytorchStreamReader failed locating file constants.pkl: file not found

I tried to use DJL to load the Yolov5 model for target recognition, but an error was reported.

ai.djl.engine.EngineException: PytorchStreamReader failed locating file constants.pkl: file not found
        at ai.djl.pytorch.jni.PyTorchLibrary.moduleLoad(Native Method)
        at ai.djl.pytorch.jni.JniUtils.loadModule(JniUtils.java:1360)
        at ai.djl.pytorch.engine.PtModel.load(PtModel.java:89)
        at ai.djl.repository.zoo.BaseModelLoader.loadModel(BaseModelLoader.java:156)
        at ai.djl.repository.zoo.Criteria.loadModel(Criteria.java:166)
        at ai.djl.repository.zoo.ModelZoo.loadModel(ModelZoo.java:132)
        at com.czworks.dji.Test10.main(Test10.java:58)


Solution 1:[1]

DJL uses PyTorch C++ API, it only support TorchScript model. You need trace your model.

See the following document: How to convert PyTorch model to TorchScript

Lading a TorchScript model in C++

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank Liu