I have been given a pytorch model file, and some object detection results. The object detection results give number to identify what kind of object it detected, but I want the names from the model file.
Some python code I found looks like this
model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
stride, names, pt = model.stride, model.names, model.pt
I am pretty sure I need to get the names array, but I'm working in java, not python. I looked into the ai.djl.pytorch.engine.PtModel, but could not spot anything that looks like a mapping from numbers to names.
It even looks like DeepJavaLibrary can't support loading a plain .pt file:
String fname = "/tmp/yolov5s.pt";
{
PtEngine engine = (PtEngine) Engine.getEngine("PyTorch");
Model model = engine.newModel("bacon", null);
model.load(new File(fname).toPath());
Block block = model.getBlock();
System.out.println(block);
}
Exception in thread "main" 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:1550)
at ai.djl.pytorch.engine.PtModel.load(PtModel.java:90)
at ai.djl.Model.load(Model.java:110)
at project.pictureServer.PyTorchFile.main(PyTorchFile.java:37)
What is the proper way to map from object/class numbers to names using Java and a PyTorch model file?