Cập nhật mã nguồn và file Colab Cache

This commit is contained in:
2026-07-16 19:32:43 +07:00
parent 25969cb0f5
commit a258db54cd
69 changed files with 3377 additions and 645 deletions
+117
View File
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Script Tải Dữ liệu Vệ tinh (Cache) qua Google Colab\n",
"Mục đích của Notebook này là mượn sức mạnh đường truyền và RAM của Google Colab để tải 270 ảnh Sentinel-2 & Sentinel-1 từ Microsoft Planetary Computer. Sau khi xử lý nội suy, nó sẽ sinh ra một file cache `.joblib` duy nhất chứa toàn bộ mảng dữ liệu. \n",
"Bạn chỉ cần tải file `.joblib` đó về máy là xong!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install planetary-computer pystac-client odc-stac geopandas rasterio xarray joblib scikit-learn xgboost lightgbm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hướng dẫn:\n",
"1. Nén toàn bộ thư mục `remote-sensing` ở máy tính của bạn thành file `remote-sensing.zip`.\n",
"2. Upload file `remote-sensing.zip` đó lên Google Drive (để ngay ngoài cùng, ngang hàng với thư mục MyDrive).\n",
"3. Chạy ô lệnh bên dưới để giải nén và chuyển vào thư mục dự án."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"# Giải nén dự án từ Google Drive\n",
"!unzip -q -o /content/drive/MyDrive/remote-sensing.zip -d /content/\n",
"os.chdir('/content/remote-sensing')\n",
"!ls -la"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bắt đầu tải và Cache Dữ Liệu\n",
"Chạy một mô hình CPU đơn giản (Decision Tree) để ép hệ thống gọi hàm `FeatureExtractor`. Hàm này sẽ làm mọi việc nặng nhọc: tìm ảnh, ghép mây, tính trung vị và lưu kết quả vào thư mục `dataset_cache/`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Lệnh này sẽ mất khoảng 5-15 phút để tải toàn bộ ảnh từ Microsoft\n",
"!python train_land_decision_tree_gpu.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hoàn tất\n",
"Bạn hãy kiểm tra xem file `.joblib` lớn (khoảng 40-60MB) đã xuất hiện chưa. Nếu rồi, hãy lưu ngược nó lại Google Drive để tải về máy!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Xem file cache đã được tạo thành công chưa\n",
"!ls -lh dataset_cache/\n",
"\n",
"# Copy toàn bộ thư mục cache sang Google Drive để tải về máy dễ dàng\n",
"!cp -r dataset_cache/ /content/drive/MyDrive/dataset_cache_finished/\n",
"print(\"Hoàn thành! Bạn hãy mở Google Drive của mình, tìm thư mục 'dataset_cache_finished' và tải file .joblib mới nhất về máy tính.\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}