Skip to content

Instantly share code, notes, and snippets.

@fancyerii
Last active October 24, 2022 14:24
Show Gist options
  • Save fancyerii/c1096f9f8c9bd9705da1b1c7d6ca2138 to your computer and use it in GitHub Desktop.
Save fancyerii/c1096f9f8c9bd9705da1b1c7d6ca2138 to your computer and use it in GitHub Desktop.
Load Tensorflow Model in Java
package com.easemob.ai.robotapi.test.tensorflow;
import org.tensorflow.SavedModelBundle;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
public class ImportModelTest {
public static void main(String[] args) {
try (SavedModelBundle b = SavedModelBundle.load("/home/mc/data/test-tensorflow/model", "serve")) {
Session s = b.session();
float[][] matrix=new float[1][1];
matrix[0]=new float[]{0.5f};
Tensor input = Tensor.create(matrix);
Tensor result = s.runner().feed("input", input).fetch("output").run().get(0);
float[][] res=new float[1][1];
res[0]=new float[1];
result.copyTo(res);
System.out.println("results: "+res[0][0]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment