From 22486771fd059fdc3a4664585ba939d2175c75cd Mon Sep 17 00:00:00 2001 From: Yuanwen Tian Date: Wed, 25 Sep 2024 10:40:52 +0800 Subject: [PATCH 1/2] fix: fine tune multiple times should edit original id --- vision_agent/tools/meta_tools.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/vision_agent/tools/meta_tools.py b/vision_agent/tools/meta_tools.py index 5cb035d3..75b8b7a6 100644 --- a/vision_agent/tools/meta_tools.py +++ b/vision_agent/tools/meta_tools.py @@ -643,7 +643,23 @@ def use_object_detection_fine_tuning( return output_str code = artifacts[name] - patterns = [ + + patterns_with_fine_tune_id = [ + ( + r'florence2_phrase_grounding\(\s*"([^"]+)"\s*,\s*([^,]+)(?:,\s*"[^"]+")?\s*\)', + lambda match: f'florence2_phrase_grounding("{match.group(1)}", {match.group(2)}, "{fine_tune_id}")', + ), + ( + r'owl_v2_image\(\s*"([^"]+)"\s*,\s*([^,]+)(?:,\s*"[^"]+")?\s*\)', + lambda match: f'owl_v2_image("{match.group(1)}", {match.group(2)}, "{fine_tune_id}")', + ), + ( + r'florence2_sam2_image\(\s*"([^"]+)"\s*,\s*([^,]+)(?:,\s*"[^"]+")?\s*\)', + lambda match: f'florence2_sam2_image("{match.group(1)}", {match.group(2)}, "{fine_tune_id}")', + ), + ] + + patterns_without_fine_tune_id = [ ( r"florence2_phrase_grounding\(\s*([^\)]+)\s*\)", lambda match: f'florence2_phrase_grounding({match.group(1)}, "{fine_tune_id}")', @@ -659,8 +675,13 @@ def use_object_detection_fine_tuning( ] new_code = code - for pattern, replacer in patterns: - new_code = re.sub(pattern, replacer, new_code) + + for index, (pattern_with_fine_tune_id, replacer_with_fine_tune_id) in enumerate(patterns_with_fine_tune_id): + if re.search(pattern_with_fine_tune_id, new_code): + new_code = re.sub(pattern_with_fine_tune_id, replacer_with_fine_tune_id, new_code) + else: + (pattern_without_fine_tune_id, replacer_without_fine_tune_id) = patterns_without_fine_tune_id[index] + new_code = re.sub(pattern_without_fine_tune_id, replacer_without_fine_tune_id, new_code) if new_code == code: output_str = ( From 5d6175a22b6c4a9cba056440c41ac6fff751580c Mon Sep 17 00:00:00 2001 From: Yuanwen Tian Date: Wed, 25 Sep 2024 13:19:18 +0800 Subject: [PATCH 2/2] format --- vision_agent/tools/meta_tools.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/vision_agent/tools/meta_tools.py b/vision_agent/tools/meta_tools.py index 75b8b7a6..e108f8a4 100644 --- a/vision_agent/tools/meta_tools.py +++ b/vision_agent/tools/meta_tools.py @@ -676,12 +676,20 @@ def use_object_detection_fine_tuning( new_code = code - for index, (pattern_with_fine_tune_id, replacer_with_fine_tune_id) in enumerate(patterns_with_fine_tune_id): + for index, (pattern_with_fine_tune_id, replacer_with_fine_tune_id) in enumerate( + patterns_with_fine_tune_id + ): if re.search(pattern_with_fine_tune_id, new_code): - new_code = re.sub(pattern_with_fine_tune_id, replacer_with_fine_tune_id, new_code) + new_code = re.sub( + pattern_with_fine_tune_id, replacer_with_fine_tune_id, new_code + ) else: - (pattern_without_fine_tune_id, replacer_without_fine_tune_id) = patterns_without_fine_tune_id[index] - new_code = re.sub(pattern_without_fine_tune_id, replacer_without_fine_tune_id, new_code) + (pattern_without_fine_tune_id, replacer_without_fine_tune_id) = ( + patterns_without_fine_tune_id[index] + ) + new_code = re.sub( + pattern_without_fine_tune_id, replacer_without_fine_tune_id, new_code + ) if new_code == code: output_str = (