Fix Run All Tests to properly test both memory and no-memory scenarios
This commit is contained in:
@@ -71,7 +71,8 @@ def home():
|
|||||||
'/': 'GET - Frontend interface or API information',
|
'/': 'GET - Frontend interface or API information',
|
||||||
'/api': 'GET - API information (JSON)',
|
'/api': 'GET - API information (JSON)',
|
||||||
'/detect': 'POST - Upload image for memory module detection',
|
'/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',
|
'/detect/base64': 'POST - Process base64 encoded image',
|
||||||
'/health': 'GET - Health check'
|
'/health': 'GET - Health check'
|
||||||
},
|
},
|
||||||
@@ -89,7 +90,8 @@ def api_info():
|
|||||||
'/': 'GET - Frontend interface or API information',
|
'/': 'GET - Frontend interface or API information',
|
||||||
'/api': 'GET - API information (JSON)',
|
'/api': 'GET - API information (JSON)',
|
||||||
'/detect': 'POST - Upload image for memory module detection',
|
'/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',
|
'/detect/base64': 'POST - Process base64 encoded image',
|
||||||
'/health': 'GET - Health check'
|
'/health': 'GET - Health check'
|
||||||
},
|
},
|
||||||
@@ -254,6 +256,68 @@ def detect_hardcoded_image():
|
|||||||
'success': False
|
'success': False
|
||||||
}), 500
|
}), 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'])
|
@app.route('/detect/base64', methods=['POST'])
|
||||||
def detect_base64_image():
|
def detect_base64_image():
|
||||||
"""
|
"""
|
||||||
|
|||||||
+27
-8
@@ -390,26 +390,45 @@ async function runAllTests() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test 2: Hardcoded Image
|
// Test 2: Image with Memory Modules
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/detect/hardcoded`);
|
const response = await fetch(`${API_BASE_URL}/detect/hardcoded`);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
testResults.push({
|
testResults.push({
|
||||||
name: 'Hardcoded Image Detection',
|
name: 'Image with Memory Modules',
|
||||||
success: result.success,
|
success: result.success && result.num_detections > 0,
|
||||||
message: result.success ?
|
message: result.success ?
|
||||||
`Found ${result.num_detections} memory modules` :
|
`✅ Found ${result.num_detections} memory modules` :
|
||||||
`Error: ${result.error}`
|
`❌ Error: ${result.error}`
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
testResults.push({
|
testResults.push({
|
||||||
name: 'Hardcoded Image Detection',
|
name: 'Image with Memory Modules',
|
||||||
success: false,
|
success: false,
|
||||||
message: `Error: ${error.message}`
|
message: `❌ Error: ${error.message}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test 3: API Information
|
// 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 4: API Information
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api`);
|
const response = await fetch(`${API_BASE_URL}/api`);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user