public final class ModelSource
- Object
- ModelSource
Describes where an
InferenceSession should obtain a .tflite
model. Byte sources are defensively copied. File sources are especially
useful with ModelCache because native ports can open the cached
path without loading the full model into the Java heap.Fields
public static final int BYTES = 1 | |
public static final int FILE = 2 | |
public static final int RESOURCE = 3 |
Methods
public static ModelSource bytes(byte[] value) | Creates an in-memory model source. |
public static ModelSource file(String path) | Creates a source for an existing private filesystem path. |
public static ModelSource resource(String path) | Creates a source for a model packaged in application resources. |
public int getKind() | |
public byte[] getBytes() | |
public byte[] getBytesUnsafe() | Returns the internal model byte array without copying it. |
public String getPath() |
Inherited methods
Field details
BYTES
public static final int BYTES = 1FILE
public static final int FILE = 2RESOURCE
public static final int RESOURCE = 3Method details
bytes
public static ModelSource bytes(byte[] value)Creates an in-memory model source.
Parameters
valuebyte[]- complete model bytes, copied by this method
Returns
a byte-backed source
file
public static ModelSource file(String path)Creates a source for an existing private filesystem path.
Parameters
pathString- path understood by
FileSystemStorage
Returns
a file-backed source; the session never owns or deletes the file
resource
public static ModelSource resource(String path)Creates a source for a model packaged in application resources.
Parameters
pathString- absolute classpath-style resource path
Returns
a resource-backed source
getKind
public int getKind()getBytes
public byte[] getBytes()Returns
a defensive copy of model bytes, or
null for non-byte sourcesgetBytesUnsafe
public byte[] getBytesUnsafe()Returns the internal model byte array without copying it.
This escape hatch is intended for native backend handoff and
memory-sensitive applications. The returned array must be treated as
read-only: modifying it changes the model source and violates this
class’s immutability contract. Prefer getBytes() unless the
additional full-model copy is known to be unacceptable.
Returns
internal model bytes, or
null for non-byte sourcesgetPath
public String getPath()Returns
the file/resource path, or
null for a byte source