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.

รูปแบบคำสั่ง

TfliteModel(model)

พารามิเตอร์สำหรับสร้างออบเจ็กต์

ชื่อคำอธิบาย
modelString
Model reference to use for inference (prefer template model name).
จำเป็น · ระบุตามตำแหน่งหรือชื่อ
ไม่มีค่าเริ่มต้น

ค่าที่ส่งกลับ

ตัวอย่าง

# ตรวจสอบความพร้อมของโมเดลก่อนรันการตรวจจับ
if TfliteModel.exists("enemy_model"):
    detector = TfliteModel("enemy_model")
    hits = detector.inference()
    if len(hits) > 0:
        click(hits[0])

ฟิลด์

ชื่อคำอธิบาย
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.
ค่าเริ่มต้น: LETTERBOX
color_modeString
Resolved preprocessing color mode: RGB, BGR, or GRAYSCALE.
ค่าเริ่มต้น: RGB
norm_modeString
Resolved preprocessing normalization: ZERO_ONE, MINUS_ONE_ONE, IMAGENET, or CUSTOM.
ค่าเริ่มต้น: ZERO_ONE
padding_colorInt
Padding fill value (0 -> 255) used by LETTERBOX resize mode.
ค่าเริ่มต้น: 114
ตัวอย่างการสร้างออบเจ็กต์
# นำเข้าโมเดล TFLite ที่รองรับ แล้วเลือกชนิดเอาต์พุตใน Template Manager
# สร้าง model handle ที่ผูกกับชื่อโมเดล TFLite หนึ่งรายการใน Template Manager
model = TfliteModel("enemy_model")

เมธอด

4 เมธอด

TfliteModel.exists

ตรวจสอบว่าไฟล์โมเดล TFLite ในเครื่อง (แก้ไขด้วยชื่อรุ่นหรือรหัสเดิม) พร้อมใช้งานในมาโครนี้หรือไม่

รูปแบบคำสั่ง

TfliteModel.exists(model)

พารามิเตอร์

ชื่อคำอธิบาย
modelString
Model reference to check.
จำเป็น · ระบุตามตำแหน่งหรือชื่อ
ไม่มีค่าเริ่มต้น

ค่าที่ส่งกลับ

Boolean — เป็นจริงหากไฟล์โมเดลในเครื่องพร้อมใช้งาน

ตัวอย่าง

# ตรวจสอบโมเดลที่นำเข้าใน Template Manager
if TfliteModel.exists("enemy_detector"):
    print("Model available")

TfliteModel.list

ส่งคืนการอ้างอิงโมเดลท้องถิ่นที่มีอยู่ในปัจจุบันสำหรับมาโคร (ต้องการชื่อที่แสดง)

รูปแบบคำสั่ง

TfliteModel.list()

ค่าที่ส่งกลับ

list[String] — รายการอ้างอิงรุ่น

ตัวอย่าง

# แสดงรายการโมเดลที่มาโครนี้ใช้งานได้
print(TfliteModel.list())

TfliteModel.exists

ตรวจสอบว่าไฟล์โมเดลในเครื่องของตัวตรวจจับนี้พร้อมใช้งานหรือไม่

รูปแบบคำสั่ง

model.exists()

ค่าที่ส่งกลับ

Boolean — เป็นจริงหากไฟล์โมเดลโลคัลสามารถใช้งานได้ทันที

ตัวอย่าง

# สร้างออบเจ็กต์หลังยืนยันว่ามีโมเดลที่นำเข้าแล้วเท่านั้น
if TfliteModel.exists("enemy_detector"):
    model = TfliteModel("enemy_detector")
    print(model.exists())

TfliteModel.inference

เรียกใช้โมเดล TFLite ที่เลือกโดยไม่มีการกรองคลาสและส่งคืนรายการที่ตรงกันทั้งหมด เมื่อมีการระบุภูมิภาค รูปภาพบนหน้าจอจะถูกครอบตัดก่อนการประมวลผลล่วงหน้าและการอนุมาน สิ่งนี้สามารถลดความแม่นยำของโมเดลได้หากโมเดลไม่ได้รับการฝึกฝนกับรูปภาพที่ครอบตัดในทำนองเดียวกัน การจับคู่ประเภทไม่มีจุดหรือขอบเขต

รูปแบบคำสั่ง

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

พารามิเตอร์

ชื่อคำอธิบาย
thresholdNumber
Confidence threshold in 0 -> 1.
ไม่บังคับ · ระบุตามตำแหน่งหรือชื่อ
ค่าเริ่มต้น: 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.
ไม่บังคับ · ระบุตามตำแหน่งหรือชื่อ
ค่าเริ่มต้น: None
max_resultsInt
Maximum number of detections returned.
ไม่บังคับ · ระบุตามตำแหน่งหรือชื่อ
ค่าเริ่มต้น: 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.
ไม่บังคับ · ระบุตามตำแหน่งหรือชื่อ
ค่าเริ่มต้น: False

ค่าที่ส่งกลับ

MatchList — รายการจับคู่การอนุมานในทุกคลาส

ตัวอย่าง

# รัน inference ของโมเดลดิบและตรวจดูเอาต์พุต debug ของ preprocess
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)))