Train and test split on DFC2018
This commit is contained in:
parent
19d9b99091
commit
53b320fa60
196
Notebooks/DFC2018 Ground truth split train and validation.ipynb
Normal file
196
Notebooks/DFC2018 Ground truth split train and validation.ipynb
Normal file
@ -0,0 +1,196 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"# Triskele\n",
|
||||
"import sys\n",
|
||||
"from pathlib import Path\n",
|
||||
"triskele_path = Path('../triskele/python/')\n",
|
||||
"sys.path.append(str(triskele_path.resolve()))\n",
|
||||
"import triskele"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fs = np.array([16,3]) * 2 # Figure Size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Load ground truth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gt = triskele.read('../Data/ground_truth/2018_IEEE_GRSS_DFC_GT_TR.tif')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.figure(figsize=fs)\n",
|
||||
"plt.imshow(gt)\n",
|
||||
"plt.colorbar()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"count = np.unique(gt, return_counts=True)\n",
|
||||
"lbl = pd.read_csv('../Data/ground_truth/labels.csv', header=None, names=['Label'], index_col=0)\n",
|
||||
"lbl['Count'] = count[1]\n",
|
||||
"lbl"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.bar(*count, log=True)\n",
|
||||
"plt.xticks(lbl.index.values,lbl['Label'], rotation=90)\n",
|
||||
"plt.show()\n",
|
||||
"\n",
|
||||
"plt.bar(count[0][1:], count[1][1:])\n",
|
||||
"plt.xticks(lbl.index.values[1:], lbl['Label'][1:], rotation=90)\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Split data\n",
|
||||
"\n",
|
||||
"Create a filter raster `split` with values:\n",
|
||||
"\n",
|
||||
"- `0` No Data\n",
|
||||
"- `1` Train\n",
|
||||
"- `2` Test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"train_part = .7\n",
|
||||
"\n",
|
||||
"split = np.zeros_like(gt)\n",
|
||||
"\n",
|
||||
"for lbl, lblc in zip(count[0][1:], count[1][1:]):\n",
|
||||
" treshold = int(lblc * train_part)\n",
|
||||
" #print('lbl:{}, count:{}, train:{}'.format(lbl, lblc, treshold))\n",
|
||||
" f = np.nonzero(gt == lbl)\n",
|
||||
" split[f[0][:treshold], f[1][:treshold]] = 1\n",
|
||||
" split[f[0][treshold:], f[1][treshold:]] = 2\n",
|
||||
" \n",
|
||||
"plt.figure(figsize=fs)\n",
|
||||
"plt.imshow(split)\n",
|
||||
"#plt.imshow(split * (gt==1))\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Metaclasses "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"metaclasses_A = {'Grass': [1, 2, 3],\n",
|
||||
" 'Trees': [4, 5],\n",
|
||||
" 'Hard Ground': [6, 17],\n",
|
||||
" 'Water': [7],\n",
|
||||
" 'Buildings': [8, 9],\n",
|
||||
" 'Roads': [10, 11, 12, 13, 14, 16],\n",
|
||||
" 'Railways': [15],\n",
|
||||
" 'Cars': [18],\n",
|
||||
" 'Trains': [19],\n",
|
||||
" 'Stadium': [20]}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.figure(figsize=fs)\n",
|
||||
"plt.imshow(np.isin(gt, metaclasses_A['Roads']))\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.figure(figsize=fs)\n",
|
||||
"plt.imshow(gt * np.isin(gt, [10, 11]))#metaclasses_A['Roads']))\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"~~on~~"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
Loading…
Reference in New Issue
Block a user