From 9389fa492b0188ab85d2bba902f5451c0b1528d1 Mon Sep 17 00:00:00 2001 From: Mohamad Al Mdfaa Date: Sat, 17 Jun 2023 12:36:16 +0300 Subject: [PATCH] fix: improve phrases2classes implementation (#143) This commit improves the phrases2classes implementation by using a regular expression to match sub-phrases in the phrases list. This makes the implementation more accurate and efficient. --- groundingdino/util/inference.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/groundingdino/util/inference.py b/groundingdino/util/inference.py index 718bc7b..d6e81d8 100644 --- a/groundingdino/util/inference.py +++ b/groundingdino/util/inference.py @@ -250,8 +250,10 @@ class Model: def phrases2classes(phrases: List[str], classes: List[str]) -> np.ndarray: class_ids = [] for phrase in phrases: - try: - class_ids.append(classes.index(phrase)) - except ValueError: + for class_ in classes: + if class_ in phrase: + class_ids.append(classes.index(class_)) + break + else: class_ids.append(None) return np.array(class_ids)