sohamnk commited on
Commit
97c0463
·
verified ·
1 Parent(s): 0d341d8

Update pipeline/logic.py

Browse files
Files changed (1) hide show
  1. pipeline/logic.py +10 -1
pipeline/logic.py CHANGED
@@ -24,6 +24,8 @@ def download_image_from_url(image_url: str) -> Image.Image:
24
  print(" [Download] ✅ Image downloaded and standardized to RGB.")
25
  return image_rgb
26
 
 
 
27
  def detect_and_crop(image: Image.Image, object_name: str, models: dict) -> Image.Image:
28
  print(f"\n [Detect & Crop] Starting detection for object: '{object_name}'")
29
  image_np = np.array(image.convert("RGB"))
@@ -32,9 +34,16 @@ def detect_and_crop(image: Image.Image, object_name: str, models: dict) -> Image
32
  inputs = models['processor_gnd'](images=image, text=prompt, return_tensors="pt").to(models['device'])
33
  with torch.no_grad():
34
  outputs = models['model_gnd'](**inputs)
 
 
35
  results = models['processor_gnd'].post_process_grounded_object_detection(
36
- outputs, inputs.input_ids, box_threshold=0.4, text_threshold=0.3, target_sizes=[(height, width)]
 
 
 
 
37
  )
 
38
  if not results or len(results[0]['boxes']) == 0:
39
  print(" [Detect & Crop] ⚠ Warning: Grounding DINO did not detect the object. Using full image.")
40
  return image
 
24
  print(" [Download] ✅ Image downloaded and standardized to RGB.")
25
  return image_rgb
26
 
27
+ # In pipeline/logic.py
28
+
29
  def detect_and_crop(image: Image.Image, object_name: str, models: dict) -> Image.Image:
30
  print(f"\n [Detect & Crop] Starting detection for object: '{object_name}'")
31
  image_np = np.array(image.convert("RGB"))
 
34
  inputs = models['processor_gnd'](images=image, text=prompt, return_tensors="pt").to(models['device'])
35
  with torch.no_grad():
36
  outputs = models['model_gnd'](**inputs)
37
+
38
+ # THIS IS THE CORRECTED LINE:
39
  results = models['processor_gnd'].post_process_grounded_object_detection(
40
+ outputs,
41
+ inputs.input_ids,
42
+ object_detection_threshold=0.4, # Renamed from box_threshold
43
+ text_detection_threshold=0.3, # Renamed from text_threshold
44
+ target_sizes=[(height, width)]
45
  )
46
+
47
  if not results or len(results[0]['boxes']) == 0:
48
  print(" [Detect & Crop] ⚠ Warning: Grounding DINO did not detect the object. Using full image.")
49
  return image