TfliteModel

Use a TFLite model imported in Template Manager to recognize objects or classify an image. Select the correct model type there. Supported outputs: YOLOv8/YOLO11 detection [1,N,4+C]/[1,4+C,N]; YOLO26 detection [1,N,6]/[N,6]; YOLO11/YOLO26 and MobileNetV3 classification [1,C]. FLOAT32, INT8 and UINT8 are supported automatically. Classification returns class scores and metadata without screen points or bounds. Inference requires a local model file; failure to obtain it raises an 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
How the image is resized: LETTERBOX preserves its proportions and adds padding; STRETCH fills the input size; CROP_CENTER crops the center.
Default: LETTERBOX
color_modeString
Image color format used by the model: RGB, BGR or GRAYSCALE.
Default: RGB
norm_modeString
How pixel values are converted for the model: ZERO_ONE, MINUS_ONE_ONE, IMAGENET or CUSTOM.
Default: ZERO_ONE
padding_colorInt
Value from 0 to 255 used to fill the border added by LETTERBOX.
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 model on one current screen image or the supplied region and return a MatchList across all classes. An empty list means no matches or no screen frame available yet. Missing capture permission, model loading or execution failures raise errors. A region crops the image before model processing. Use images similar to the model’s training data; cropping can reduce accuracy. Classification results have no point or bounds. In Edit mode, the Recognition Debug Frame setting draws the scan region in red and detection boxes in green, including when debug=False. Classification only shows the scan region.

Syntax

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

Parameters

NameDescription
thresholdNumber
Minimum confidence from 0 to 1. The app uses at least 0.01 when running the model.
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 results to return. The fractional part is removed, then the value is limited to 1..64.
Optional · Positional or named
Default: 8
debugBoolean
True opens an image preview and model results in Edit mode. Detection previews show boxes and classes; classification previews show the input image and class scores. Run-only mode ignores this option. Returned Match values do not include debug_result.
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)))