Search in sources :

Example 6 with Tensor

use of org.tensorflow.Tensor in project zoltar by spotify.

the class TensorFlowGraphModelTest method testDummyLoadOfTensorFlowGraphWithPrefix.

@Test
public void testDummyLoadOfTensorFlowGraphWithPrefix() throws Exception {
    final String prefix = "test";
    final Path graphFile = createADummyTFGraph();
    try (final TensorFlowGraphModel model = TensorFlowGraphModel.create(graphFile.toUri(), null, prefix);
        final Session session = model.instance();
        final Tensor<Double> double3 = Tensors.create(3.0D)) {
        List<Tensor<?>> result = null;
        try {
            result = session.runner().fetch(prefix + "/" + mulResult).feed(prefix + "/" + inputOpName, double3).run();
            assertEquals(result.get(0).doubleValue(), 6.0D, Double.MIN_VALUE);
        } finally {
            if (result != null) {
                result.forEach(Tensor::close);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Tensor(org.tensorflow.Tensor) Session(org.tensorflow.Session) PredictorsTest(com.spotify.zoltar.PredictorsTest) Test(org.junit.Test)

Aggregations

Session (org.tensorflow.Session)6 Tensor (org.tensorflow.Tensor)6 Test (org.junit.Test)4 PredictorsTest (com.spotify.zoltar.PredictorsTest)3 Path (java.nio.file.Path)3 Graph (org.tensorflow.Graph)2 JFeatureSpec (com.spotify.featran.java.JFeatureSpec)1 Identity (com.spotify.featran.transformers.Identity)1 ExtractFn (com.spotify.zoltar.FeatureExtractFns.ExtractFn)1 ModelLoader (com.spotify.zoltar.ModelLoader)1 PredictFn (com.spotify.zoltar.PredictFns.PredictFn)1 Prediction (com.spotify.zoltar.Prediction)1 FeatranExtractFns (com.spotify.zoltar.featran.FeatranExtractFns)1 IOException (java.io.IOException)1 URI (java.net.URI)1 LongBuffer (java.nio.LongBuffer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Arrays (java.util.Arrays)1