hoàn thành chức năng remove cloud train
This commit is contained in:
@@ -0,0 +1,605 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="vi">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cloud Removal Training - Deep Learning</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.nav {
|
||||
background: #f8f9fa;
|
||||
padding: 15px 30px;
|
||||
border-bottom: 2px solid #e9ecef;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
color: #667eea;
|
||||
text-decoration: none;
|
||||
margin-right: 20px;
|
||||
font-weight: 500;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
color: #764ba2;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 1.5em;
|
||||
color: #333;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 3px solid #667eea;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
border-left: 4px solid #667eea;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="number"],
|
||||
select {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
font-size: 1em;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
input[type="text"]:focus,
|
||||
input[type="number"]:focus,
|
||||
select:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px 30px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.model-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.model-card {
|
||||
background: white;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.model-card:hover {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.model-card h3 {
|
||||
color: #667eea;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.model-info {
|
||||
font-size: 0.9em;
|
||||
color: #6c757d;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 5px 15px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.status-training {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
height: 30px;
|
||||
background: #e9ecef;
|
||||
border-radius: 15px;
|
||||
overflow: hidden;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
|
||||
transition: width 0.3s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background: #e7f3ff;
|
||||
border-left: 4px solid #2196F3;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: #fff3cd;
|
||||
border-left: 4px solid #ffc107;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.grid-2 {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.grid-2 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.model-list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.logs {
|
||||
background: #1e1e1e;
|
||||
color: #d4d4d4;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9em;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.logs .log-entry {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.logs .log-info {
|
||||
color: #4ec9b0;
|
||||
}
|
||||
|
||||
.logs .log-warning {
|
||||
color: #dcdcaa;
|
||||
}
|
||||
|
||||
.logs .log-error {
|
||||
color: #f48771;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🌥️ Cloud Removal Training</h1>
|
||||
<p>Train Deep Learning Models để khử mây từ ảnh Sentinel-2</p>
|
||||
</div>
|
||||
|
||||
<div class="nav">
|
||||
<a href="/">← Trang chủ</a>
|
||||
<a href="/training">Land Classification</a>
|
||||
<a href="/prediction">Prediction</a>
|
||||
<a href="#models">Models đã train</a>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<!-- Info Section -->
|
||||
<div class="section">
|
||||
<div class="info-box">
|
||||
<strong>📚 Dataset:</strong> SEN12MS-CR (Sentinel-12 Multi-Seasonal Cloud Removal)<br>
|
||||
<strong>🏗️ Architecture:</strong> U-Net với skip connections<br>
|
||||
<strong>📊 Input:</strong> S2 cloudy (4 bands) + S1 radar (2 bands) = 6 channels<br>
|
||||
<strong>🎯 Output:</strong> S2 clean (4 bands)<br>
|
||||
<strong>⏱️ Training time:</strong> ~2-3 hours (GPU) / ~20-30 hours (CPU)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Training Configuration -->
|
||||
<div class="section">
|
||||
<h2 class="section-title">⚙️ Cấu hình Training</h2>
|
||||
|
||||
<div class="card">
|
||||
<form id="trainingForm">
|
||||
<div class="grid-2">
|
||||
<div class="form-group">
|
||||
<label>📂 Data Directory</label>
|
||||
<input type="text" id="dataDir" value="winter_dataset" required>
|
||||
<small style="color: #6c757d;">Thư mục chứa dữ liệu SEN12MS-CR</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>🏷️ Model Name</label>
|
||||
<input type="text" id="modelName" value="cloud_removal_unet" required>
|
||||
<small style="color: #6c757d;">Tên model để lưu</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>📦 Batch Size</label>
|
||||
<input type="number" id="batchSize" value="8" min="1" max="32" required>
|
||||
<small style="color: #6c757d;">Giảm xuống 4 hoặc 2 nếu GPU hết RAM</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>🔄 Number of Epochs</label>
|
||||
<input type="number" id="numEpochs" value="50" min="1" max="200" required>
|
||||
<small style="color: #6c757d;">Số lượng epochs training</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>📈 Learning Rate</label>
|
||||
<input type="number" id="learningRate" value="0.0001" step="0.00001" min="0.00001" max="0.01" required>
|
||||
<small style="color: #6c757d;">Learning rate (default: 1e-4)</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="useS1" checked>
|
||||
<label for="useS1">📡 Use Sentinel-1 (Radar Data)</label>
|
||||
</div>
|
||||
<small style="color: #6c757d;">Sử dụng dữ liệu radar (VV, VH) để cải thiện kết quả</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="useGPU" checked>
|
||||
<label for="useGPU">🚀 Use GPU</label>
|
||||
</div>
|
||||
<small style="color: #6c757d;">Sử dụng GPU để training nhanh hơn</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 20px;">
|
||||
<button type="submit" class="btn btn-primary">🚀 Start Training</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="refreshModels()">🔄 Refresh Models</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Training Status -->
|
||||
<div class="section" id="trainingStatus" style="display: none;">
|
||||
<h2 class="section-title">📊 Training Status</h2>
|
||||
<div class="card">
|
||||
<div id="statusMessage"></div>
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill" id="progressBar" style="width: 0%;">0%</div>
|
||||
</div>
|
||||
<div class="logs" id="trainingLogs">
|
||||
<div class="log-entry log-info">Training logs will appear here...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Models List -->
|
||||
<div class="section" id="models">
|
||||
<h2 class="section-title">🤖 Cloud Removal Models</h2>
|
||||
<div class="model-list" id="modelsList">
|
||||
<div class="model-card">
|
||||
<p style="text-align: center; color: #6c757d;">Loading models...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Methods Info -->
|
||||
<div class="section">
|
||||
<h2 class="section-title">📖 Cloud Removal Methods</h2>
|
||||
<div class="grid-2">
|
||||
<div class="card">
|
||||
<h3>🔹 Classic (Default)</h3>
|
||||
<p>3-step approach: temporal → median → spatial interpolation</p>
|
||||
<div class="status-badge status-success">Fast</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3>🔹 Hybrid</h3>
|
||||
<p>Classical + ML KNN - balanced speed & quality</p>
|
||||
<div class="status-badge status-success">Recommended</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3>🔹 ML KNN</h3>
|
||||
<p>K-Nearest Neighbors inpainting - good quality</p>
|
||||
<div class="status-badge status-training">Medium Speed</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3>🔹 Deep Learning</h3>
|
||||
<p>U-Net CNN - best quality for large gaps</p>
|
||||
<div class="status-badge status-error">Requires Model</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Load models on page load
|
||||
window.addEventListener('load', () => {
|
||||
refreshModels();
|
||||
loadCloudRemovalMethods();
|
||||
});
|
||||
|
||||
// Handle training form submission
|
||||
document.getElementById('trainingForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const config = {
|
||||
data_dir: document.getElementById('dataDir').value,
|
||||
model_name: document.getElementById('modelName').value,
|
||||
use_s1: document.getElementById('useS1').checked,
|
||||
batch_size: parseInt(document.getElementById('batchSize').value),
|
||||
num_epochs: parseInt(document.getElementById('numEpochs').value),
|
||||
learning_rate: parseFloat(document.getElementById('learningRate').value),
|
||||
use_gpu: document.getElementById('useGPU').checked
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/cloud-removal/train', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
// 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>
|
||||
`;
|
||||
|
||||
addLog('info', `Training started: ${result.training_id}`);
|
||||
addLog('info', `Config: ${JSON.stringify(config, null, 2)}`);
|
||||
|
||||
// Simulate progress (actual progress would come from websocket)
|
||||
simulateProgress();
|
||||
} else {
|
||||
alert('Error starting training: ' + (result.detail || result.error));
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error: ' + error.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Refresh models list
|
||||
async function refreshModels() {
|
||||
try {
|
||||
const response = await fetch('/api/cloud-removal/models');
|
||||
const data = await response.json();
|
||||
|
||||
const modelsList = document.getElementById('modelsList');
|
||||
|
||||
if (data.models && data.models.length > 0) {
|
||||
modelsList.innerHTML = data.models.map(model => `
|
||||
<div class="model-card">
|
||||
<h3>📦 ${model.filename}</h3>
|
||||
<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>
|
||||
<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>
|
||||
<div style="margin-top: 15px;">
|
||||
<button class="btn btn-danger" onclick="deleteModel('${model.filename}')">
|
||||
🗑️ Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
} else {
|
||||
modelsList.innerHTML = `
|
||||
<div class="model-card">
|
||||
<p style="text-align: center; color: #6c757d;">
|
||||
No cloud removal models found.<br>
|
||||
Train your first model above!
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading models:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete model
|
||||
async function deleteModel(filename) {
|
||||
if (!confirm(`Delete model ${filename}?`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/cloud-removal/models/${filename}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Model deleted successfully');
|
||||
refreshModels();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert('Error deleting model: ' + error.detail);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Load cloud removal methods
|
||||
async function loadCloudRemovalMethods() {
|
||||
try {
|
||||
const response = await fetch('/api/cloud-removal/methods');
|
||||
const data = await response.json();
|
||||
console.log('Available cloud removal methods:', data.methods);
|
||||
} catch (error) {
|
||||
console.error('Error loading methods:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Add log entry
|
||||
function addLog(type, message) {
|
||||
const logs = document.getElementById('trainingLogs');
|
||||
const timestamp = new Date().toLocaleTimeString();
|
||||
const logClass = type === 'error' ? 'log-error' : (type === 'warning' ? 'log-warning' : 'log-info');
|
||||
|
||||
const entry = document.createElement('div');
|
||||
entry.className = `log-entry ${logClass}`;
|
||||
entry.textContent = `[${timestamp}] ${message}`;
|
||||
|
||||
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>
|
||||
Reference in New Issue
Block a user