use of org.tensorflow.lite.Interpreter in project MasterProject by Alexsogge.
the class HandWashDetection method loadTFModel.
private void loadTFModel() throws IOException {
Log.d("pred", "Load TF model");
tfliteModel = loadTFModelFile(context);
if (tfliteModel == null) {
initModelFallback();
}
try {
tfInterpreter = new Interpreter(tfliteModel, tfliteOptions);
} catch (IllegalArgumentException | NullPointerException e) {
Log.e("Tensorflow", "Error during load tf model. Use fallback...");
e.printStackTrace();
initModelFallback();
tfInterpreter = new Interpreter(tfliteModel, tfliteOptions);
}
}
use of org.tensorflow.lite.Interpreter in project djl by deepjavalibrary.
the class TfLiteModel method load.
/**
* {@inheritDoc}
*/
@Override
public void load(Path modelPath, String prefix, Map<String, ?> options) throws IOException {
setModelDir(modelPath);
if (block != null) {
throw new UnsupportedOperationException("TFLite does not support dynamic blocks");
}
Path modelFile = findModelFile(prefix);
if (modelFile == null) {
modelFile = findModelFile(modelDir.toFile().getName());
if (modelFile == null) {
throw new FileNotFoundException("TFLite model file not found in: " + modelPath);
}
}
Interpreter interpreter = new Interpreter(modelFile.toFile());
setBlock(new TfLiteSymbolBlock(interpreter, getNDManager()));
}
use of org.tensorflow.lite.Interpreter in project djl by deepjavalibrary.
the class TfLiteModel method load.
/**
* {@inheritDoc}
*/
@Override
public void load(InputStream is, Map<String, ?> options) throws IOException {
if (block != null) {
throw new UnsupportedOperationException("TFLite does not support dynamic blocks");
}
modelDir = Files.createTempDirectory("tflite-model");
modelDir.toFile().deleteOnExit();
byte[] buf = Utils.toByteArray(is);
Engine engine = Engine.getEngine(TfLiteEngine.ENGINE_NAME);
ByteBuffer bb = engine.newBaseManager().allocateDirect(buf.length);
bb.put(buf);
Interpreter interpreter = new Interpreter(bb);
setBlock(new TfLiteSymbolBlock(interpreter, getNDManager()));
}
use of org.tensorflow.lite.Interpreter in project amplify-android by aws-amplify.
the class TextClassificationModel method load.
/**
* Loads the pre-trained text classification model into
* TensorFlow Lite interpreter.
*/
@WorkerThread
@Override
public synchronized void load() {
// No-op if loaded already
if (loaded) {
return;
}
try {
ByteBuffer buffer = loadModelFile();
interpreter = new Interpreter(buffer);
if (onLoaded != null) {
onLoaded.accept(interpreter);
}
loaded = true;
} catch (PredictionsException exception) {
if (onLoadError != null) {
onLoadError.accept(exception);
}
}
}
Aggregations