Set confidence threshold to 80% and remove slider from frontend

 Frontend Changes:
- Removed confidence threshold slider from web interface
- Added fixed 80% confidence display with green info box
- Updated JavaScript to use fixed 0.8 threshold
- Removed slider-related CSS styles

 Backend Changes:
- Updated all API endpoints to default to 80% confidence (0.8)
- Modified POST /detect, GET /detect/hardcoded, POST /detect/base64
- Updated comments to reflect new default threshold

 Testing Updates:
- Updated test_api.py to use 80% confidence for all tests
- Ensures consistent testing with new threshold

 Benefits:
- High precision mode (80% confidence) reduces false positives
- Simplified user interface without threshold adjustment
- Consistent detection behavior across all endpoints
This commit is contained in:
Aherobo Ovie Victor
2025-07-11 20:47:04 +01:00
parent c4de90fbec
commit 26a6f6f625
6 changed files with 31 additions and 40 deletions
+6 -6
View File
@@ -149,8 +149,8 @@ def detect_memory_modules():
'success': False 'success': False
}), 400 }), 400
# Get confidence threshold from form data # Get confidence threshold from form data (default 80%)
conf_threshold = float(request.form.get('confidence', 0.5)) conf_threshold = float(request.form.get('confidence', 0.8))
# Save uploaded file temporarily # Save uploaded file temporarily
filename = secure_filename(file.filename) filename = secure_filename(file.filename)
@@ -219,8 +219,8 @@ def detect_hardcoded_image():
'success': False 'success': False
}), 404 }), 404
# Get confidence threshold from query parameters # Get confidence threshold from query parameters (default 80%)
conf_threshold = float(request.args.get('confidence', 0.5)) conf_threshold = float(request.args.get('confidence', 0.8))
# Run detection # Run detection
detections, annotated_image = detector.detect( detections, annotated_image = detector.detect(
@@ -283,8 +283,8 @@ def detect_base64_image():
'success': False 'success': False
}), 400 }), 400
# Get confidence threshold # Get confidence threshold (default 80%)
conf_threshold = float(data.get('confidence', 0.5)) conf_threshold = float(data.get('confidence', 0.8))
# Decode base64 image # Decode base64 image
try: try:
+1
View File
@@ -8,6 +8,7 @@ Pillow==10.0.1
# Web Framework # Web Framework
Flask==2.3.3 Flask==2.3.3
Flask-CORS==4.0.0 Flask-CORS==4.0.0
Flask-RESTX==1.3.0
Werkzeug==2.3.7 Werkzeug==2.3.7
# Data Processing # Data Processing
+2 -7
View File
@@ -24,11 +24,6 @@ function setupEventListeners() {
uploadArea.addEventListener('dragleave', handleDragLeave); uploadArea.addEventListener('dragleave', handleDragLeave);
uploadArea.addEventListener('drop', handleDrop); uploadArea.addEventListener('drop', handleDrop);
uploadArea.addEventListener('click', () => document.getElementById('fileInput').click()); uploadArea.addEventListener('click', () => document.getElementById('fileInput').click());
// Confidence slider
document.getElementById('confidenceSlider').addEventListener('input', function() {
document.getElementById('confidenceValue').textContent = this.value;
});
} }
async function checkApiStatus() { async function checkApiStatus() {
@@ -144,7 +139,7 @@ async function processUploadedImage() {
return; return;
} }
const confidence = document.getElementById('confidenceSlider').value; const confidence = 0.8; // Fixed 80% threshold
showLoading('Processing uploaded image...'); showLoading('Processing uploaded image...');
try { try {
@@ -175,7 +170,7 @@ async function testHardcodedImage() {
showLoading('Testing hardcoded image...'); showLoading('Testing hardcoded image...');
try { try {
const response = await fetch(`${API_BASE_URL}/detect/hardcoded?confidence=0.5`); const response = await fetch(`${API_BASE_URL}/detect/hardcoded?confidence=0.8`);
const result = await response.json(); const result = await response.json();
hideLoading(); hideLoading();
+9 -13
View File
@@ -186,22 +186,18 @@ header p {
border-radius: 8px; border-radius: 8px;
} }
.confidence-control { .confidence-info {
margin-bottom: 15px; margin-bottom: 15px;
padding: 10px;
background: #e8f5e8;
border-radius: 6px;
border-left: 4px solid #28a745;
} }
.confidence-control label { .confidence-info p {
display: block; margin: 0;
margin-bottom: 8px; color: #155724;
font-weight: 500; font-size: 0.9rem;
}
.confidence-control input[type="range"] {
width: 100%;
height: 6px;
border-radius: 3px;
background: #ddd;
outline: none;
} }
.results-content { .results-content {
+2 -3
View File
@@ -58,9 +58,8 @@
</div> </div>
<div class="upload-controls" style="display: none;" id="uploadControls"> <div class="upload-controls" style="display: none;" id="uploadControls">
<div class="confidence-control"> <div class="confidence-info">
<label for="confidenceSlider">Confidence Threshold: <span id="confidenceValue">0.5</span></label> <p><strong>Confidence Threshold:</strong> 80% (High Precision Mode)</p>
<input type="range" id="confidenceSlider" min="0.1" max="1.0" step="0.1" value="0.5">
</div> </div>
<button class="btn btn-success" onclick="processUploadedImage()"> <button class="btn btn-success" onclick="processUploadedImage()">
<i class="fas fa-search"></i> Detect Memory Modules <i class="fas fa-search"></i> Detect Memory Modules
+3 -3
View File
@@ -53,7 +53,7 @@ def test_hardcoded_detection():
"""Test detection with hardcoded image.""" """Test detection with hardcoded image."""
print("\n🖼️ Testing Hardcoded Image Detection...") print("\n🖼️ Testing Hardcoded Image Detection...")
try: try:
response = requests.get(f"{BASE_URL}/detect/hardcoded?confidence=0.5") response = requests.get(f"{BASE_URL}/detect/hardcoded?confidence=0.8")
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
if data['success']: if data['success']:
@@ -105,7 +105,7 @@ def test_file_upload():
try: try:
with open(test_image_path, 'rb') as f: with open(test_image_path, 'rb') as f:
files = {'image': f} files = {'image': f}
data = {'confidence': '0.5'} data = {'confidence': '0.8'}
response = requests.post(f"{BASE_URL}/detect", files=files, data=data) response = requests.post(f"{BASE_URL}/detect", files=files, data=data)
if response.status_code == 200: if response.status_code == 200:
@@ -165,7 +165,7 @@ def test_base64_detection():
# Send request # Send request
payload = { payload = {
'image': base64_string, 'image': base64_string,
'confidence': 0.5 'confidence': 0.8
} }
response = requests.post( response = requests.post(