Skip to content

Commit

Permalink
remove prints and correct small error
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Jan 16, 2025
1 parent 41fbece commit 0c5aeb1
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/main/java/io/bioimage/modelrunner/model/StardistAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ public abstract class StardistAbstract implements Closeable {

private static final String RUN_MODEL_CODE = ""
+ "output = model.predict_instances(im, return_predict=False)" + System.lineSeparator()
//+ "print(output)" + System.lineSeparator()
+ "print(type(output))" + System.lineSeparator()
+ "if type(output) == np.ndarray:" + System.lineSeparator()
+ " im[:] = output" + System.lineSeparator()
+ " im[:] = output" + System.lineSeparator()
Expand All @@ -127,26 +125,20 @@ public abstract class StardistAbstract implements Closeable {
+ "shm_list = []" + System.lineSeparator()
+ "np_list = []" + System.lineSeparator()
+ "for kk, vv in output[1].items():" + System.lineSeparator()
+ " print(kk)" + System.lineSeparator()
+ " if type(vv) != np.ndarray:" + System.lineSeparator()
+ " task.update('Output ' + kk + ' is not a np.ndarray. Only np.ndarrays supported.')" + System.lineSeparator()
+ " print(type(vv))" + System.lineSeparator()
+ " continue" + System.lineSeparator()
+ " if output[1][kk].nbytes == 0:" + System.lineSeparator()
+ " task.outputs[kk] = None" + System.lineSeparator()
+ " else:" + System.lineSeparator()
+ " task.outputs[kk + '" + SHAPE_KEY + "'] = output[1][kk].shape" + System.lineSeparator()
+ " print(type(output[1][kk].shape))" + System.lineSeparator()
+ " task.outputs[kk + '"+ DTYPE_KEY + "'] = str(output[1][kk].dtype)" + System.lineSeparator()
+ " print(type(output[1][kk].dtype))" + System.lineSeparator()
+ " shm = shared_memory.SharedMemory(create=True, size=output[1][kk].nbytes)" + System.lineSeparator()
+ " task.outputs[kk + '"+ SHM_NAME_KEY + "'] = shm.name" + System.lineSeparator()
+ " print(type(shm.name))" + System.lineSeparator()
+ " shm_list.append(shm)" + System.lineSeparator()
+ " aa = np.ndarray(output[1][kk].shape, dtype=output[1][kk].dtype, buffer=shm.buf)" + System.lineSeparator()
+ " aa[:] = output[1][kk]" + System.lineSeparator()
+ " np_list.append(aa)" + System.lineSeparator()
+ "print('dd')" + System.lineSeparator()
+ "globals()['shm_list'] = shm_list" + System.lineSeparator()
+ "globals()['np_list'] = np_list" + System.lineSeparator()

Expand Down Expand Up @@ -292,7 +284,7 @@ Map<String, RandomAccessibleInterval<T>> reconstructOutputs(Task task, String sh

if (task.outputs.get(KEYS_KEY) != null) {
for (String kk : (List<String>) task.outputs.get(KEYS_KEY)) {
outs.put("", reconstruct(task, kk));
outs.put(kk, reconstruct(task, kk));
}
}

Expand All @@ -318,12 +310,10 @@ RandomAccessibleInterval<T> reconstruct(Task task, String key) throws IOExceptio
SharedMemoryArray shmCoords = SharedMemoryArray.readOrCreate(shm_name, coordsSh,
Cast.unchecked(CommonUtils.getImgLib2DataType(coords_dtype)), false, false);

Map<String, RandomAccessibleInterval<T>> outs = new HashMap<String, RandomAccessibleInterval<T>>();
// TODO I do not understand why is complaining when the types align perfectly
RandomAccessibleInterval<T> coordsRAI = shmCoords.getSharedRAI();
RandomAccessibleInterval<T> coordsCopy = Tensor.createCopyOfRaiInWantedDataType(Cast.unchecked(coordsRAI),
Util.getTypeFromInterval(Cast.unchecked(shmCoords)));
outs.put("coords", coordsCopy);
Util.getTypeFromInterval(Cast.unchecked(coordsRAI)));

shmCoords.close();

Expand Down

0 comments on commit 0c5aeb1

Please sign in to comment.