hoàn thành tính cận trên và cận dưới của tất cả các thuật toán

This commit is contained in:
Victor Phan
2026-02-24 21:36:02 +07:00
parent ae4d8cbbc9
commit 0ab6461882
203 changed files with 3089 additions and 86 deletions
Regular → Executable
+532 -30
View File
@@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cloud Removal Training - Deep Learning</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<style>
* {
margin: 0;
@@ -553,15 +554,161 @@
<!-- Training Status -->
<div class="section" id="trainingStatus" style="display: none;">
<h2 class="section-title">📊 Training Status</h2>
<h2 class="section-title">📊 Training Status - Real-time Baseline PSNR Tracking</h2>
<div class="card">
<div id="statusMessage"></div>
<div class="progress-bar">
<!-- Metrics Grid -->
<div class="grid-2" style="margin-top: 20px;">
<div class="card" style="text-align: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
<h4 style="margin-bottom: 10px;">📈 Model PSNR</h4>
<div style="font-size: 2.5em; font-weight: bold;" id="modelPSNR">--</div>
<small>dB (higher is better)</small>
</div>
<div class="card" style="text-align: center; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: white;">
<h4 style="margin-bottom: 10px;">📉 Baseline PSNR</h4>
<div style="font-size: 2.5em; font-weight: bold;" id="baselinePSNR">--</div>
<small>dB (cận dưới - không làm gì)</small>
</div>
<div class="card" style="text-align: center; background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); color: white;">
<h4 style="margin-bottom: 10px;">⚡ Improvement</h4>
<div style="font-size: 2.5em; font-weight: bold;" id="improvement">--</div>
<small>dB (Model - Baseline)</small>
</div>
<div class="card" style="text-align: center; background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: white;">
<h4 style="margin-bottom: 10px;">🎯 Progress</h4>
<div style="font-size: 2.5em; font-weight: bold;" id="epochProgress">0/0</div>
<small>Epochs completed</small>
</div>
</div>
<!-- Progress Bar -->
<div class="progress-bar" style="margin-top: 20px;">
<div class="progress-fill" id="progressBar" style="width: 0%;">0%</div>
</div>
<div class="logs" id="trainingLogs">
<!-- Performance Range Cards (Best & Worst) -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
<!-- Best PSNR Checkpoint -->
<div id="bestPSNRCard" style="background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%); padding: 20px; border-radius: 12px; box-shadow: 0 8px 24px rgba(255, 215, 0, 0.3); display: none;">
<h3 style="text-align: center; margin-bottom: 15px; color: white; text-shadow: 0 2px 4px rgba(0,0,0,0.2);">🏆 Best PSNR (Cao Nhất)</h3>
<div class="grid-2" style="gap: 15px;">
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Best Model PSNR</div>
<div style="font-size: 2em; font-weight: bold; color: #667eea;" id="bestModelPSNR">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">At Epoch</div>
<div style="font-size: 2em; font-weight: bold; color: #764ba2;" id="bestEpoch">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">epoch</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Train Loss</div>
<div style="font-size: 1.5em; font-weight: bold; color: #43e97b;" id="bestTrainLoss">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">MSE</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Val Loss</div>
<div style="font-size: 1.5em; font-weight: bold; color: #f5576c;" id="bestValLoss">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">MSE</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Baseline PSNR</div>
<div style="font-size: 1.5em; font-weight: bold; color: #f093fb;" id="bestBaselinePSNR">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB (cận dưới)</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Improvement</div>
<div style="font-size: 1.5em; font-weight: bold; color: #4facfe;" id="bestImprovement">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB (vs baseline)</div>
</div>
</div>
</div>
<!-- Worst PSNR Checkpoint -->
<div id="worstPSNRCard" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; border-radius: 12px; box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3); display: none;">
<h3 style="text-align: center; margin-bottom: 15px; color: white; text-shadow: 0 2px 4px rgba(0,0,0,0.2);">📉 Worst PSNR (Thấp Nhất)</h3>
<div class="grid-2" style="gap: 15px;">
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Worst Model PSNR</div>
<div style="font-size: 2em; font-weight: bold; color: #667eea;" id="worstModelPSNR">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB (cận dưới)</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">At Epoch</div>
<div style="font-size: 2em; font-weight: bold; color: #764ba2;" id="worstEpoch">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">epoch</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Train Loss</div>
<div style="font-size: 1.5em; font-weight: bold; color: #43e97b;" id="worstTrainLoss">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">MSE</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Val Loss</div>
<div style="font-size: 1.5em; font-weight: bold; color: #f5576c;" id="worstValLoss">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">MSE</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Baseline PSNR</div>
<div style="font-size: 1.5em; font-weight: bold; color: #f093fb;" id="worstBaselinePSNR">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Gap from Baseline</div>
<div style="font-size: 1.5em; font-weight: bold; color: #4facfe;" id="worstImprovement">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB</div>
</div>
</div>
</div>
</div>
<!-- Performance Range Summary -->
<div id="performanceRangeCard" style="margin-top: 20px; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); padding: 20px; border-radius: 12px; box-shadow: 0 8px 24px rgba(245, 87, 108, 0.3); display: none;">
<h3 style="text-align: center; margin-bottom: 15px; color: white; text-shadow: 0 2px 4px rgba(0,0,0,0.2);">📊 Performance Range & Baseline</h3>
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px;">
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">PSNR Range</div>
<div style="font-size: 1.5em; font-weight: bold; color: #667eea;" id="psnrRange">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB (max - min)</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Avg PSNR</div>
<div style="font-size: 1.5em; font-weight: bold; color: #43e97b;" id="avgPSNR">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Stability</div>
<div style="font-size: 1.5em; font-weight: bold; color: #f093fb;" id="stability">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">%</div>
</div>
<div style="background: rgba(255,255,255,0.95); padding: 15px; border-radius: 8px; text-align: center;">
<div style="font-size: 0.85em; color: #666; margin-bottom: 5px;">Baseline PSNR</div>
<div style="font-size: 1.5em; font-weight: bold; color: #ff6b6b;" id="baselinePSNRDisplay">--</div>
<div style="font-size: 0.75em; color: #888; margin-top: 3px;">dB (cận dưới)</div>
</div>
</div>
<div id="baselineComparisonText" style="margin-top: 15px; padding: 12px; background: rgba(255,255,255,0.9); border-radius: 6px; text-align: center; font-size: 0.9em; font-weight: 600;">
--
</div>
</div>
<!-- PSNR Chart -->
<div style="margin-top: 30px; background: white; padding: 20px; border-radius: 12px;">
<h3 style="text-align: center; margin-bottom: 20px;">📊 PSNR vs Baseline - Live Chart</h3>
<canvas id="psnrChart" width="400" height="200"></canvas>
</div>
<!-- Training Logs -->
<div class="logs" id="trainingLogs" style="margin-top: 20px;">
<div class="log-entry log-info">Training logs will appear here...</div>
</div>
<!-- Stop Button -->
<div style="margin-top: 20px; text-align: center;">
<button class="btn btn-danger" onclick="stopTraining()">⏹️ Stop Training</button>
</div>
</div>
</div>
@@ -632,11 +779,360 @@
</div>
<script>
let psnrChart = null;
let statusPolling = null;
let bestPSNRData = {
modelPSNR: 0,
epoch: 0,
trainLoss: 0,
valLoss: 0,
baselinePSNR: 0,
improvement: 0
};
let worstPSNRData = {
modelPSNR: Infinity,
epoch: 0,
trainLoss: 0,
valLoss: 0,
baselinePSNR: 0,
improvement: 0
};
let psnrHistory = [];
let baselinePSNR = 0; // PSNR cận dưới (cloudy vs clean without model)
// Load models on page load
window.addEventListener('load', () => {
refreshModels();
loadCloudRemovalMethods();
initPSNRChart();
});
// Initialize PSNR Chart
function initPSNRChart() {
const ctx = document.getElementById('psnrChart').getContext('2d');
psnrChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [
{
label: 'Model PSNR (dB)',
data: [],
borderColor: 'rgb(102, 126, 234)',
backgroundColor: 'rgba(102, 126, 234, 0.1)',
borderWidth: 3,
tension: 0.4,
fill: true
},
{
label: 'Baseline PSNR (dB)',
data: [],
borderColor: 'rgb(245, 87, 108)',
backgroundColor: 'rgba(245, 87, 108, 0.1)',
borderWidth: 2,
borderDash: [5, 5],
tension: 0,
fill: false
},
{
label: 'Improvement (dB)',
data: [],
borderColor: 'rgb(67, 233, 123)',
backgroundColor: 'rgba(67, 233, 123, 0.1)',
borderWidth: 2,
tension: 0.4,
fill: true,
yAxisID: 'y1'
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
interaction: {
mode: 'index',
intersect: false,
},
plugins: {
legend: {
display: true,
position: 'top',
},
title: {
display: true,
text: 'Model phải vượt qua Baseline (cận dưới) để có ý nghĩa!'
}
},
scales: {
y: {
type: 'linear',
display: true,
position: 'left',
title: {
display: true,
text: 'PSNR (dB)'
}
},
y1: {
type: 'linear',
display: true,
position: 'right',
title: {
display: true,
text: 'Improvement (dB)'
},
grid: {
drawOnChartArea: false,
},
}
}
}
});
}
// Update PSNR Chart with new data
function updatePSNRChart(history, baselinePSNR) {
if (!psnrChart || !history) return;
psnrChart.data.labels = history.epochs;
psnrChart.data.datasets[0].data = history.val_psnrs;
psnrChart.data.datasets[1].data = history.epochs.map(() => baselinePSNR);
psnrChart.data.datasets[2].data = history.improvements;
psnrChart.update();
}
// Poll training status
function startStatusPolling() {
if (statusPolling) clearInterval(statusPolling);
statusPolling = setInterval(async () => {
try {
const response = await fetch('/api/cloud-removal/training/status');
const status = await response.json();
if (status.is_training) {
// Update metrics
document.getElementById('modelPSNR').textContent =
status.val_psnr > 0 ? status.val_psnr.toFixed(2) : '--';
document.getElementById('baselinePSNR').textContent =
status.baseline_psnr > 0 ? status.baseline_psnr.toFixed(2) : '--';
document.getElementById('improvement').textContent =
status.improvement !== 0 ? (status.improvement > 0 ? '+' : '') + status.improvement.toFixed(2) : '--';
document.getElementById('epochProgress').textContent =
`${status.current_epoch}/${status.total_epochs}`;
// Track PSNR history
if (status.val_psnr > 0) {
psnrHistory.push(status.val_psnr);
}
// Track best PSNR (cao nhất - cận trên)
if (status.val_psnr > bestPSNRData.modelPSNR && status.val_psnr > 0) {
bestPSNRData = {
modelPSNR: status.val_psnr,
epoch: status.current_epoch,
trainLoss: status.train_loss,
valLoss: status.val_loss,
baselinePSNR: status.baseline_psnr,
improvement: status.improvement
};
// Update best PSNR display
document.getElementById('bestPSNRCard').style.display = 'block';
document.getElementById('bestModelPSNR').textContent = bestPSNRData.modelPSNR.toFixed(2);
document.getElementById('bestEpoch').textContent = bestPSNRData.epoch;
document.getElementById('bestTrainLoss').textContent = bestPSNRData.trainLoss.toFixed(6);
document.getElementById('bestValLoss').textContent = bestPSNRData.valLoss.toFixed(6);
document.getElementById('bestBaselinePSNR').textContent = bestPSNRData.baselinePSNR.toFixed(2);
document.getElementById('bestImprovement').textContent =
(bestPSNRData.improvement > 0 ? '+' : '') + bestPSNRData.improvement.toFixed(2);
// Add log for new best PSNR
addLog('success', `🏆 New Best PSNR! Epoch ${bestPSNRData.epoch}: ${bestPSNRData.modelPSNR.toFixed(2)}dB ` +
`(Improvement: +${bestPSNRData.improvement.toFixed(2)}dB vs baseline)`);
}
// Track worst PSNR (thấp nhất - cận dưới)
if (status.val_psnr < worstPSNRData.modelPSNR && status.val_psnr > 0) {
worstPSNRData = {
modelPSNR: status.val_psnr,
epoch: status.current_epoch,
trainLoss: status.train_loss,
valLoss: status.val_loss,
baselinePSNR: status.baseline_psnr,
improvement: status.improvement
};
// Update worst PSNR display
document.getElementById('worstPSNRCard').style.display = 'block';
document.getElementById('worstModelPSNR').textContent = worstPSNRData.modelPSNR.toFixed(2);
document.getElementById('worstEpoch').textContent = worstPSNRData.epoch;
document.getElementById('worstTrainLoss').textContent = worstPSNRData.trainLoss.toFixed(6);
document.getElementById('worstValLoss').textContent = worstPSNRData.valLoss.toFixed(6);
document.getElementById('worstBaselinePSNR').textContent = worstPSNRData.baselinePSNR.toFixed(2);
document.getElementById('worstImprovement').textContent =
(worstPSNRData.improvement > 0 ? '+' : '') + worstPSNRData.improvement.toFixed(2);
// Add log for new worst PSNR
addLog('warning', `📉 Worst PSNR updated: Epoch ${worstPSNRData.epoch}: ${worstPSNRData.modelPSNR.toFixed(2)}dB (cận dưới)`);
}
// Update Performance Range Summary
if (bestPSNRData.modelPSNR > 0 && worstPSNRData.modelPSNR < Infinity && psnrHistory.length > 0) {
document.getElementById('performanceRangeCard').style.display = 'block';
const range = bestPSNRData.modelPSNR - worstPSNRData.modelPSNR;
const avgPSNR = psnrHistory.reduce((a, b) => a + b, 0) / psnrHistory.length;
const stability = avgPSNR > 0 ? ((1 - range / avgPSNR) * 100) : 0;
// Update baseline PSNR (cận dưới tuyệt đối)
if (status.baseline_psnr > 0) {
baselinePSNR = status.baseline_psnr;
}
document.getElementById('psnrRange').textContent = range.toFixed(2);
document.getElementById('avgPSNR').textContent = avgPSNR.toFixed(2);
document.getElementById('stability').textContent = Math.max(0, stability).toFixed(1);
document.getElementById('baselinePSNRDisplay').textContent = baselinePSNR > 0 ? baselinePSNR.toFixed(2) : '--';
// Compare worst PSNR with baseline PSNR
const baselineComparisonDiv = document.getElementById('baselineComparisonText');
if (baselinePSNR > 0) {
const margin = worstPSNRData.modelPSNR - baselinePSNR;
if (margin > 5) {
baselineComparisonDiv.innerHTML = `✅ <strong>Tốt:</strong> PSNR thấp nhất (${worstPSNRData.modelPSNR.toFixed(2)}dB) vượt baseline +${margin.toFixed(2)}dB - Model học tốt ngay cả trong worst case`;
baselineComparisonDiv.style.color = '#2ecc71';
} else if (margin > 2) {
baselineComparisonDiv.innerHTML = `⚠️ <strong>Khá:</strong> PSNR thấp nhất (${worstPSNRData.modelPSNR.toFixed(2)}dB) vượt baseline +${margin.toFixed(2)}dB - Cần cải thiện stability`;
baselineComparisonDiv.style.color = '#f39c12';
} else if (margin > 0) {
baselineComparisonDiv.innerHTML = `⚠️ <strong>Yếu:</strong> PSNR thấp nhất (${worstPSNRData.modelPSNR.toFixed(2)}dB) chỉ vượt baseline +${margin.toFixed(2)}dB - Model không ổn định`;
baselineComparisonDiv.style.color = '#e67e22';
} else {
baselineComparisonDiv.innerHTML = `❌ <strong>Kém:</strong> PSNR thấp nhất (${worstPSNRData.modelPSNR.toFixed(2)}dB) không vượt baseline (${baselinePSNR.toFixed(2)}dB) - Model thất bại`;
baselineComparisonDiv.style.color = '#e74c3c';
}
} else {
baselineComparisonDiv.innerHTML = 'Đang chờ baseline PSNR...';
baselineComparisonDiv.style.color = '#95a5a6';
}
}
// Update progress bar
const progress = status.total_epochs > 0 ? (status.current_epoch / status.total_epochs) * 100 : 0;
const progressBar = document.getElementById('progressBar');
progressBar.style.width = progress + '%';
progressBar.textContent = Math.floor(progress) + '%';
// Update chart
if (status.history && status.history.epochs.length > 0) {
updatePSNRChart(status.history, status.baseline_psnr);
}
// Add log for significant events
if (status.current_epoch > 0 && status.current_epoch % 5 === 0) {
const improvement = status.improvement;
const emoji = improvement > 0 ? '✅' : '⚠️';
addLog('info', `Epoch ${status.current_epoch}: Model PSNR=${status.val_psnr.toFixed(2)}dB, ` +
`Baseline=${status.baseline_psnr.toFixed(2)}dB, Improvement=${emoji} ${improvement > 0 ? '+' : ''}${improvement.toFixed(2)}dB`);
}
} else {
// Training finished
if (status.progress === 'Completed!') {
addLog('info', '✅ Training completed successfully!');
stopStatusPolling();
// Regenerate report with best_checkpoint and worst_checkpoint if available
if (status.result && bestPSNRData.modelPSNR > 0) {
setTimeout(async () => {
try {
const reportData = {
training_result: status.result,
best_checkpoint: {
modelPSNR: bestPSNRData.modelPSNR,
epoch: bestPSNRData.epoch,
trainLoss: bestPSNRData.trainLoss,
valLoss: bestPSNRData.valLoss,
baselinePSNR: bestPSNRData.baselinePSNR,
improvement: bestPSNRData.improvement
}
};
// Add worst_checkpoint if available
if (worstPSNRData.modelPSNR < Infinity) {
reportData.worst_checkpoint = {
modelPSNR: worstPSNRData.modelPSNR,
epoch: worstPSNRData.epoch,
trainLoss: worstPSNRData.trainLoss,
valLoss: worstPSNRData.valLoss,
baselinePSNR: worstPSNRData.baselinePSNR,
improvement: worstPSNRData.improvement
};
}
// Add baseline PSNR if available
if (baselinePSNR > 0) {
reportData.baseline_psnr = baselinePSNR;
}
const regenerateResponse = await fetch('/api/training/report/regenerate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(reportData)
});
const regenerateData = await regenerateResponse.json();
if (regenerateData.success) {
console.log('Report regenerated with checkpoints:', regenerateData.report_path);
addLog('success', '📊 Báo cáo đã được cập nhật với Best/Worst PSNR Checkpoint và Performance Range');
}
} catch (err) {
console.error('Failed to regenerate report:', err);
}
refreshModels();
}, 1000);
} else {
setTimeout(refreshModels, 2000);
}
} else if (status.error) {
addLog('error', `❌ Error: ${status.error}`);
stopStatusPolling();
}
}
} catch (error) {
console.error('Error polling status:', error);
}
}, 2000); // Poll every 2 seconds
}
function stopStatusPolling() {
if (statusPolling) {
clearInterval(statusPolling);
statusPolling = null;
}
}
// Stop training
async function stopTraining() {
if (!confirm('Are you sure you want to stop training?')) return;
try {
const response = await fetch('/api/cloud-removal/training/stop', {
method: 'POST'
});
if (response.ok) {
addLog('warning', '⏹️ Stopping training...');
} else {
const error = await response.json();
alert('Error: ' + error.detail);
}
} catch (error) {
alert('Error: ' + error.message);
}
}
// Handle training form submission
document.getElementById('trainingForm').addEventListener('submit', async (e) => {
@@ -663,18 +1159,43 @@
const result = await response.json();
if (response.ok) {
// Reset tracking variables for new training
bestPSNRData = {
modelPSNR: 0,
epoch: 0,
trainLoss: 0,
valLoss: 0,
baselinePSNR: 0,
improvement: 0
};
worstPSNRData = {
modelPSNR: Infinity,
epoch: 0,
trainLoss: 0,
valLoss: 0,
baselinePSNR: 0,
improvement: 0
};
psnrHistory = [];
baselinePSNR = 0;
// Hide checkpoint cards at start
document.getElementById('bestPSNRCard').style.display = 'none';
document.getElementById('worstPSNRCard').style.display = 'none';
document.getElementById('performanceRangeCard').style.display = 'none';
// Show training status section
document.getElementById('trainingStatus').style.display = 'block';
document.getElementById('statusMessage').innerHTML = `
<div class="status-badge status-training">Training Started: ${result.training_id}</div>
<p style="margin-top: 10px;">Model training has started in background. This may take several hours.</p>
<div class="status-badge status-training">🚀 Training Started: ${result.training_id}</div>
<p style="margin-top: 10px;">Model training has started. Real-time metrics will appear below.</p>
`;
addLog('info', `Training started: ${result.training_id}`);
addLog('info', `Training started: ${result.training_id}`);
addLog('info', `Config: ${JSON.stringify(config, null, 2)}`);
// Simulate progress (actual progress would come from websocket)
simulateProgress();
// Start polling status
startStatusPolling();
} else {
alert('Error starting training: ' + (result.detail || result.error));
}
@@ -699,6 +1220,9 @@
<div class="model-info">📊 Epoch: ${model.epoch}</div>
<div class="model-info">📉 Train Loss: ${model.train_loss.toFixed(6)}</div>
<div class="model-info">📉 Val Loss: ${model.val_loss.toFixed(6)}</div>
${model.val_psnr ? `<div class="model-info">📈 Model PSNR: <strong>${model.val_psnr.toFixed(2)} dB</strong></div>` : ''}
${model.baseline_psnr ? `<div class="model-info">📉 Baseline PSNR: ${model.baseline_psnr.toFixed(2)} dB</div>` : ''}
${model.val_psnr && model.baseline_psnr ? `<div class="model-info">⚡ Improvement: <strong style="color: ${model.val_psnr > model.baseline_psnr ? 'green' : 'red'}">${(model.val_psnr - model.baseline_psnr > 0 ? '+' : '')}${(model.val_psnr - model.baseline_psnr).toFixed(2)} dB</strong></div>` : ''}
<div class="model-info">📡 Use S1: ${model.use_s1 ? 'Yes' : 'No'}</div>
<div class="model-info">💾 Size: ${model.size_mb.toFixed(2)} MB</div>
<div class="model-info">📅 Created: ${new Date(model.created * 1000).toLocaleString()}</div>
@@ -769,28 +1293,6 @@
logs.appendChild(entry);
logs.scrollTop = logs.scrollHeight;
}
// Simulate progress (replace with real progress tracking)
function simulateProgress() {
let progress = 0;
const interval = setInterval(() => {
progress += Math.random() * 5;
if (progress >= 100) {
progress = 100;
clearInterval(interval);
addLog('info', 'Training completed! Check models list below.');
setTimeout(refreshModels, 2000);
}
const progressBar = document.getElementById('progressBar');
progressBar.style.width = progress + '%';
progressBar.textContent = Math.floor(progress) + '%';
if (progress % 10 < 5) {
addLog('info', `Training progress: ${Math.floor(progress)}%`);
}
}, 3000);
}
</script>
</body>
</html>