@Test public void testCreate() throws IOException { EvaluatorUtil evaluatorUtil = new EvaluatorUtil(ConfigFactory.load()); TorchScriptEvaluatorManifest torchScriptEvaluatorManifest = (TorchScriptEvaluatorManifest) evaluatorUtil .getObjectMapper() .readValue( getClass().getResourceAsStream("/manifest.json"), EvaluatorManifest.class ); TorchScriptEvaluator evaluator = torchScriptEvaluatorManifest.create("src/test/resources"); TensorIO input = new TensorIO(Map.of( "input_0", new Tensor(DataType.FLOAT, new int[]{2}, new float[]{0.5f, 0.2f}) )); TensorIO output = evaluator.evaluateTensor(input); float[] output0 = (float[]) output.getTensors().get("output_0").getData(); Assertions.assertEquals(output0[0], 0.120716706f, 1e-6); Assertions.assertEquals(output0[1], 0.054772355f, 1e-6); }
@Override public TorchScriptEvaluator create(String path) throws EvaluatorException { Module module; try { module = Module.load(savedModelUri); } catch (CppException e1) { String localSavedModelUri = Paths.get(path, savedModelUri).toString(); try { module = Module.load(localSavedModelUri); } catch (CppException e2) { LOGGER.error("Cannot load TorchScript {}", savedModelUri, e1); LOGGER.error("Cannot load TorchScript {}", localSavedModelUri, e2); throw new EvaluatorException( String.format("Cannot load TorchScript %s or %s", savedModelUri, localSavedModelUri) ); } } return new TorchScriptEvaluator(module, inputs, outputs); }
TorchScriptEvaluatorManifest implements EvaluatorManifest { @Override public TorchScriptEvaluator create(String path) throws EvaluatorException { Module module; try { module = Module.load(savedModelUri); } catch (CppException e1) { String localSavedModelUri = Paths.get(path, savedModelUri).toString(); try { module = Module.load(localSavedModelUri); } catch (CppException e2) { LOGGER.error("Cannot load TorchScript {}", savedModelUri, e1); LOGGER.error("Cannot load TorchScript {}", localSavedModelUri, e2); throw new EvaluatorException( String.format("Cannot load TorchScript %s or %s", savedModelUri, localSavedModelUri) ); } } return new TorchScriptEvaluator(module, inputs, outputs); } }
TorchScriptEvaluatorManifest implements EvaluatorManifest { @Override public TorchScriptEvaluator create(String path) throws EvaluatorException { Module module; try { module = Module.load(savedModelUri); } catch (CppException e1) { String localSavedModelUri = Paths.get(path, savedModelUri).toString(); try { module = Module.load(localSavedModelUri); } catch (CppException e2) { LOGGER.error("Cannot load TorchScript {}", savedModelUri, e1); LOGGER.error("Cannot load TorchScript {}", localSavedModelUri, e2); throw new EvaluatorException( String.format("Cannot load TorchScript %s or %s", savedModelUri, localSavedModelUri) ); } } return new TorchScriptEvaluator(module, inputs, outputs); }  }
TorchScriptEvaluatorManifest implements EvaluatorManifest { @Override public TorchScriptEvaluator create(String path) throws EvaluatorException { Module module; try { module = Module.load(savedModelUri); } catch (CppException e1) { String localSavedModelUri = Paths.get(path, savedModelUri).toString(); try { module = Module.load(localSavedModelUri); } catch (CppException e2) { LOGGER.error("Cannot load TorchScript {}", savedModelUri, e1); LOGGER.error("Cannot load TorchScript {}", localSavedModelUri, e2); throw new EvaluatorException( String.format("Cannot load TorchScript %s or %s", savedModelUri, localSavedModelUri) ); } } return new TorchScriptEvaluator(module, inputs, outputs); }  @Override TorchScriptEvaluator create(String path); @Override String getType(); }
TorchScriptEvaluatorManifest implements EvaluatorManifest { @Override public TorchScriptEvaluator create(String path) throws EvaluatorException { Module module; try { module = Module.load(savedModelUri); } catch (CppException e1) { String localSavedModelUri = Paths.get(path, savedModelUri).toString(); try { module = Module.load(localSavedModelUri); } catch (CppException e2) { LOGGER.error("Cannot load TorchScript {}", savedModelUri, e1); LOGGER.error("Cannot load TorchScript {}", localSavedModelUri, e2); throw new EvaluatorException( String.format("Cannot load TorchScript %s or %s", savedModelUri, localSavedModelUri) ); } } return new TorchScriptEvaluator(module, inputs, outputs); }  @Override TorchScriptEvaluator create(String path); @Override String getType(); static final String TYPE; }