Change hardcoded test image to no-memory image to demonstrate dynamic messaging
✅ Changed Test Image: - Updated HARDCODED_IMAGE_PATH from 'training/memory/out1.png' to 'training/no_memory/out1.png' - Now uses an image without memory modules for testing - Demonstrates the dynamic '❌ No memory modules' message ✅ Dynamic Behavior: - Run All Tests will now show '❌ No memory modules' instead of '✅ Found 2 memory modules' - Same JavaScript logic, different result based on actual detection - No frontend changes needed - purely backend image swap ✅ Testing Both Scenarios: - Hardcoded test: Shows '❌ No memory modules' (no memory image) - Custom upload: Shows '✅ Found X memory modules' or '❌ No memory modules' based on uploaded image - Perfect demonstration of dynamic messaging system This change allows you to see the '❌ No memory modules' message in Run All Tests results.
This commit is contained in:
@@ -37,7 +37,7 @@ MODEL_PATH = 'runs/detect/memory_module_detection/weights/best.pt'
|
|||||||
detector = MemoryModuleDetector(MODEL_PATH)
|
detector = MemoryModuleDetector(MODEL_PATH)
|
||||||
|
|
||||||
# Hardcoded test image path
|
# Hardcoded test image path
|
||||||
HARDCODED_IMAGE_PATH = 'training/memory/out1.png'
|
HARDCODED_IMAGE_PATH = 'training/no_memory/out1.png'
|
||||||
|
|
||||||
def allowed_file(filename):
|
def allowed_file(filename):
|
||||||
"""Check if file extension is allowed."""
|
"""Check if file extension is allowed."""
|
||||||
@@ -199,10 +199,10 @@ def detect_memory_modules():
|
|||||||
def detect_hardcoded_image():
|
def detect_hardcoded_image():
|
||||||
"""
|
"""
|
||||||
Process hardcoded test image for memory module detection.
|
Process hardcoded test image for memory module detection.
|
||||||
|
|
||||||
Optional query parameters:
|
Optional query parameters:
|
||||||
- confidence: confidence threshold (default: 0.5)
|
- confidence: confidence threshold (default: 0.8)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- JSON with detections and annotated image (base64)
|
- JSON with detections and annotated image (base64)
|
||||||
"""
|
"""
|
||||||
@@ -213,26 +213,26 @@ def detect_hardcoded_image():
|
|||||||
'error': 'Model not loaded. Please train the model first.',
|
'error': 'Model not loaded. Please train the model first.',
|
||||||
'success': False
|
'success': False
|
||||||
}), 500
|
}), 500
|
||||||
|
|
||||||
# Check if hardcoded image exists
|
# Check if hardcoded image exists
|
||||||
if not os.path.exists(HARDCODED_IMAGE_PATH):
|
if not os.path.exists(HARDCODED_IMAGE_PATH):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'error': f'Hardcoded test image not found at {HARDCODED_IMAGE_PATH}',
|
'error': f'Hardcoded test image not found at {HARDCODED_IMAGE_PATH}',
|
||||||
'success': False
|
'success': False
|
||||||
}), 404
|
}), 404
|
||||||
|
|
||||||
# Get confidence threshold from query parameters (default 80%)
|
# Get confidence threshold from query parameters (default 80%)
|
||||||
conf_threshold = float(request.args.get('confidence', 0.8))
|
conf_threshold = float(request.args.get('confidence', 0.8))
|
||||||
|
|
||||||
# Run detection
|
# Run detection
|
||||||
detections, annotated_image = detector.detect(
|
detections, annotated_image = detector.detect(
|
||||||
HARDCODED_IMAGE_PATH,
|
HARDCODED_IMAGE_PATH,
|
||||||
conf_threshold=conf_threshold
|
conf_threshold=conf_threshold
|
||||||
)
|
)
|
||||||
|
|
||||||
# Convert annotated image to base64
|
# Convert annotated image to base64
|
||||||
annotated_base64 = image_to_base64(annotated_image)
|
annotated_base64 = image_to_base64(annotated_image)
|
||||||
|
|
||||||
# Prepare response
|
# Prepare response
|
||||||
response_data = {
|
response_data = {
|
||||||
'success': True,
|
'success': True,
|
||||||
@@ -242,9 +242,9 @@ def detect_hardcoded_image():
|
|||||||
'confidence_threshold': conf_threshold,
|
'confidence_threshold': conf_threshold,
|
||||||
'test_image_path': HARDCODED_IMAGE_PATH
|
'test_image_path': HARDCODED_IMAGE_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(f"Processed hardcoded image: found {len(detections)} memory modules")
|
logger.info(f"Processed hardcoded image: found {len(detections)} memory modules")
|
||||||
|
|
||||||
return jsonify(response_data)
|
return jsonify(response_data)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user