Class ModelSource
java.lang.Object
com.codename1.ai.inference.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.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ModelSourcebytes(byte[] value) Creates an in-memory model source.static ModelSourceCreates a source for an existing private filesystem path.byte[]getBytes()byte[]Returns the internal model byte array without copying it.intgetKind()getPath()static ModelSourceCreates a source for a model packaged in application resources.
-
Field Details
-
BYTES
public static final int BYTES- See Also:
-
FILE
public static final int FILE- See Also:
-
RESOURCE
public static final int RESOURCE- See Also:
-
-
Method Details
-
bytes
Creates an in-memory model source.- Parameters:
value- complete model bytes, copied by this method- Returns:
- a byte-backed source
-
file
Creates a source for an existing private filesystem path.- Parameters:
path- path understood byFileSystemStorage- Returns:
- a file-backed source; the session never owns or deletes the file
-
resource
Creates a source for a model packaged in application resources.- Parameters:
path- absolute classpath-style resource path- Returns:
- a resource-backed source
-
getKind
-
getBytes
public byte[] getBytes()- Returns:
- a defensive copy of model bytes, or
nullfor non-byte sources
-
getBytesUnsafe
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
nullfor non-byte sources
-
getPath
- Returns:
- the file/resource path, or
nullfor a byte source
-