Spaces:
Paused
Paused
Upload app.py
Browse files
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.
|
| 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 |
-
#
|
| 570 |
-
input_size = model_data
|
| 571 |
-
|
| 572 |
-
|
|
|
|
| 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:
|
| 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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|