Merge pull request #3 from CTU-CSIRO/add_caculate_accuracy

add caculate accuracy
This commit is contained in:
CTU-CSIRO
2024-08-30 07:53:12 +07:00
committed by GitHub
9 changed files with 216 additions and 161 deletions
+25 -78
View File
@@ -3279,6 +3279,17 @@
"progress(average_ndvi)" "progress(average_ndvi)"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "6be55b09-44d9-4957-a2d9-00f1c58d0aee",
"metadata": {},
"outputs": [],
"source": [
"# compute average_ndvi\n",
"average_ndvi = average_ndvi.compute()"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 10,
@@ -3394,73 +3405,19 @@
} }
], ],
"source": [ "source": [
"# compute average_ndvi\n", "## cấu hình dữ liệu vh vv file\n",
"average_ndvi = average_ndvi.compute()\n",
"\n",
"## cấu hình dữ liệu train và vh vv file\n",
"train_path = \"train/ST_training data_updated_1130points.shp\" # đường dẫn shp file train\n",
"name_vh = \"vh-0922_0923-full_ST.tif\"\n", "name_vh = \"vh-0922_0923-full_ST.tif\"\n",
"name_vv = \"vv-0922_0923-full_ST.tif\"\n", "name_vv = \"vv-0922_0923-full_ST.tif\"\n",
"\n", "\n",
"## load dữ liệu điểm train\n",
"train = load_train_data(train_path)\n",
"train.head()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b32cfb3f-e267-4995-853d-8e0e26f5501f",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 527 µs, sys: 111 µs, total: 638 µs\n",
"Wall time: 375 µs\n"
]
}
],
"source": [
"%%time\n", "%%time\n",
"## tải về dữ liệu sen1\n", "## tải về dữ liệu sen1\n",
"import os\n",
"if not os.path.exists(name_vh):\n", "if not os.path.exists(name_vh):\n",
" !aws s3 cp s3://easi-asia-dc-data/staging/ctu/sentinel-1/vh-0922_0923-full_ST.tif vh-0922_0923-full_ST.tif\n", " !aws s3 cp s3://easi-asia-dc-data/staging/ctu/sentinel-1/vh-0922_0923-full_ST.tif vh-0922_0923-full_ST.tif\n",
"if not os.path.exists(name_vv):\n", "if not os.path.exists(name_vv):\n",
" !aws s3 cp s3://easi-asia-dc-data/staging/ctu/sentinel-1/vv-0922_0923-full_ST.tif vv-0922_0923-full_ST.tif" " !aws s3 cp s3://easi-asia-dc-data/staging/ctu/sentinel-1/vv-0922_0923-full_ST.tif vv-0922_0923-full_ST.tif\n",
] " \n",
},
{
"cell_type": "code",
"execution_count": 12,
"id": "9838697a-2260-45ef-a810-533428a783e9",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning 1: TIFFReadDirectory:Invalid data type for tag StripByteCounts\n",
"Warning 1: TIFFFetchNormalTag:ASCII value for tag \"GeoASCIIParams\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations\n",
"Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.\n",
"Warning 1: TIFFReadDirectory:Invalid data type for tag StripByteCounts\n",
"Warning 1: TIFFFetchNormalTag:ASCII value for tag \"GeoASCIIParams\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations\n",
"Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.\n"
]
}
],
"source": [
"# load dữ liệu sen1\n", "# load dữ liệu sen1\n",
"dsvh, dsvv = load_sen1(name_vh, name_vv)\n", "dsvh, dsvv = load_sen1(name_vh, name_vv)"
"\n",
"# xây dựng tập dataset\n",
"datasets = get_data_sen1_and_sen2(train, average_ndvi, dsvh, dsvv)"
] ]
}, },
{ {
@@ -3472,6 +3429,11 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"## load dữ liệu điểm train\n",
"train_path = \"train/ST_training data_updated_1130points.shp\" # đường dẫn shp file train\n",
"train = load_train_data(train_path)\n",
"train.head()\n",
"\n",
"# cấu hình nhãn dữ liệu\n", "# cấu hình nhãn dữ liệu\n",
"label_mapping = {\n", "label_mapping = {\n",
" \"Lua tom\": \"0\",\n", " \"Lua tom\": \"0\",\n",
@@ -3484,6 +3446,9 @@
" \"Rung\": \"7\"\n", " \"Rung\": \"7\"\n",
"}\n", "}\n",
"\n", "\n",
"# xây dựng tập dataset\n",
"datasets = get_data_sen1_and_sen2(train, average_ndvi, dsvh, dsvv)\n",
"\n",
"# chia tập dữ liệu train, val, test\n", "# chia tập dữ liệu train, val, test\n",
"X_train, X_val, X_test, y_train, y_val, y_test = split_train_data(train, label_mapping, datasets)" "X_train, X_val, X_test, y_train, y_val, y_test = split_train_data(train, label_mapping, datasets)"
] ]
@@ -3530,26 +3495,8 @@
"# kiểm tra độ chính xác với tập test\n", "# kiểm tra độ chính xác với tập test\n",
"y_pred_test = grid_search.predict(X_test)\n", "y_pred_test = grid_search.predict(X_test)\n",
"test_accuracy = accuracy_score(y_test, y_pred_test)\n", "test_accuracy = accuracy_score(y_test, y_pred_test)\n",
"print(f\"Accuracy for test data {round(test_accuracy, 2)*100} %\")" "print(f\"Accuracy for test data {round(test_accuracy, 2)*100} %\")\n",
] "\n",
},
{
"cell_type": "code",
"execution_count": 16,
"id": "f1a14379-ed6e-4897-9ca4-2669743fab40",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done!\n"
]
}
],
"source": [
"# Lưu mô hình huấn luyện\n", "# Lưu mô hình huấn luyện\n",
"save_model(\"model.joblib\", grid_search)" "save_model(\"model.joblib\", grid_search)"
] ]
+110 -82
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
UTF-8
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
PROJCS["WGS_1984_UTM_Zone_48N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",105.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
+44
View File
@@ -0,0 +1,44 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="3.30.0-'s-Hertogenbosch">
<identifier></identifier>
<parentidentifier></parentidentifier>
<language></language>
<type>dataset</type>
<title></title>
<abstract></abstract>
<contact>
<name></name>
<organization></organization>
<position></position>
<voice></voice>
<fax></fax>
<email></email>
<role></role>
</contact>
<links/>
<dates/>
<fees></fees>
<encoding></encoding>
<crs>
<spatialrefsys nativeFormat="Wkt">
<wkt>PROJCRS["WGS 84 / UTM zone 48N",BASEGEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],MEMBER["World Geodetic System 1984 (G2139)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4326]],CONVERSION["UTM zone 48N",METHOD["Transverse Mercator",ID["EPSG",9807]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",105,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["Scale factor at natural origin",0.9996,SCALEUNIT["unity",1],ID["EPSG",8805]],PARAMETER["False easting",500000,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Engineering survey, topographic mapping."],AREA["Between 102°E and 108°E, northern hemisphere between equator and 84°N, onshore and offshore. Cambodia. China. Indonesia. Laos. Malaysia - West Malaysia. Mongolia. Russian Federation. Singapore. Thailand. Vietnam."],BBOX[0,102,84,108]],ID["EPSG",32648]]</wkt>
<proj4>+proj=utm +zone=48 +datum=WGS84 +units=m +no_defs</proj4>
<srsid>3132</srsid>
<srid>32648</srid>
<authid>EPSG:32648</authid>
<description>WGS 84 / UTM zone 48N</description>
<projectionacronym>utm</projectionacronym>
<ellipsoidacronym>EPSG:7030</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</crs>
<extent>
<spatial miny="0" minz="0" maxz="0" crs="EPSG:32648" minx="0" maxy="0" dimensions="2" maxx="0"/>
<temporal>
<period>
<start></start>
<end></end>
</period>
</temporal>
</extent>
</qgis>
Binary file not shown.
Binary file not shown.
+35 -1
View File
@@ -317,4 +317,38 @@ def save_result(result, HT_MAP):
# cbar.ax.set_yticklabels(labels) # cbar.ax.set_yticklabels(labels)
# plt.title(f'{HT_MAP[k]["name"]}') # plt.title(f'{HT_MAP[k]["name"]}')
# plt.axis('off') # plt.axis('off')
# plt.show() # plt.show()
def accuracy_test(test, data_array):
# cấu hình nhãn dữ liệu
label_mapping = {
"Lua tom": "0",
"Lua": "1",
"CHN": "2",
"CLN": "3",
"TS": "4",
"Song": "5",
"Dat xay dung": "6",
"Rung": "7"
}
chk = []
pred = []
dd = []
for idx, point in test.iterrows():
label = point.LULC
predict = data_array.sel(x=point.geometry.x, y=point.geometry.y, method='nearest').values
pred.append(label_mapping[label])
dd.append(str(predict))
chk.append(predict == int(label_mapping[label]))
test["code"] = pred
test["dd"] = dd
test["check"] = chk
path = "ThuanHoa/TestAccuracy"
if not os.path.exists(path):
os.mkdir(path)
test.to_file(f"{path}/result.shp")
percentage_true = np.mean(chk) * 100
print(f"độ chính xác: {percentage_true:.2f}%")