From d4bd12fd4397d4f3cfbe1d4ac75c2350e7ab5461 Mon Sep 17 00:00:00 2001 From: Shuqi XIAO Date: Wed, 9 Jul 2025 13:01:48 +0800 Subject: [PATCH] fix: Initialize `txt_masks` to prevent `UnboundLocalError` during ONNX export The `extract_feat` method in `YOLOWorldDetector` was missing initialization of txt_masks when using cached text features, causing ONNX export to fail with `UnboundLocalError`. This fix ensures `txt_masks` is properly initialized to `None` in all code paths. --- yolo_world/models/detectors/yolo_world.py | 1 + 1 file changed, 1 insertion(+) diff --git a/yolo_world/models/detectors/yolo_world.py b/yolo_world/models/detectors/yolo_world.py index c72963d1..7b393df1 100644 --- a/yolo_world/models/detectors/yolo_world.py +++ b/yolo_world/models/detectors/yolo_world.py @@ -94,6 +94,7 @@ def extract_feat( if txt_feats is not None: # forward image only img_feats = self.backbone.forward_image(batch_inputs) + txt_masks = None else: img_feats, (txt_feats, txt_masks) = self.backbone(batch_inputs, texts)