Last active
October 24, 2022 14:24
-
-
Save fancyerii/c1096f9f8c9bd9705da1b1c7d6ca2138 to your computer and use it in GitHub Desktop.
Load Tensorflow Model in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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