Class TfModel
java.lang.Object
ai.beestream.jitnn.tf.TfModel
- All Implemented Interfaces:
AutoCloseable
A TensorFlow model on jitNN: a SavedModel directory (TensorFlow 2 / Keras
export, with
its variables checkpoint) or a frozen GraphDef file. The graph is flattened (function calls
inlined), its variables read from the checkpoint, and it is translated to the operators of
jitnn-onnx, which runs it.
TfModel model = TfModel.load(Path.of("my_saved_model"));
Map<String, Tensor> out = model.run(Map.of("keras_tensor", Tensor.of(x, 1, 4)));
Inputs and outputs carry the signature's names. Integer inputs (token ids) are INT32 tensors;
images stay NHWC, as TensorFlow takes them.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases the model's weights (seeOnnxSession.close()); the model cannot run afterwards.The model's input names, asruntakes them.static TfModelLoads a SavedModel directory'sserving_defaultsignature, or a frozen GraphDef file.static TfModelLoads signaturesignatureof a SavedModel (ignored for a frozen GraphDef, whose inputs are its placeholders and whose outputs are the nodes nothing consumes).The model's output names.Runs the model; outputs are lazy jitNN tensors, by signature output name.session()The jitnn-onnx session the model was translated to.
-
Method Details
-
load
Loads a SavedModel directory'sserving_defaultsignature, or a frozen GraphDef file.- Throws:
IOException
-
load
Loads signaturesignatureof a SavedModel (ignored for a frozen GraphDef, whose inputs are its placeholders and whose outputs are the nodes nothing consumes). WithhalfPrecision, matrix products run on FP16 operands, as in jitnn-onnx.- Throws:
IOException
-
inputNames
-
outputNames
-
session
The jitnn-onnx session the model was translated to. -
close
public void close()Releases the model's weights (seeOnnxSession.close()); the model cannot run afterwards.- Specified by:
closein interfaceAutoCloseable
-
run
-