Spaces:
Sleeping
Sleeping
Update services/vision/service.py
Browse files
services/vision/service.py
CHANGED
|
@@ -159,9 +159,11 @@ async def _florence_caption(image: Image.Image) -> str:
|
|
| 159 |
|
| 160 |
try:
|
| 161 |
device = get_device()
|
|
|
|
| 162 |
_florence_model.to(device)
|
| 163 |
prompt = "<MORE_DETAILED_CAPTION>"
|
| 164 |
inputs = _florence_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
|
|
|
| 165 |
|
| 166 |
with torch.no_grad():
|
| 167 |
generated_ids = _florence_model.generate(
|
|
@@ -188,9 +190,11 @@ async def _florence_detect(image: Image.Image) -> list[dict]:
|
|
| 188 |
|
| 189 |
try:
|
| 190 |
device = get_device()
|
|
|
|
| 191 |
_florence_model.to(device)
|
| 192 |
prompt = "<OD>"
|
| 193 |
inputs = _florence_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
|
|
|
| 194 |
|
| 195 |
with torch.no_grad():
|
| 196 |
generated_ids = _florence_model.generate(
|
|
@@ -249,7 +253,7 @@ async def _grounding_dino_detect(image: Image.Image) -> list[dict]:
|
|
| 249 |
results = _dino_processor.post_process_grounded_object_detection(
|
| 250 |
outputs,
|
| 251 |
inputs.input_ids,
|
| 252 |
-
|
| 253 |
text_threshold=VISION_CONFIG["grounding_dino_text_threshold"],
|
| 254 |
target_sizes=[image.size[::-1]],
|
| 255 |
)
|
|
|
|
| 159 |
|
| 160 |
try:
|
| 161 |
device = get_device()
|
| 162 |
+
dtype = get_torch_dtype()
|
| 163 |
_florence_model.to(device)
|
| 164 |
prompt = "<MORE_DETAILED_CAPTION>"
|
| 165 |
inputs = _florence_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
| 166 |
+
inputs = {k: v.to(dtype) if v.is_floating_point() else v for k, v in inputs.items()}
|
| 167 |
|
| 168 |
with torch.no_grad():
|
| 169 |
generated_ids = _florence_model.generate(
|
|
|
|
| 190 |
|
| 191 |
try:
|
| 192 |
device = get_device()
|
| 193 |
+
dtype = get_torch_dtype()
|
| 194 |
_florence_model.to(device)
|
| 195 |
prompt = "<OD>"
|
| 196 |
inputs = _florence_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
| 197 |
+
inputs = {k: v.to(dtype) if v.is_floating_point() else v for k, v in inputs.items()}
|
| 198 |
|
| 199 |
with torch.no_grad():
|
| 200 |
generated_ids = _florence_model.generate(
|
|
|
|
| 253 |
results = _dino_processor.post_process_grounded_object_detection(
|
| 254 |
outputs,
|
| 255 |
inputs.input_ids,
|
| 256 |
+
box_threshold=VISION_CONFIG["grounding_dino_box_threshold"],
|
| 257 |
text_threshold=VISION_CONFIG["grounding_dino_text_threshold"],
|
| 258 |
target_sizes=[image.size[::-1]],
|
| 259 |
)
|