doniramdani820 commited on
Commit
72ca6f0
Β·
verified Β·
1 Parent(s): 660bc39

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -137,7 +137,7 @@ CONFIGS = {
137
  'model_path': 'best_upright.onnx',
138
  'yaml_path': 'data_upright.yaml',
139
  'input_size': 640,
140
- 'confidence_threshold': 0.45,
141
  'nms_threshold': 0.45
142
  }
143
  }
@@ -559,6 +559,9 @@ async def handle_upright_challenge(data: dict) -> dict:
559
  'processing_time': (datetime.now() - start_time).total_seconds()
560
  }
561
 
 
 
 
562
  image_bytes = base64.b64decode(image_b64.split(',')[1])
563
  reconstructed_image_pil = Image.open(io.BytesIO(image_bytes))
564
  original_w, original_h = reconstructed_image_pil.size
@@ -566,10 +569,11 @@ async def handle_upright_challenge(data: dict) -> dict:
566
  # Debug: Log image dimensions
567
  logger.info(f"πŸ” UPRIGHT DEBUG: Original image dimensions: {original_w}x{original_h}")
568
 
569
- # Determine input size for this inference (prefer model config, default to 300 for upright 3x2 grid)
570
- input_size = model_data.get('input_size')
571
- if not isinstance(input_size, int) or input_size <= 0:
572
- input_size = 300
 
573
 
574
  input_tensor = preprocess_image(image_bytes, input_size)
575
  outputs = model_data['session'].run(None, {model_data['input_name']: input_tensor})[0]
@@ -604,13 +608,25 @@ async def handle_upright_challenge(data: dict) -> dict:
604
 
605
  # Debug: Log scaling parameters
606
  logger.info(f"πŸ” UPRIGHT DEBUG: Scaling parameters: scale={scale:.4f}, pad_x={pad_x:.2f}, pad_y={pad_y:.2f}")
607
- logger.info(f"πŸ” UPRIGHT DEBUG: Model input size: {model_data['input_size']}")
608
 
609
  x_center_orig = (box_model[0] - pad_x) / scale
610
  y_center_orig = (box_model[1] - pad_y) / scale
611
 
612
- # Debug: Log original space coordinates
613
- logger.info(f"πŸ” UPRIGHT DEBUG: Original space coordinates: x_center={x_center_orig:.2f}, y_center={y_center_orig:.2f}")
 
 
 
 
 
 
 
 
 
 
 
 
614
 
615
  # Debug: Log grid calculation details
616
  grid_cols, grid_rows = 3, 2
 
137
  'model_path': 'best_upright.onnx',
138
  'yaml_path': 'data_upright.yaml',
139
  'input_size': 640,
140
+ 'confidence_threshold': 0.25, # Lowered from 0.45 for better detection
141
  'nms_threshold': 0.45
142
  }
143
  }
 
559
  'processing_time': (datetime.now() - start_time).total_seconds()
560
  }
561
 
562
+ # Debug: Log model configuration
563
+ logger.info(f"πŸ” UPRIGHT DEBUG: Model config: input_size={model_data['input_size']}, confidence={model_data['confidence']}, nms={model_data['nms']}")
564
+
565
  image_bytes = base64.b64decode(image_b64.split(',')[1])
566
  reconstructed_image_pil = Image.open(io.BytesIO(image_bytes))
567
  original_w, original_h = reconstructed_image_pil.size
 
569
  # Debug: Log image dimensions
570
  logger.info(f"πŸ” UPRIGHT DEBUG: Original image dimensions: {original_w}x{original_h}")
571
 
572
+ # Use the model's configured input size consistently
573
+ input_size = model_data['input_size']
574
+
575
+ # Debug: Log model configuration
576
+ logger.info(f"πŸ” UPRIGHT DEBUG: Model configured input size: {input_size}")
577
 
578
  input_tensor = preprocess_image(image_bytes, input_size)
579
  outputs = model_data['session'].run(None, {model_data['input_name']: input_tensor})[0]
 
608
 
609
  # Debug: Log scaling parameters
610
  logger.info(f"πŸ” UPRIGHT DEBUG: Scaling parameters: scale={scale:.4f}, pad_x={pad_x:.2f}, pad_y={pad_y:.2f}")
611
+ logger.info(f"πŸ” UPRIGHT DEBUG: Input size used: {input_size}")
612
 
613
  x_center_orig = (box_model[0] - pad_x) / scale
614
  y_center_orig = (box_model[1] - pad_y) / scale
615
 
616
+ # Debug: Log original space coordinates with detailed calculation
617
+ logger.info(f"πŸ” UPRIGHT DEBUG: Coordinate transformation:")
618
+ logger.info(f"πŸ” UPRIGHT DEBUG: Model coordinates: x={box_model[0]:.2f}, y={box_model[1]:.2f}")
619
+ logger.info(f"πŸ” UPRIGHT DEBUG: Subtract padding: x={box_model[0]:.2f}-{pad_x:.2f}={box_model[0]-pad_x:.2f}, y={box_model[1]:.2f}-{pad_y:.2f}={box_model[1]-pad_y:.2f}")
620
+ logger.info(f"πŸ” UPRIGHT DEBUG: Divide by scale: x={box_model[0]-pad_x:.2f}/{scale:.4f}={x_center_orig:.2f}, y={box_model[1]-pad_y:.2f}/{scale:.4f}={y_center_orig:.2f}")
621
+ logger.info(f"πŸ” UPRIGHT DEBUG: Final original space coordinates: x_center={x_center_orig:.2f}, y_center={y_center_orig:.2f}")
622
+
623
+ # Validate coordinates are within reasonable bounds
624
+ if x_center_orig < 0 or y_center_orig < 0 or x_center_orig > original_w or y_center_orig > original_h:
625
+ logger.warning(f"⚠️ UPRIGHT WARNING: Coordinates out of bounds: ({x_center_orig:.2f}, {y_center_orig:.2f}) for image {original_w}x{original_h}")
626
+ # Clamp to image bounds
627
+ x_center_orig = max(0, min(x_center_orig, original_w))
628
+ y_center_orig = max(0, min(y_center_orig, original_h))
629
+ logger.info(f"πŸ”§ UPRIGHT FIX: Clamped coordinates to: ({x_center_orig:.2f}, {y_center_orig:.2f})")
630
 
631
  # Debug: Log grid calculation details
632
  grid_cols, grid_rows = 3, 2