'Path for loading PyTorch model in Java with DJL

I trained a custom PyTorch model and saved it as a .pt file. I'm now trying to load this model in Java using DJL.

Path modelDir = Paths.get("/Users/myname/eclipse-workspace/myProject/src/ML/");
Model model = Model.newInstance("model.pt");
model.load(modelDir);

However, this gives the following exception:

ai.djl.engine.EngineException: No deep learning engine found. I found that even when I change the path to something totally invalid, I get the same error. So I think the issue is with the path or the model name. What am I doing wrong? I'm running the project via Maven in Eclipse by the way.

Thank you!



Solution 1:[1]

From the error message, looks like you haven't specify PyTorch Engine/Native dependencies in your projects. You need to supply that first. Then please follow the instruction here: https://docs.djl.ai/jupyter/load_pytorch_model.html to load your pytorch model

Solution 2:[2]

You need include pytorch engine package in your project:

<dependency>
    <groupId>ai.djl.pytorch</groupId>
    <artifactId>pytorch-engine</artifactId>
    <version>0.16.0</version>
    <scope>runtime</scope>
</dependency>

DJL support multiple engines (e.g. PyTorch, TensorFlow, Apache MXNet). These engine packages are shipped in separate maven packages. DJL will locate the engine in the class path at runtime.

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 King Lan
Solution 2 Frank Liu