Search in sources :

Example 1 with SavedModelBundle

use of org.tensorflow.SavedModelBundle in project sponge by softelnet.

the class TensorflowTest method testLoadModel.

// TODO @Test
public void testLoadModel() throws Exception {
    String modelDir = "examples/tensorflow/estimator/model";
    SavedModelBundle bundle = SavedModelBundle.load(modelDir + "/" + SpongeUtils.getLastSubdirectory(modelDir), "serve");
    try (Session s = bundle.session()) /* ; Tensor output = s.runner().fetch("MyConst").run().get(0) */
    {
        Tensor x = Tensor.create(new float[] { 2, 5, 8, 1 });
        Tensor y = s.runner().feed("x", x).fetch("y").run().get(0);
        logger.info("y = {}", y.floatValue());
    }
}
Also used : Tensor(org.tensorflow.Tensor) SavedModelBundle(org.tensorflow.SavedModelBundle) Session(org.tensorflow.Session)

Example 2 with SavedModelBundle

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

the class TensorFlowModel method create.

/**
 * Note: Please use Models from zoltar-models module.
 *
 * <p>Returns a TensorFlow model given {@link SavedModelBundle} export directory URI and
 * {@link Options}.</p>
 */
public static TensorFlowModel create(final URI modelResource, final Options options) throws IOException {
    final URI localDir = FileSystemExtras.downloadIfNonLocal(modelResource);
    final SavedModelBundle model = SavedModelBundle.load(localDir.toString(), options.tags().toArray(new String[0]));
    return new AutoValue_TensorFlowModel(model, options);
}
Also used : SavedModelBundle(org.tensorflow.SavedModelBundle) URI(java.net.URI)

Aggregations

SavedModelBundle (org.tensorflow.SavedModelBundle)2 URI (java.net.URI)1 Session (org.tensorflow.Session)1 Tensor (org.tensorflow.Tensor)1