Skip to content

Commit

Permalink
remove prints
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 20, 2024
1 parent 71738d2 commit 704447f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.charset.StandardCharsets;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -58,13 +57,11 @@
import io.bioimage.modelrunner.tensor.Tensor;
import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray;
import io.bioimage.modelrunner.utils.CommonUtils;
import net.imglib2.Cursor;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Cast;
import net.imglib2.util.Util;
import net.imglib2.view.Views;

/**
* This class implements an interface that allows the main plugin to interact in
Expand Down Expand Up @@ -190,11 +187,11 @@ private void launchModelLoadOnProcess() throws IOException, InterruptedException
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED) {
this.runner.close();
runner = null;
throw new RuntimeException();
throw new RuntimeException(task.error);
}
}

Expand Down Expand Up @@ -245,7 +242,6 @@ protected void runFromShmas(List<String> inputs, List<String> outputs) throws IO
IValueVector inputsVector = new IValueVector();
for (String ee : inputs) {
Map<String, Object> decoded = Types.decode(ee);
System.out.println("MM: -> " + ee);
SharedMemoryArray shma = SharedMemoryArray.read((String) decoded.get(MEM_NAME_KEY));
org.bytedeco.pytorch.Tensor inT = TensorBuilder.build(shma);
inputsVector.put(new IValue(inT));
Expand Down Expand Up @@ -310,7 +306,7 @@ else if (task.status == TaskStatus.FAILED)
else if (task.status == TaskStatus.CRASHED) {
this.runner.close();
runner = null;
throw new RuntimeException();
throw new RuntimeException(task.error);
}
for (int i = 0; i < outputTensors.size(); i ++) {
String name = (String) Types.decode(encOuts.get(i)).get(MEM_NAME_KEY);
Expand All @@ -321,30 +317,7 @@ else if (task.status == TaskStatus.CRASHED) {
shmaOutputList.add(shm);
}
RandomAccessibleInterval<T> rai = shm.getSharedRAI();
System.out.println("Output size: " + Arrays.toString(rai.dimensionsAsLongArray()));
// TODO remove
double max0 = 0;
Cursor<T> iter0 = Views.iterable(rai).cursor();
while (iter0.hasNext()) {
iter0.next();
double doub = iter0.get().getRealDouble();
if (doub > max0)
max0 = doub;
}
System.out.println("Output SHM " + i + " max value: " + max0);
// TODO remove
outputTensors.get(i).setData(Tensor.createCopyOfRaiInWantedDataType(Cast.unchecked(rai), Util.getTypeFromInterval(Cast.unchecked(rai))));
// TODO remove
double max = 0;
Cursor<R> iter = Views.iterable(outputTensors.get(i).getData()).cursor();
while (iter.hasNext()) {
iter.next();
double doub = iter.get().getRealDouble();
if (doub > max)
max = doub;
}
System.out.println("Copied ouput " + i + " max value: " + max);
// TODO remove
}
} catch (Exception e) {
closeShmas();
Expand Down Expand Up @@ -385,11 +358,11 @@ public void closeModel() {
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED) {
this.runner.close();
runner = null;
throw new RuntimeException();
throw new RuntimeException(task.error);
}
this.runner.close();
this.runner = null;
Expand Down Expand Up @@ -432,16 +405,6 @@ private <T extends RealType<T> & NativeType<T>> List<String> encodeInputs(List<T
List<String> encodedInputTensors = new ArrayList<String>();
Gson gson = new Gson();
for (Tensor<T> tt : inputTensors) {
System.out.println("Input size: " + Arrays.toString(tt.getData().dimensionsAsLongArray()));
double max0 = 0;
Cursor<T> iter0 = Views.iterable(tt.getData()).cursor();
while (iter0.hasNext()) {
iter0.next();
double doub = iter0.get().getRealDouble();
if (doub > max0)
max0 = doub;
}
System.out.println("Input max: " + max0);
SharedMemoryArray shma = SharedMemoryArray.createSHMAFromRAI(tt.getData(), false, true);
shmaInputList.add(shma);
HashMap<String, Object> map = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ private static org.bytedeco.pytorch.Tensor buildFloat(SharedMemoryArray shmArray
float[] flat = new float[buff.capacity() / 4];
buff.asFloatBuffer().get(flat);
Tensor ndarray = Tensor.create(flat, ogShape);

// TODO remove
double max0 = 0;
for (float ff : flat) {
if (ff > max0)
max0 = ff;
}
System.out.println("Input max: " + max0);
// TODO remove
return ndarray;
}

Expand Down

0 comments on commit 704447f

Please sign in to comment.