Class ModelSource

java.lang.Object
com.codename1.ai.inference.ModelSource

public final class ModelSource extends Object
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 Details

  • Method Details

    • bytes

      public static ModelSource bytes(byte[] value)
      Creates an in-memory model source.
      Parameters:
      value - 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 - 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 - absolute classpath-style resource path
      Returns:
      a resource-backed source
    • getKind

      public int getKind()
      Returns:
      BYTES, FILE, or RESOURCE
    • 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