I have traced a model in PyTorch and loaded it in successfully in DJL. Now I want to make sure pre/postprocessing works correctly in my JAVA server. I have written the result of the pre- and postprocessing into numpy files (.npy), e.g. with np.save('preprocessed.npy', some_tensor.detach().numpy())
How can I load the .npy file in JAVA/DJL into an NDArray to test the input/output of my traced model?
A solution using purely DJL would be preferred, but additional helper libraries are also a possibility.
Thanks to the great help in the DJL Slack I found the following solution:
As of now (v0.23.0) it is possible via a workaround:
The method
ai.djl.ndarray.NDSerializer.decodeNumpyprovides this functionality. As it is package private, you need to either call it via reflection or create a new class like this as a workaround:However, in the next release, DJL will officially support this via the
NDArray.decode,NDManager.decodeandNDList.decodemethods. These methods will autodetect the underlying format and allow for a variety of formats.