Spaces:
Paused
Paused
Update modules/masking_module.py
Browse files
modules/masking_module.py
CHANGED
@@ -9,6 +9,7 @@ from typing import Any
|
|
9 |
import supervision as sv
|
10 |
from sam2.build_sam import build_sam2, build_sam2_video_predictor
|
11 |
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
|
|
12 |
|
13 |
device = torch.device('cuda')
|
14 |
|
@@ -134,7 +135,8 @@ def masking_process(image,obj):
|
|
134 |
# task_prompt = '<REGION_TO_SEGMENTATION>'
|
135 |
# # task_prompt = '<OPEN_VOCABULARY_DETECTION>'
|
136 |
# print(type(task_prompt),type(obj))
|
137 |
-
print('1')
|
|
|
138 |
image = Image.fromarray(image).convert("RGB")
|
139 |
|
140 |
# results = florence2(image,task_prompt, text_input=obj)
|
@@ -150,17 +152,18 @@ def masking_process(image,obj):
|
|
150 |
# obj = "Tiger"
|
151 |
|
152 |
Florence_results = florence2(image,task_prompt, text_input=obj)
|
153 |
-
print('2')
|
154 |
SAM_IMAGE_MODEL = load_sam_image_model(device=device)
|
155 |
-
print('3')
|
156 |
detections = sv.Detections.from_lmm(
|
157 |
lmm=sv.LMM.FLORENCE_2,
|
158 |
result=Florence_results,
|
159 |
resolution_wh=image.size
|
160 |
)
|
161 |
-
print('4')
|
162 |
response = run_sam_inference(SAM_IMAGE_MODEL, image, detections)
|
163 |
-
print('
|
|
|
164 |
if response['code'] == 400:
|
165 |
print("no object found")
|
166 |
return "no object found"
|
|
|
9 |
import supervision as sv
|
10 |
from sam2.build_sam import build_sam2, build_sam2_video_predictor
|
11 |
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
12 |
+
import time
|
13 |
|
14 |
device = torch.device('cuda')
|
15 |
|
|
|
135 |
# task_prompt = '<REGION_TO_SEGMENTATION>'
|
136 |
# # task_prompt = '<OPEN_VOCABULARY_DETECTION>'
|
137 |
# print(type(task_prompt),type(obj))
|
138 |
+
# print('1')
|
139 |
+
start_time = time.time()
|
140 |
image = Image.fromarray(image).convert("RGB")
|
141 |
|
142 |
# results = florence2(image,task_prompt, text_input=obj)
|
|
|
152 |
# obj = "Tiger"
|
153 |
|
154 |
Florence_results = florence2(image,task_prompt, text_input=obj)
|
155 |
+
# print('2')
|
156 |
SAM_IMAGE_MODEL = load_sam_image_model(device=device)
|
157 |
+
# print('3')
|
158 |
detections = sv.Detections.from_lmm(
|
159 |
lmm=sv.LMM.FLORENCE_2,
|
160 |
result=Florence_results,
|
161 |
resolution_wh=image.size
|
162 |
)
|
163 |
+
# print('4')
|
164 |
response = run_sam_inference(SAM_IMAGE_MODEL, image, detections)
|
165 |
+
print(f'Time taken by masking model: {time.time() - start}')
|
166 |
+
# print('5')
|
167 |
if response['code'] == 400:
|
168 |
print("no object found")
|
169 |
return "no object found"
|