TfliteModel

TFLite model handle for scripts. The model type must be selected in Template Manager metadata. Supported outputs are YOLOv8/YOLO11 object detection [1,N,4+C]/[1,4+C,N], YOLO26 end-to-end detection [1,N,6]/[N,6], YOLO11/YOLO26 image classification [1,C], and MobileNetV3 image classification [1,C]. Runtime detects FLOAT32, INT8, or UINT8 tensor precision from the model and dequantizes quantized detection and classification outputs before applying thresholds. Classification matches return class confidence and metadata without point or bounds. Inference methods require a local model file; when local file is missing and runtime download fails, script raises a runtime error.

Syntax

TfliteModel(model)

Constructor parameters

NameDescription
modelString
Model reference to use for inference (prefer template model name).
Required · Positional or named
No default

Returns

Example

# Check model availability before running detection
if TfliteModel.exists("enemy_model"):
    detector = TfliteModel("enemy_model")
    hits = detector.inference()
    if len(hits) > 0:
        click(hits[0])

Fields

NameDescription
modelString
Model reference in current macro (prefer template model name; legacy model id still accepted).
resize_modeString
Resolved preprocessing resize mode: LETTERBOX, STRETCH, or CROP_CENTER.
Default: LETTERBOX
color_modeString
Resolved preprocessing color mode: RGB, BGR, or GRAYSCALE.
Default: RGB
norm_modeString
Resolved preprocessing normalization: ZERO_ONE, MINUS_ONE_ONE, IMAGENET, or CUSTOM.
Default: ZERO_ONE
padding_colorInt
Padding fill value (0 -> 255) used by LETTERBOX resize mode.
Default: 114
Constructor example
# Import a supported TFLite model and choose its output type in Template Manager.
# Create a model handle bound to one TFLite model name in Template Manager.
model = TfliteModel("enemy_model")

Methods

4 methods

TfliteModel.exists

Check whether a local TFLite model file (resolved by model name or legacy id) is currently available in this macro.

Syntax

TfliteModel.exists(model)

Parameters

NameDescription
modelString
Model reference to check.
Required · Positional or named
No default

Returns

Boolean — true if local model file is ready to use.

Example

# Check a model imported in Template Manager
if TfliteModel.exists("enemy_detector"):
    print("Model available")

TfliteModel.list

Return local model references currently available for the macro (prefer display names).

Syntax

TfliteModel.list()

Returns

list[String] — Model reference list.

Example

# List models available to this macro
print(TfliteModel.list())

TfliteModel.exists

Check whether this detector's local model file is available.

Syntax

model.exists()

Returns

Boolean — true if the local model file can be used immediately.

Example

# Create only after confirming the imported model exists
if TfliteModel.exists("enemy_detector"):
    model = TfliteModel("enemy_detector")
    print(model.exists())

TfliteModel.inference

Run the selected TFLite model without class filtering and return all matches. When region is supplied, its screen image is cropped before preprocessing and inference; this can reduce model accuracy if the model was not trained on similarly cropped images. Classification matches have no point or bounds.

Syntax

model.inference(threshold=0.5, region=None, max_results=8, debug=False)

Parameters

NameDescription
thresholdNumber
Confidence threshold in 0 -> 1.
Optional · Positional or named
Default: 0.5
regionRegion?
Optional screen region. Its image is cropped before preprocessing and inference, which can reduce accuracy if the model was not trained on similarly cropped images.
Optional · Positional or named
Default: None
max_resultsInt
Maximum number of detections returned.
Optional · Positional or named
Default: 8
debugBoolean
In Edit mode, true saves a preprocess preview and opens the runtime debug dialog. Run-only mode ignores the debug output and performs normal inference without a dialog. Detailed model-result rows and preprocess config stay in the dialog; returned Match objects do not include debug_result. Detection previews draw bbox/class labels; classification previews show the preprocessed input plus class scores.
Optional · Positional or named
Default: False

Returns

MatchList — Inference matches list across all classes.

Example

# Run raw model inference and inspect preprocess debug output
detector = TfliteModel("enemy_model")
search = Region(100, 200, 300, 400)
hits = detector.inference(threshold=0.55, region=search, max_results=12, debug=True)
text(str(len(hits)))