Path for loading PyTorch model in Java with DJL

1k Views Asked by At

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!

2

There are 2 best solutions below

0
King Lan On

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

0
Frank Liu On

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.