Fix Run All Tests to properly test both memory and no-memory scenarios

This commit is contained in:
Aherobo Ovie Victor
2025-07-11 22:11:09 +01:00
parent 4d5ccfd9af
commit b96839d436
2 changed files with 94 additions and 11 deletions
+66 -2
View File
@@ -71,7 +71,8 @@ def home():
'/': 'GET - Frontend interface or API information',
'/api': 'GET - API information (JSON)',
'/detect': 'POST - Upload image for memory module detection',
'/detect/hardcoded': 'GET - Process hardcoded test image',
'/detect/hardcoded': 'GET - Process hardcoded test image (with memory)',
'/detect/no-memory': 'GET - Process test image without memory modules',
'/detect/base64': 'POST - Process base64 encoded image',
'/health': 'GET - Health check'
},
@@ -89,7 +90,8 @@ def api_info():
'/': 'GET - Frontend interface or API information',
'/api': 'GET - API information (JSON)',
'/detect': 'POST - Upload image for memory module detection',
'/detect/hardcoded': 'GET - Process hardcoded test image',
'/detect/hardcoded': 'GET - Process hardcoded test image (with memory)',
'/detect/no-memory': 'GET - Process test image without memory modules',
'/detect/base64': 'POST - Process base64 encoded image',
'/health': 'GET - Health check'
},
@@ -254,6 +256,68 @@ def detect_hardcoded_image():
'success': False
}), 500
@app.route('/detect/no-memory', methods=['GET'])
def detect_no_memory_image():
"""
Process hardcoded test image without memory modules for testing.
Optional query parameters:
- confidence: confidence threshold (default: 0.8)
Returns:
- JSON with detections (should be 0) and annotated image (base64)
"""
try:
# Check if model is loaded
if detector.model is None:
return jsonify({
'error': 'Model not loaded. Please train the model first.',
'success': False
}), 500
# Use no-memory test image
no_memory_image_path = 'training/no_memory/out21.png'
# Check if no-memory image exists
if not os.path.exists(no_memory_image_path):
return jsonify({
'error': f'No-memory test image not found at {no_memory_image_path}',
'success': False
}), 404
# Get confidence threshold from query parameters (default 80%)
conf_threshold = float(request.args.get('confidence', 0.8))
# Run detection
detections, annotated_image = detector.detect(
no_memory_image_path,
conf_threshold=conf_threshold
)
# Convert annotated image to base64
annotated_base64 = image_to_base64(annotated_image)
# Prepare response
response_data = {
'success': True,
'detections': detections,
'num_detections': len(detections),
'annotated_image': annotated_base64,
'confidence_threshold': conf_threshold,
'test_image_path': no_memory_image_path
}
logger.info(f"Processed no-memory image: found {len(detections)} memory modules")
return jsonify(response_data)
except Exception as e:
logger.error(f"Error processing no-memory image: {str(e)}")
return jsonify({
'error': f'Error processing no-memory image: {str(e)}',
'success': False
}), 500
@app.route('/detect/base64', methods=['POST'])
def detect_base64_image():
"""
+28 -9
View File
@@ -390,26 +390,45 @@ async function runAllTests() {
});
}
// Test 2: Hardcoded Image
// Test 2: Image with Memory Modules
try {
const response = await fetch(`${API_BASE_URL}/detect/hardcoded`);
const result = await response.json();
testResults.push({
name: 'Hardcoded Image Detection',
success: result.success,
message: result.success ?
`Found ${result.num_detections} memory modules` :
`Error: ${result.error}`
name: 'Image with Memory Modules',
success: result.success && result.num_detections > 0,
message: result.success ?
`Found ${result.num_detections} memory modules` :
`Error: ${result.error}`
});
} catch (error) {
testResults.push({
name: 'Hardcoded Image Detection',
name: 'Image with Memory Modules',
success: false,
message: `Error: ${error.message}`
message: `Error: ${error.message}`
});
}
// Test 3: Image without Memory Modules
try {
const response = await fetch(`${API_BASE_URL}/detect/no-memory`);
const result = await response.json();
testResults.push({
name: 'Image without Memory Modules',
success: result.success && result.num_detections === 0,
message: result.success ?
`✅ Correctly detected ${result.num_detections} memory modules` :
`❌ Error: ${result.error}`
});
} catch (error) {
testResults.push({
name: 'Image without Memory Modules',
success: false,
message: `❌ Error: ${error.message}`
});
}
// Test 3: API Information
// Test 4: API Information
try {
const response = await fetch(`${API_BASE_URL}/api`);
const result = await response.json();