Skip to content

Commit 574119e

Browse files
committed
version for debugging
1 parent 8b79eec commit 574119e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.scijava</groupId>
77
<artifactId>pom-scijava</artifactId>
8-
<version>37.0.0</version>
8+
<version>39.0.0</version>
99
<relativePath />
1010
</parent>
1111

src/main/java/io/bioimage/modelrunner/pytorch/PytorchInterface.java

+29
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.bioimage.modelrunner.engine.DeepLearningEngineInterface;
2828
import io.bioimage.modelrunner.exceptions.LoadModelException;
2929
import io.bioimage.modelrunner.exceptions.RunModelException;
30+
import io.bioimage.modelrunner.numpy.DecodeNumpy;
3031
import io.bioimage.modelrunner.pytorch.shm.ShmBuilder;
3132
import io.bioimage.modelrunner.pytorch.shm.TensorBuilder;
3233
import io.bioimage.modelrunner.pytorch.tensor.ImgLib2Builder;
@@ -36,6 +37,7 @@
3637
import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray;
3738
import io.bioimage.modelrunner.utils.CommonUtils;
3839
import net.imglib2.RandomAccessibleInterval;
40+
import net.imglib2.img.array.ArrayImgs;
3941
import net.imglib2.type.NativeType;
4042
import net.imglib2.type.numeric.RealType;
4143
import net.imglib2.util.Cast;
@@ -71,6 +73,7 @@
7173
import ai.djl.repository.zoo.ZooModel;
7274
import ai.djl.training.util.ProgressBar;
7375
import ai.djl.translate.TranslateException;
76+
import ai.djl.util.Platform;
7477

7578
/**
7679
* This class implements an interface that allows the main plugin to interact in
@@ -163,6 +166,8 @@ private Service getRunner() throws IOException, URISyntaxException {
163166
public void loadModel(String modelFolder, String modelSource)
164167
throws LoadModelException
165168
{
169+
System.out.println("[DEBUG 1]: " + ai.djl.util.Utils.getenv("PATH"));
170+
System.out.println("[DEBUG 2]: " + Platform.fromSystem("pytorch"));
166171
this.modelFolder = modelFolder;
167172
this.modelSource = modelSource;
168173
if (interprocessing) {
@@ -566,4 +571,28 @@ private static String padSpecialJavaBin(String javaBin) {
566571
}
567572
return javaBin;
568573
}
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+
}
569598
}

0 commit comments

Comments
 (0)