|
27 | 27 | import io.bioimage.modelrunner.engine.DeepLearningEngineInterface; |
28 | 28 | import io.bioimage.modelrunner.exceptions.LoadModelException; |
29 | 29 | import io.bioimage.modelrunner.exceptions.RunModelException; |
| 30 | +import io.bioimage.modelrunner.numpy.DecodeNumpy; |
30 | 31 | import io.bioimage.modelrunner.pytorch.shm.ShmBuilder; |
31 | 32 | import io.bioimage.modelrunner.pytorch.shm.TensorBuilder; |
32 | 33 | import io.bioimage.modelrunner.pytorch.tensor.ImgLib2Builder; |
|
36 | 37 | import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray; |
37 | 38 | import io.bioimage.modelrunner.utils.CommonUtils; |
38 | 39 | import net.imglib2.RandomAccessibleInterval; |
| 40 | +import net.imglib2.img.array.ArrayImgs; |
39 | 41 | import net.imglib2.type.NativeType; |
40 | 42 | import net.imglib2.type.numeric.RealType; |
41 | 43 | import net.imglib2.util.Cast; |
|
71 | 73 | import ai.djl.repository.zoo.ZooModel; |
72 | 74 | import ai.djl.training.util.ProgressBar; |
73 | 75 | import ai.djl.translate.TranslateException; |
| 76 | +import ai.djl.util.Platform; |
74 | 77 |
|
75 | 78 | /** |
76 | 79 | * This class implements an interface that allows the main plugin to interact in |
@@ -163,6 +166,8 @@ private Service getRunner() throws IOException, URISyntaxException { |
163 | 166 | public void loadModel(String modelFolder, String modelSource) |
164 | 167 | throws LoadModelException |
165 | 168 | { |
| 169 | + System.out.println("[DEBUG 1]: " + ai.djl.util.Utils.getenv("PATH")); |
| 170 | + System.out.println("[DEBUG 2]: " + Platform.fromSystem("pytorch")); |
166 | 171 | this.modelFolder = modelFolder; |
167 | 172 | this.modelSource = modelSource; |
168 | 173 | if (interprocessing) { |
@@ -566,4 +571,28 @@ private static String padSpecialJavaBin(String javaBin) { |
566 | 571 | } |
567 | 572 | return javaBin; |
568 | 573 | } |
| 574 | + |
| 575 | + public static <T extends RealType<T> & NativeType<T>, R extends RealType<R> & NativeType<R>> void |
| 576 | + main(String[] args) throws IOException, URISyntaxException, LoadModelException, RunModelException { |
| 577 | + PytorchInterface pi = new PytorchInterface(false); |
| 578 | + String folder = "/home/carlos/git/deepimagej-plugin/models/DeepBacs Segmentation Boundary Model_29012025_162730"; |
| 579 | + String wt = folder + "/44a0b00b-f171-4fa2-9c39-160e610e9496.pt"; |
| 580 | + String npy = folder + "/cfdcff5e-c4e4-4baf-826f-b453751a139d_raw_test_tensor_.npy"; |
| 581 | + pi.loadModel(folder, wt); |
| 582 | + |
| 583 | + RandomAccessibleInterval<T> in = DecodeNumpy.loadNpy(npy); |
| 584 | + |
| 585 | + ArrayList<Tensor<T>> ins = new ArrayList<Tensor<T>>(); |
| 586 | + ArrayList<Tensor<R>> ous = new ArrayList<Tensor<R>>(); |
| 587 | + Tensor<T> inT = Tensor.build("ff", "bcyx", (RandomAccessibleInterval<T>) in); |
| 588 | + Tensor<R> ouT = (Tensor<R>) Tensor.build("gg", "bcyx", ArrayImgs.floats(new long[] {1, 2, 256, 256})); |
| 589 | + |
| 590 | + ins.add(inT); |
| 591 | + ous.add(ouT); |
| 592 | + |
| 593 | + pi.run(Cast.unchecked(ins), Cast.unchecked(ous)); |
| 594 | + |
| 595 | + DecodeNumpy.saveNpy(folder + "/out_yes_pre.npy", ous.get(0).getData()); |
| 596 | + |
| 597 | + } |
569 | 598 | } |
0 commit comments