public final class ModelSource

  1. Object
  2. 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 = 1

FILE

public static final int FILE = 2

RESOURCE

public static final int RESOURCE = 3

Method details

bytes

public static ModelSource bytes(byte[] value)
Creates an in-memory model source.

Parameters

value byte[]
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

path String
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

path String
absolute classpath-style resource path

Returns

a resource-backed source

getKind

public int getKind()

Returns

getBytes

public byte[] getBytes()

Returns

a defensive copy of model bytes, or null for 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 null for non-byte sources

getPath

public String getPath()

Returns

the file/resource path, or null for a byte source