@Name(value="tflite::impl::FlatBufferModelBase<tflite::impl::FlatBufferModel>") @NoOffset @Properties(inherit=tensorflowlite.class) public class FlatBufferModelBase extends Pointer
using namespace tflite;
StderrReporter error_reporter;
auto model = FlatBufferModelBase::BuildFromFile("interesting_model.tflite",
&error_reporter);
MyOpResolver resolver; // You need to subclass OpResolver to provide
// implementations.
InterpreterBuilder builder(*model, resolver);
std::unique_ptr interpreter;
if(builder(&interpreter) == kTfLiteOk) {
.. run model inference with interpreter
}
OpResolver must be defined to provide your kernel implementations to the
interpreter. This is environment specific and may consist of just the
builtin ops, or some custom operators you defined to extend tflite.Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
FlatBufferModelBase(Pointer p)
Pointer cast constructor.
|
Modifier and Type | Method and Description |
---|---|
Pointer |
access() |
Allocation |
allocation() |
static FlatBufferModel |
BuildFromAllocation(Allocation allocation) |
static FlatBufferModel |
BuildFromAllocation(Allocation allocation,
ErrorReporter error_reporter)
Builds a model directly from an allocation.
|
static FlatBufferModel |
BuildFromBuffer(BytePointer caller_owned_buffer,
long buffer_size) |
static FlatBufferModel |
BuildFromBuffer(BytePointer caller_owned_buffer,
long buffer_size,
ErrorReporter error_reporter)
Builds a model based on a pre-loaded flatbuffer.
|
static FlatBufferModel |
BuildFromBuffer(String caller_owned_buffer,
long buffer_size) |
static FlatBufferModel |
BuildFromBuffer(String caller_owned_buffer,
long buffer_size,
ErrorReporter error_reporter) |
static FlatBufferModel |
BuildFromFile(BytePointer filename) |
static FlatBufferModel |
BuildFromFile(BytePointer filename,
ErrorReporter error_reporter)
Builds a model based on a file.
|
static FlatBufferModel |
BuildFromFile(String filename) |
static FlatBufferModel |
BuildFromFile(String filename,
ErrorReporter error_reporter) |
static FlatBufferModel |
BuildFromFileDescriptor(int fd) |
static FlatBufferModel |
BuildFromFileDescriptor(int fd,
ErrorReporter error_reporter)
Builds a model based on a file descriptor.
|
static FlatBufferModel |
BuildFromModel(Pointer caller_owned_model_spec) |
static FlatBufferModel |
BuildFromModel(Pointer caller_owned_model_spec,
ErrorReporter error_reporter)
Builds a model directly from a flatbuffer pointer
Caller retains ownership of the buffer and should keep it alive until the
returned object is destroyed.
|
static boolean |
CheckBufferOutsideModel(Pointer model)
Check If the buffer is stored as part of the Flatbuffer or outside
Return false if the buffers are part of the Flatbuffer
|
boolean |
CheckModelIdentifier()
Returns true if the model identifier is correct (otherwise false and
reports an error).
|
ErrorReporter |
error_reporter() |
String |
GetMinimumRuntime() |
Pointer |
GetModel() |
boolean |
initialized() |
StringStringMap |
ReadAllMetadata() |
static StringStringMap |
ReadAllMetadata(Pointer model) |
void |
ValidateModelBuffers(ErrorReporter error_reporter) |
static FlatBufferModel |
VerifyAndBuildFromAllocation(Allocation allocation) |
static FlatBufferModel |
VerifyAndBuildFromAllocation(Allocation allocation,
TfLiteVerifier extra_verifier,
ErrorReporter error_reporter)
Verifies whether the content of the allocation is legit, then builds a
model based on the provided allocation.
|
static FlatBufferModel |
VerifyAndBuildFromBuffer(BytePointer caller_owned_buffer,
long buffer_size) |
static FlatBufferModel |
VerifyAndBuildFromBuffer(BytePointer caller_owned_buffer,
long buffer_size,
TfLiteVerifier extra_verifier,
ErrorReporter error_reporter)
Verifies whether the content of the buffer is legit, then builds a model
based on the pre-loaded flatbuffer.
|
static FlatBufferModel |
VerifyAndBuildFromBuffer(String caller_owned_buffer,
long buffer_size) |
static FlatBufferModel |
VerifyAndBuildFromBuffer(String caller_owned_buffer,
long buffer_size,
TfLiteVerifier extra_verifier,
ErrorReporter error_reporter) |
static FlatBufferModel |
VerifyAndBuildFromFile(BytePointer filename) |
static FlatBufferModel |
VerifyAndBuildFromFile(BytePointer filename,
TfLiteVerifier extra_verifier,
ErrorReporter error_reporter)
Verifies whether the content of the file is legit, then builds a model
based on the file.
|
static FlatBufferModel |
VerifyAndBuildFromFile(String filename) |
static FlatBufferModel |
VerifyAndBuildFromFile(String filename,
TfLiteVerifier extra_verifier,
ErrorReporter error_reporter) |
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, getPointer, hashCode, interruptDeallocatorThread, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zero
public FlatBufferModelBase(Pointer p)
Pointer(Pointer)
.@UniquePtr public static FlatBufferModel BuildFromFile(@Cast(value="const char*") BytePointer filename, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime
is longer than the FlatBufferModelBase instance.
Returns a nullptr in case of failure.@UniquePtr public static FlatBufferModel BuildFromFile(@Cast(value="const char*") BytePointer filename)
@UniquePtr public static FlatBufferModel BuildFromFile(String filename, ErrorReporter error_reporter)
@UniquePtr public static FlatBufferModel BuildFromFile(String filename)
@UniquePtr public static FlatBufferModel VerifyAndBuildFromFile(@Cast(value="const char*") BytePointer filename, TfLiteVerifier extra_verifier, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime
is longer than the FlatBufferModelBase instance.
Returns a nullptr in case of failure.@UniquePtr public static FlatBufferModel VerifyAndBuildFromFile(@Cast(value="const char*") BytePointer filename)
@UniquePtr public static FlatBufferModel VerifyAndBuildFromFile(String filename, TfLiteVerifier extra_verifier, ErrorReporter error_reporter)
@UniquePtr public static FlatBufferModel VerifyAndBuildFromFile(String filename)
@UniquePtr public static FlatBufferModel BuildFromFileDescriptor(int fd, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime
is longer than the FlatBufferModelBase instance. Caller retains ownership
of fd
and must ensure it is closed after BuildFromFile returns. Returns
a nullptr in case of failure.@UniquePtr public static FlatBufferModel BuildFromFileDescriptor(int fd)
@UniquePtr public static FlatBufferModel BuildFromBuffer(@Cast(value="const char*") BytePointer caller_owned_buffer, @Cast(value="size_t") long buffer_size, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime is longer than the
FlatBufferModelBase instance.
Returns a nullptr in case of failure.
NOTE: this does NOT validate the buffer so it should NOT be called on
invalid/untrusted input. Use VerifyAndBuildFromBuffer in that case@UniquePtr public static FlatBufferModel BuildFromBuffer(@Cast(value="const char*") BytePointer caller_owned_buffer, @Cast(value="size_t") long buffer_size)
@UniquePtr public static FlatBufferModel BuildFromBuffer(String caller_owned_buffer, @Cast(value="size_t") long buffer_size, ErrorReporter error_reporter)
@UniquePtr public static FlatBufferModel BuildFromBuffer(String caller_owned_buffer, @Cast(value="size_t") long buffer_size)
@UniquePtr public static FlatBufferModel VerifyAndBuildFromBuffer(@Cast(value="const char*") BytePointer caller_owned_buffer, @Cast(value="size_t") long buffer_size, TfLiteVerifier extra_verifier, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime is longer than the FlatBufferModelBase
instance. Returns a nullptr in case of failure.@UniquePtr public static FlatBufferModel VerifyAndBuildFromBuffer(@Cast(value="const char*") BytePointer caller_owned_buffer, @Cast(value="size_t") long buffer_size)
@UniquePtr public static FlatBufferModel VerifyAndBuildFromBuffer(String caller_owned_buffer, @Cast(value="size_t") long buffer_size, TfLiteVerifier extra_verifier, ErrorReporter error_reporter)
@UniquePtr public static FlatBufferModel VerifyAndBuildFromBuffer(String caller_owned_buffer, @Cast(value="size_t") long buffer_size)
@UniquePtr public static FlatBufferModel BuildFromAllocation(@UniquePtr Allocation allocation, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime is
longer than the FlatBufferModelBase instance.
Returns a nullptr in case of failure (e.g., the allocation is invalid).@UniquePtr public static FlatBufferModel BuildFromAllocation(@UniquePtr Allocation allocation)
@UniquePtr public static FlatBufferModel VerifyAndBuildFromAllocation(@UniquePtr Allocation allocation, TfLiteVerifier extra_verifier, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime is
longer than the FlatBufferModelBase instance.
Returns a nullptr in case of failure.@UniquePtr public static FlatBufferModel VerifyAndBuildFromAllocation(@UniquePtr Allocation allocation)
@UniquePtr public static FlatBufferModel BuildFromModel(@Cast(value="const tflite::Model*") Pointer caller_owned_model_spec, ErrorReporter error_reporter)
error_reporter
and must ensure its lifetime is longer than the FlatBufferModelBase
instance. Returns a nullptr in case of failure.@UniquePtr public static FlatBufferModel BuildFromModel(@Cast(value="const tflite::Model*") Pointer caller_owned_model_spec)
public ErrorReporter error_reporter()
@Const public Allocation allocation()
@StdString public String GetMinimumRuntime()
@ByVal public StringStringMap ReadAllMetadata()
@ByVal public static StringStringMap ReadAllMetadata(@Cast(value="const tflite::Model*") Pointer model)
public void ValidateModelBuffers(ErrorReporter error_reporter)
@Cast(value="bool") public boolean CheckModelIdentifier()
Copyright © 2025. All rights reserved.