update train file nam

This commit is contained in:
Victor Phan
2026-03-03 20:36:24 +07:00
parent 0a892c736a
commit 7574cec64d
14 changed files with 26 additions and 75 deletions
+3 -3
View File
@@ -854,8 +854,8 @@
"TRAINING DATA SETUP\n",
"======================================================================\n",
"\n",
"[1] Loading training data: train/ST_training data_updated_1130points_new.shp\n",
" ❌ Error: train/ST_training data_updated_1130points_new.shp: No such file or directory\n",
"[1] Loading training data: train/ST_training_data_updated_1130points_new.shp\n",
" ❌ Error: train/ST_training_data_updated_1130points_new.shp: No such file or directory\n",
"\n",
"[2] Label mapping:\n",
" 0: Lua tom\n",
@@ -878,7 +878,7 @@
"print(\"=\"*70)\n",
"\n",
"# Load training points\n",
"train_path = \"train/ST_training data_updated_1130points_new.shp\"\n",
"train_path = \"train/ST_training_data_updated_1130points_new.shp\"\n",
"print(f\"\\n[1] Loading training data: {train_path}\")\n",
"\n",
"try:\n",
+1 -1
View File
@@ -33,7 +33,7 @@ CACHE_DIR = "dataset_cache"
CACHE_FILE = f"{CACHE_DIR}/sentinel2_timeseries_40scenes.nc"
# --- Training data ---
TRAIN_PATH = "train/ST_training data_updated_1130points_new.shp"
TRAIN_PATH = "train/ST_training_data_updated_1130points_new.shp"
# --- Features sử dụng để train ---
AVAILABLE_FEATURES = [
+2 -2
View File
@@ -2854,7 +2854,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "d2585562-88aa-4c7d-bf70-1f6affcf65d4",
"metadata": {
"tags": []
@@ -2862,7 +2862,7 @@
"outputs": [],
"source": [
"## cấu hình bộ dữ liệu điểm huấn luyện mô hình (train file)\n",
"train_path = \"train/ST_training data_updated_1130points_new.shp\" # đường dẫn shp file train\n",
"train_path = \"train/ST_training_data_updated_1130points_new.shp\" # đường dẫn shp file train\n",
"\n",
"## load dữ liệu điểm huấn luyện mô hình (train file)\n",
"train = load_train_data(train_path)\n",
-49
View File
@@ -428,55 +428,6 @@
"plt.tight_layout()\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28f87d0e",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from datetime import datetime\n",
"\n",
"# ── Lưu mô hình PyTorch ────────────────────────────────────────────────────────\n",
"model_path = \"model_mobilenet_land_use.pth\"\n",
"torch.save(model.state_dict(), model_path)\n",
"print(f\"✅ Model saved → {model_path}\")\n",
"\n",
"# ── Lưu thông tin mô hình ──────────────────────────────────────────────────────\n",
"info = {\n",
" \"model_type\": \"MobileNetV3_LR-ASPP\",\n",
" \"n_features\": n_features,\n",
" \"n_classes\": n_classes,\n",
" \"learning_rate\": LEARNING_RATE,\n",
" \"batch_size\": BATCH_SIZE,\n",
" \"max_epochs\": N_EPOCHS,\n",
" \"early_stopping_patience\": PATIENCE,\n",
" \"optimizer\": \"Adam\",\n",
" \"scheduler\": \"ReduceLROnPlateau(factor=0.5, patience=5)\",\n",
" \"class_weight\": \"balanced\",\n",
" \"label_mapping\": label_mapping,\n",
" \"test_accuracy\": float(acc),\n",
" \"train_samples\": len(X_train_np),\n",
" \"val_samples\": len(X_val_np),\n",
" \"test_samples\": len(X_test_np),\n",
" \"saved_at\": datetime.now().isoformat(),\n",
"}\n",
"info_path = \"model_mobilenet_land_use_info.json\"\n",
"with open(info_path, \"w\") as f:\n",
" json.dump(info, f, indent=2, ensure_ascii=False)\n",
"print(f\"✅ Info saved → {info_path}\")\n",
"print(json.dumps(info, indent=2, ensure_ascii=False))\n",
"\n",
"# ── Đóng kết nối Dask ──────────────────────────────────────────────────────────\n",
"try:\n",
" client.close()\n",
" cluster.close()\n",
" print(\"✅ Dask cluster closed.\")\n",
"except Exception:\n",
" pass\n"
]
}
],
"metadata": {
+1 -1
View File
@@ -103,7 +103,7 @@
"outputs": [],
"source": [
"## Chuẩn bị dữ liệu train\n",
"train_path = \"train/ST_training data_updated_1130points_new.shp\"\n",
"train_path = \"train/ST_training_data_updated_1130points_new.shp\"\n",
"train = load_train_data(train_path)\n",
"train.head()\n",
"\n",
+1 -1
View File
@@ -140,7 +140,7 @@
"outputs": [],
"source": [
"## ── Chuẩn bị dữ liệu train ───────────────────────────────────────────────────\n",
"train_path = \"train/ST_training data_updated_1130points_new.shp\"\n",
"train_path = \"train/ST_training_data_updated_1130points_new.shp\"\n",
"\n",
"train = load_train_data(train_path)\n",
"train.head()\n",
+2 -2
View File
@@ -2854,7 +2854,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "d2585562-88aa-4c7d-bf70-1f6affcf65d4",
"metadata": {
"tags": []
@@ -2862,7 +2862,7 @@
"outputs": [],
"source": [
"## cấu hình bộ dữ liệu điểm huấn luyện mô hình (train file)\n",
"train_path = \"train/ST_training data_updated_1130points_new.shp\" # đường dẫn shp file train\n",
"train_path = \"train/ST_training_data_updated_1130points_new.shp\" # đường dẫn shp file train\n",
"\n",
"## load dữ liệu điểm huấn luyện mô hình (train file)\n",
"train = load_train_data(train_path)\n",
+2 -2
View File
@@ -1727,7 +1727,7 @@
"FEATURE EXTRACTION\n",
"======================================================================\n",
"\n",
"[1] Loading training data from: train/ST_training data_updated_1130points_new.shp\n",
"[1] Loading training data from: train/ST_training_data_updated_1130points_new.shp\n",
"✅ Loaded 1130 training points\n",
" Available columns: ['No', 'X', 'Y', 'LU2022', 'Hientrang', 'HT_code', 'geometry']\n",
" Using label column: 'HT_code'\n",
@@ -1769,7 +1769,7 @@
"# Load training shapefile\n",
"import geopandas as gpd\n",
"\n",
"train_path = 'train/ST_training data_updated_1130points_new.shp'\n",
"train_path = 'train/ST_training_data_updated_1130points_new.shp'\n",
"print(f\"\\n[1] Loading training data from: {train_path}\")\n",
"train_gdf = gpd.read_file(train_path)\n",
"\n",
+6 -6
View File
@@ -44,7 +44,7 @@ DEFAULT_LABEL_MAPPING = {
{
"files": [
{
"filename": "ST_training data_updated_1130points_new.shp",
"filename": "ST_training_data_updated_1130points_new.shp",
"path": "train/...",
"size_mb": 0.15,
"point_count": 1130,
@@ -110,7 +110,7 @@ DEFAULT_LABEL_MAPPING = {
Features:
- Dropdown chọn shapefile từ thư mục `/train`
- Tự động load default: `ST_training data_updated_1130points_new.shp`
- Tự động load default: `ST_training_data_updated_1130points_new.shp`
- Hiển thị thông tin: số điểm, label column, số lớp, bbox
#### ✅ Thêm phần hiển thị thông tin Shapefile:
@@ -149,7 +149,7 @@ Features:
#### ✅ Cập nhật form submission:
- Thêm `training_shapefile` vào config
- Default: `train/ST_training data_updated_1130points_new.shp`
- Default: `train/ST_training_data_updated_1130points_new.shp`
#### ✅ Event listeners:
```javascript
@@ -252,7 +252,7 @@ curl http://localhost:8000/api/training/files
curl http://localhost:8000/api/training/labels
# Get shapefile labels
curl "http://localhost:8000/api/training/shapefile/ST_training data_updated_1130points_new.shp/labels"
curl "http://localhost:8000/api/training/shapefile/ST_training_data_updated_1130points_new.shp/labels"
```
### Check Browser Console:
@@ -265,8 +265,8 @@ curl "http://localhost:8000/api/training/shapefile/ST_training data_updated_1130
## 📝 Notes
1. **Training shapefile path format**:
- Frontend select value: `ST_training data_updated_1130points_new.shp`
- Backend receives: `train/ST_training data_updated_1130points_new.shp`
- Frontend select value: `ST_training_data_updated_1130points_new.shp`
- Backend receives: `train/ST_training_data_updated_1130points_new.shp`
- Auto-prepend `train/` prefix in form submission
2. **Label mapping**:
+3 -3
View File
@@ -3807,7 +3807,7 @@ async def change_detection_predict_workflow(
# --- STEP 6: COMPARE WITH GROUND TRUTH ---
print("[CHANGE DETECTION] Comparing with ground truth...")
gt_shapefile = "train/ST_training data_updated_1130points_new.shp"
gt_shapefile = "train/ST_training_data_updated_1130points_new.shp"
gt_raster = rasterize_ground_truth(gt_shapefile, (height, width), bbox, class_column="class")
# Calculate changes
@@ -3912,7 +3912,7 @@ async def change_detection_workflow(request: ChangeDetectionWorkflowRequest):
pred_transform = pred_ds.transform
# Rasterize ground truth training data
gt_shapefile = "train/ST_training data_updated_1130points_new.shp"
gt_shapefile = "train/ST_training_data_updated_1130points_new.shp"
gt_raster = rasterize_ground_truth(gt_shapefile, pred_arr.shape, bbox, class_column="class")
# Calculate change detection
@@ -4700,7 +4700,7 @@ async def predict_with_ndvi(config: PredictionWithNDVIConfig, background_tasks:
change_map = None
try:
# Use training shapefile as ground truth
gt_shapefile = "train/ST_training data_updated_1130points_new.shp"
gt_shapefile = "train/ST_training_data_updated_1130points_new.shp"
gt_raster = rasterize_ground_truth(gt_shapefile, (height, width), bbox, class_column="class")
# Compare prediction and ground truth
mask_valid = (gt_raster >= 0) & (prediction_raster >= 0)
@@ -135,7 +135,7 @@ File .tif (mỗi pixel = 1 mã loại đất)
- **Tổng cộng**: ~39 features cho mỗi pixel
### Labels (Nhãn):
- Được lấy từ shapefile training: `train/ST_training data_updated_1130points_new.shp`
- Được lấy từ shapefile training: `train/ST_training_data_updated_1130points_new.shp`
- 1130 điểm mẫu đã được gắn nhãn thủ công bởi chuyên gia
---
+1 -1
View File
@@ -45,7 +45,7 @@ def test_training_files():
print(f"❌ Error: {response.status_code}")
print()
def test_shapefile_labels(filename="ST_training data_updated_1130points_new.shp"):
def test_shapefile_labels(filename="ST_training_data_updated_1130points_new.shp"):
"""Test /api/training/shapefile/{filename}/labels endpoint"""
print("=" * 70)
print(f"TEST 3: Getting labels from shapefile: {filename}")
+1 -1
View File
@@ -359,7 +359,7 @@ def train_model(
max_scenes=12,
cloud_cover=30,
resolution=20,
training_shapefile='train/ST_training data_updated_1130points_new.shp',
training_shapefile='train/ST_training_data_updated_1130points_new.shp',
model_type='xgboost',
n_estimators=100,
max_depth=20,
+2 -2
View File
@@ -804,7 +804,7 @@
});
// Select default shapefile
const defaultFile = 'ST_training data_updated_1130points_new.shp';
const defaultFile = 'ST_training_data_updated_1130points_new.shp';
const defaultOption = Array.from(select.options).find(opt => opt.value === defaultFile);
if (defaultOption) {
select.value = defaultFile;
@@ -1074,7 +1074,7 @@
// Get selected training shapefile
const selectedShapefile = document.getElementById('trainingShapefile').value;
const trainingShapefile = selectedShapefile || 'train/ST_training data_updated_1130points_new.shp';
const trainingShapefile = selectedShapefile || 'train/ST_training_data_updated_1130points_new.shp';
const config = {
min_lon: parseFloat(document.getElementById('minLon').value),