diff --git a/src/main/java/org/bioimageanalysis/icy/deeplearning/tensorflow/v1/Tensorflow1Interface.java b/src/main/java/org/bioimageanalysis/icy/deeplearning/tensorflow/v1/Tensorflow1Interface.java index a8caccca751f9f2e2e04f599622216f93ac40b6e..bc3a5cdb7fbebfb9f7f3cf2c2ed3b37bd90e8231 100644 --- a/src/main/java/org/bioimageanalysis/icy/deeplearning/tensorflow/v1/Tensorflow1Interface.java +++ b/src/main/java/org/bioimageanalysis/icy/deeplearning/tensorflow/v1/Tensorflow1Interface.java @@ -103,7 +103,7 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface private static SavedModelBundle model; private static SignatureDef sig; - private boolean interprocessing = true; + private boolean interprocessing = false; private String tmpDir; @@ -111,8 +111,6 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface public Tensorflow1Interface() throws IOException { - // TODO remove tmpDIr - tmpDir = getTemporaryDir(); boolean isMac = PlatformDetection.isMacOS(); boolean isIntel = new PlatformDetection().getArch().equals(PlatformDetection.ARCH_X86_64); if (isMac && isIntel) { @@ -124,8 +122,6 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface public Tensorflow1Interface(boolean doInterprocessing) throws IOException { - // TODO remove tmpDIr - tmpDir = getTemporaryDir(); if (!doInterprocessing) { interprocessing = false; } else { @@ -202,6 +198,7 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface try { sig = MetaGraphDef.parseFrom(byteGraph).getSignatureDefOrThrow("serving_default"); } catch (InvalidProtocolBufferException e) { + closeModel(); throw new LoadModelException(); } } @@ -246,22 +243,20 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface args.add(this.tmpDir); for (Tensor tensor : inputTensors) {args.add(tensor.getName() + INPUT_FILE_TERMINATION);} for (Tensor tensor : outputTensors) {args.add(tensor.getName() + OUTPUT_FILE_TERMINATION);} + /* try { main(new String[] {args.get(4), args.get(5), args.get(6), args.get(7)}); } catch (LoadModelException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } catch (RunModelException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } retrieveInterprocessingTensors(outputTensors); if (true) return; - + */ ProcessBuilder builder = new ProcessBuilder(args); Process process; try { @@ -270,8 +265,10 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface throw new RunModelException("Error executing the Tensorflow 1 model in" + " a separate process. The process was not terminated correctly."); } catch (RunModelException e) { + closeModel(); throw e; } catch (Exception e) { + closeModel(); throw new RunModelException(e.getCause().toString()); } @@ -319,6 +316,7 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface byteBuffer.put(MappedFileBuilder.createFileHeader(tensor)); MappedFileBuilder.build(tensor, byteBuffer); } catch (IOException e) { + closeModel(); throw new RunModelException(e.getCause().toString()); } } @@ -333,6 +331,7 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface ByteBuffer byteBuffer = mem.duplicate(); tensor.setData(MappedBufferToImgLib2.build(byteBuffer)); } catch (IOException e) { + closeModel(); throw new RunModelException(e.getCause().toString()); } } @@ -347,6 +346,7 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface ByteBuffer byteBuffer = mem.duplicate(); return MappedBufferToImgLib2.buildTensor(byteBuffer); } catch (IOException e) { + closeModel(); throw new RunModelException(e.getCause().toString()); } } @@ -356,7 +356,7 @@ public class Tensorflow1Interface implements DeepLearningEngineInterface * process with the corresponding tensors * @return */ - private List<String> getProcessCommandsWithoutArgs(){ + private List<String> getProcessCommandsWithoutArgs() { String javaHome = System.getProperty("java.home"); String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; String classpath = System.getProperty("java.class.path");