Skip to content

Commit

Permalink
Updating pointnet_test, processing_data_2
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmaral committed Dec 23, 2024
1 parent 52b0cbb commit aef744b
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 470 deletions.
151 changes: 123 additions & 28 deletions segmentation/pointnet_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Implementación PointNet en Keras, Tensorflow 2.0"
"# Implementación PointNet en Keras, Tensorflow 2.0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lectura y preparación del conjunto de datos"
]
},
{
Expand All @@ -27,16 +34,32 @@
"from sklearn.model_selection import train_test_split\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Cargar y Leer archivos _.csv_ de cada subconjunto"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"path_x_train = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/x_train/\"\n",
"path_y_train = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/y_train/\"\n",
"path_x_val = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/x_val/\"\n",
"path_y_val = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/y_val/\"\n",
"# Linux\n",
"\n",
"#path_x_train = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/x_train/\"\n",
"#path_y_train = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/y_train/\"\n",
"#path_x_val = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/x_val/\"\n",
"#path_y_val = \"/home/felix/Escritorio/TFG/datasets_norm/goose_norm_test/y_val/\"\n",
"\n",
"# MacOS\n",
"\n",
"path_x_train = \"/Users/felixmaral/Desktop/TFG/dataset_norm/goose_teesting/x_train/\"\n",
"path_y_train = \"/Users/felixmaral/Desktop/TFG/dataset_norm/goose_teesting/y_train/\"\n",
"path_x_val = \"/Users/felixmaral/Desktop/TFG/dataset_norm/goose_teesting/x_val/\"\n",
"path_y_val = \"/Users/felixmaral/Desktop/TFG/dataset_norm/goose_teesting/y_val/\"\n",
"\n",
"file_list_x_train = sorted(os.listdir(path_x_train))\n",
"file_list_y_train = sorted(os.listdir(path_y_train))\n",
Expand All @@ -49,47 +72,119 @@
"Y_val = []\n",
"\n",
"for file in file_list_x_train:\n",
" df = pd.read_csv(path_x_train+file)\n",
" X_train.append(df)\n",
" df_x_train = pd.read_csv(path_x_train+file)\n",
" X_train.append(df_x_train)\n",
"\n",
"for file in file_list_y_train:\n",
" df['sem_label'] = pd.read_csv(path_y_train+file)\n",
" Y_train.append(df)\n",
" df_y_train = pd.DataFrame()\n",
" df_y_train['sem_label'] = pd.read_csv(path_y_train+file)\n",
" Y_train.append(df_y_train)\n",
"\n",
"for file in file_list_x_val:\n",
" df = pd.read_csv(path_x_val+file)\n",
" X_val.append(df)\n",
" df_x_val = pd.read_csv(path_x_val+file)\n",
" X_val.append(df_x_val)\n",
"\n",
"for file in file_list_y_val:\n",
" df['sem_label'] = pd.read_csv(path_y_val+file)\n",
" Y_val.append(df)"
" df_y_val = pd.DataFrame()\n",
" df_y_val['sem_label'] = pd.read_csv(path_y_val+file)\n",
" Y_val.append(df_y_val)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[50 41 51 59 17 38 23 31 4 8 47 0 55 45]\n",
"[50 59 51 27 17 41 8 28 4 31 0]\n"
]
}
],
"outputs": [],
"source": [
"# Estudio de clases\n",
"\n",
"Y_train_concat = pd.concat(Y_train)\n",
"Y_val_concat = pd.concat(Y_val)\n",
"Y_concat = pd.concat(([pd.DataFrame(Y_train_concat), pd.DataFrame(Y_val_concat)]))\n",
"\n",
"clases_unicas_train = Y_train_concat['sem_label'].unique()\n",
"clases_unicas_val = Y_val_concat['sem_label'].unique()\n",
"clases_unicas = set([int(x) for x in np.concatenate((clases_unicas_train, clases_unicas_val))])\n",
"\n",
"print(\"Clases definidas en el conjunto de entrenamiento: \", clases_unicas_train)\n",
"print(\"\\nClases definidas en el conjunto de validación: \",clases_unicas_val)\n",
"print(\"\\nClases definidas en el conjunto de datos: \",clases_unicas)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Calcula las clases faltantes en Xtrain\n",
"clases_faltantes_train = list(set(clases_unicas_train) - set(clases_unicas_val))\n",
"clases_unicas_df = np.concatenate((clases_unicas_train, clases_faltantes_train))\n",
"\n",
"# Calcula las clases existentes en el conjunto de datos\n",
"clases_unicas_df = sorted(set(clases_unicas_df))\n",
"\n",
"print(\"En el conjunto de datos hay: \", len(clases_unicas), \"clases únicas\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Histograma de frecuencia de clases\n",
"\n",
"from matplotlib.ticker import FuncFormatter\n",
"\n",
"# Crear el histograma\n",
"plt.figure(figsize=(16, 6))\n",
"plt.style.use('ggplot')\n",
"plt.hist(Y_concat['sem_label'], \n",
" bins=np.arange(Y_concat['sem_label'].min(), Y_concat['sem_label'].max() + 2), \n",
" edgecolor='k', \n",
" alpha=1, \n",
" align='mid')\n",
"\n",
"# Chatgpt code\n",
"# Configurar el formateador para el eje Y\n",
"#ax = plt.gca()\n",
"#formatter = FuncFormatter(lambda x, _: f\"{int(x):,}\") # Formato con separadores de miles\n",
"#ax.yaxis.set_major_formatter(formatter) # Aplicar el formateador\n",
"\n",
"# Personalización del gráfico\n",
"plt.title(\"Histograma de Etiquetas Semánticas\", pad=20)\n",
"plt.xlabel(\"Etiqueta Semántica\", labelpad=10)\n",
"plt.ylabel(\"Frecuencia\", labelpad=10)\n",
"plt.grid(axis='y', linestyle='--', alpha=0.7)\n",
"\n",
"# Configurar las marcas del eje X en incrementos de 1\n",
"x_ticks = np.arange(Y_concat['sem_label'].min(), Y_concat['sem_label'].max() + 2, 1)\n",
"plt.xticks(x_ticks, fontsize=8)\n",
"\n",
"# Ajustar padding de los x_ticks\n",
"plt.gca().tick_params(axis='x', pad=10) # Aumenta el espacio entre los ticks y el eje\n",
"\n",
"# Mostrar el gráfico\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Clases que faltan en el conjunto de datos\n",
"\n",
"GOOSE_CLASSES = [i for i in range(0, 64)]\n",
"\n",
"# Calcular clases faltantes\n",
"\n",
"clases_faltantes = [i for i in GOOSE_CLASSES if i not in clases_unicas]\n",
"\n",
"print(clases_unicas_train)\n",
"print(clases_unicas_val)\n"
"print(f\"Hay {len(clases_faltantes)} clases que no están representadas en este conjunto de datos: \")\n",
"print(clases_faltantes)\n"
]
},
{
Expand All @@ -102,7 +197,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "usr",
"display_name": "tfg",
"language": "python",
"name": "python3"
},
Expand Down
Loading

0 comments on commit aef744b

Please sign in to comment.