From bc0fa746f961f5137620d34b4d6d506d3d94b097 Mon Sep 17 00:00:00 2001 From: Eduardo Bezerra Date: Thu, 23 Jan 2025 18:25:59 -0300 Subject: [PATCH] Add gitignore --- .gitignore | 5 + notebooks/read_data.ipynb | 186 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 .gitignore create mode 100644 notebooks/read_data.ipynb diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..fb925bce6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +temp/IPqM-Fall.zip +temp/12760391.zip +labels_and_data/ +database/ +builders/__pycache__/ diff --git a/notebooks/read_data.ipynb b/notebooks/read_data.ipynb new file mode 100644 index 000000000..3264fe130 --- /dev/null +++ b/notebooks/read_data.ipynb @@ -0,0 +1,186 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "sys.path.insert(1, '..')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting scikit-learn\n", + " Downloading scikit_learn-1.6.1-cp311-cp311-macosx_10_9_x86_64.whl.metadata (31 kB)\n", + "Requirement already satisfied: numpy>=1.19.5 in /Users/ebezerra/miniconda3/envs/falldetect/lib/python3.11/site-packages (from scikit-learn) (1.23.5)\n", + "Requirement already satisfied: scipy>=1.6.0 in /Users/ebezerra/miniconda3/envs/falldetect/lib/python3.11/site-packages (from scikit-learn) (1.13.0)\n", + "Collecting joblib>=1.2.0 (from scikit-learn)\n", + " Using cached joblib-1.4.2-py3-none-any.whl.metadata (5.4 kB)\n", + "Collecting threadpoolctl>=3.1.0 (from scikit-learn)\n", + " Using cached threadpoolctl-3.5.0-py3-none-any.whl.metadata (13 kB)\n", + "Downloading scikit_learn-1.6.1-cp311-cp311-macosx_10_9_x86_64.whl (12.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.1/12.1 MB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hUsing cached joblib-1.4.2-py3-none-any.whl (301 kB)\n", + "Using cached threadpoolctl-3.5.0-py3-none-any.whl (18 kB)\n", + "Installing collected packages: threadpoolctl, joblib, scikit-learn\n", + "Successfully installed joblib-1.4.2 scikit-learn-1.6.1 threadpoolctl-3.5.0\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "#pip install scikit-learn" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting matplotlib\n", + " Downloading matplotlib-3.10.0-cp311-cp311-macosx_10_12_x86_64.whl.metadata (11 kB)\n", + "Collecting contourpy>=1.0.1 (from matplotlib)\n", + " Downloading contourpy-1.3.1-cp311-cp311-macosx_10_9_x86_64.whl.metadata (5.4 kB)\n", + "Collecting cycler>=0.10 (from matplotlib)\n", + " Using cached cycler-0.12.1-py3-none-any.whl.metadata (3.8 kB)\n", + "Collecting fonttools>=4.22.0 (from matplotlib)\n", + " Downloading fonttools-4.55.5-cp311-cp311-macosx_10_9_x86_64.whl.metadata (165 kB)\n", + "Collecting kiwisolver>=1.3.1 (from matplotlib)\n", + " Downloading kiwisolver-1.4.8-cp311-cp311-macosx_10_9_x86_64.whl.metadata (6.2 kB)\n", + "Requirement already satisfied: numpy>=1.23 in /Users/ebezerra/miniconda3/envs/falldetect/lib/python3.11/site-packages (from matplotlib) (1.23.5)\n", + "Requirement already satisfied: packaging>=20.0 in /Users/ebezerra/miniconda3/envs/falldetect/lib/python3.11/site-packages (from matplotlib) (24.1)\n", + "Collecting pillow>=8 (from matplotlib)\n", + " Downloading pillow-11.1.0-cp311-cp311-macosx_10_10_x86_64.whl.metadata (9.1 kB)\n", + "Collecting pyparsing>=2.3.1 (from matplotlib)\n", + " Downloading pyparsing-3.2.1-py3-none-any.whl.metadata (5.0 kB)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /Users/ebezerra/miniconda3/envs/falldetect/lib/python3.11/site-packages (from matplotlib) (2.9.0.post0)\n", + "Requirement already satisfied: six>=1.5 in /Users/ebezerra/miniconda3/envs/falldetect/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)\n", + "Downloading matplotlib-3.10.0-cp311-cp311-macosx_10_12_x86_64.whl (8.2 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m8.2/8.2 MB\u001b[0m \u001b[31m16.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hDownloading contourpy-1.3.1-cp311-cp311-macosx_10_9_x86_64.whl (269 kB)\n", + "Using cached cycler-0.12.1-py3-none-any.whl (8.3 kB)\n", + "Downloading fonttools-4.55.5-cp311-cp311-macosx_10_9_x86_64.whl (2.3 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.3/2.3 MB\u001b[0m \u001b[31m21.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading kiwisolver-1.4.8-cp311-cp311-macosx_10_9_x86_64.whl (66 kB)\n", + "Downloading pillow-11.1.0-cp311-cp311-macosx_10_10_x86_64.whl (3.2 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.2/3.2 MB\u001b[0m \u001b[31m14.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hDownloading pyparsing-3.2.1-py3-none-any.whl (107 kB)\n", + "Installing collected packages: pyparsing, pillow, kiwisolver, fonttools, cycler, contourpy, matplotlib\n", + "Successfully installed contourpy-1.3.1 cycler-0.12.1 fonttools-4.55.5 kiwisolver-1.4.8 matplotlib-3.10.0 pillow-11.1.0 pyparsing-3.2.1\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "#pip install matplotlib" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'optuna'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[16], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mos\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mbuilders\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodel_builders\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m generate_training_testing_and_validation_sets, create_study_object, objective, \\\n\u001b[1;32m 3\u001b[0m cnn1d_architecture, save_results, mlp_architecture, save_best_trial_to_csv\n\u001b[1;32m 5\u001b[0m label_type \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbinary_one\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 6\u001b[0m position \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mleft\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", + "File \u001b[0;32m~/ailab/fall-detect/notebooks/../builders/model_builders.py:14\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mkeras\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Sequential\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mkeras\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mlayers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Dense, Dropout, Conv1D, Flatten, MaxPooling1D\n\u001b[0;32m---> 14\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01moptuna\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mcsv\u001b[39;00m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mitertools\u001b[39;00m\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'optuna'" + ] + } + ], + "source": [ + "import os\n", + "from builders.model_builders import generate_training_testing_and_validation_sets, create_study_object, objective, \\\n", + " cnn1d_architecture, save_results, mlp_architecture, save_best_trial_to_csv\n", + "\n", + "label_type = \"binary_one\"\n", + "position = \"left\"\n", + "scenario = \"Sc1_acc_T\"\n", + "\n", + "number_of_labels = 37 if label_type == \"multiple_one\" else 26 if label_type == \"multiple_two\" else 2\n", + "\n", + "current_directory = os.path.dirname(__file__)\n", + "\n", + "data_path = os.path.join(current_directory,\"labels_and_data\",\"data\",\"chest\") if position == \"chest\" \\\n", + " else os.path.join(current_directory,\"labels_and_data\",\"data\",\"left\") if position == \"left\" \\\n", + " else os.path.join(current_directory,\"labelssce_and_data\",\"data\",\"right\")\n", + "label_path = os.path.join(current_directory,\"labels_and_data\",\"labels\",\"chest\") if position == \"chest\" \\\n", + " else os.path.join(current_directory,\"labels_and_data\",\"labels\",\"left\") if position == \"left\" \\\n", + " else os.path.join(current_directory,\"labels_and_data\",\"labels\",\"right\")\n", + "\n", + "array_size = 1020 if position == \"chest\" else 450\n", + "\n", + "neural_network_scenarios = {\n", + " \"Sc1_acc_T\": [os.path.join(data_path,'magacc_time_domain_data_array.npy'), (array_size,1)], # for Sc1_CNN1D_acc_T and Sc1_MLP_acc_T\n", + " \"Sc1_gyr_T\": [os.path.join(data_path,'maggyr_time_domain_data_array.npy'), (array_size,1)], # for Sc1_CNN1D_gyr_T and Sc1_MLP_gyr_T\n", + " \"Sc1_acc_F\": [os.path.join(data_path,'magacc_frequency_domain_data_array.npy'), (int(array_size/2),1)], # for Sc1_CNN1D_acc_F and Sc1_MLP_acc_F\n", + " \"Sc1_gyr_F\": [os.path.join(data_path,'maggyr_frequency_domain_data_array.npy'), (int(array_size/2),1)], # for Sc1_CNN1D_gyr_F and Sc1_MLP_gyr_F\n", + " \"Sc_2_acc_T\": [os.path.join(data_path,'acc_x_y_z_axes_time_domain_data_array.npy'), (array_size,3)], # for Sc_2_CNN1D_acc_T and Sc_2_MLP_acc_T\n", + " \"Sc_2_gyr_T\": [os.path.join(data_path,'gyr_x_y_z_axes_time_domain_data_array.npy'), (array_size,3)], # for Sc_2_CNN1D_gyr_T and Sc_2_MLP_gyr_T\n", + " \"Sc_2_acc_F\": [os.path.join(data_path,'acc_x_y_z_axes_frequency_domain_data_array.npy'), (int(array_size/2),3)], # for Sc_2_CNN1D_acc_F and Sc_2_MLP_acc_F\n", + " \"Sc_2_gyr_F\": [os.path.join(data_path,'gyr_x_y_z_axes_frequency_domain_data_array.npy'), (int(array_size/2),3)], # for Sc_2_CNN1D_gyr_F and Sc_2_MLP_gyr_F\n", + " \"Sc_3_T\": [os.path.join(data_path,'magacc_and_maggyr_time_domain_data_array.npy'), (array_size,2)], # for Sc_3_CNN1D_T and Sc_3_MLP_T\n", + " \"Sc_3_F\": [os.path.join(data_path,'magacc_and_maggyr_frequency_domain_data_array.npy'), (int(array_size/2),2)], # for Sc_3_CNN1D_F and Sc_3_MLP_F\n", + " \"Sc_4_T\": [os.path.join(data_path,'acc_and_gyr_three_axes_time_domain_data_array.npy'), (array_size,6)], # for Sc_4_CNN1D_T and Sc_4_MLP_T\n", + " \"Sc_4_F\": [os.path.join(data_path,'acc_and_gyr_three_axes_frequency_domain_data_array.npy'), (int(array_size/2),6)], # for Sc_4_CNN1D_F and Sc_4_MLP_F\n", + "}\n", + "\n", + "data = neural_network_scenarios[scenario]\n", + "\n", + "label_index = 1 if label_type == \"multiple_one\" else 2 if label_type == \"multiple_two\" else 3 if label_type == \"binary_one\" else 4\n", + "label_options = {1:\"multiple_class_label_1.npy\",2:\"multiple_class_label_2.npy\",3:\"binary_class_label_1.npy\",4:\"binary_class_label_2.npy\"}\n", + "\n", + "labels = os.path.join(label_path, label_options.get(label_index))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "X_train, X_test, y_train, y_test, X_val, y_val = generate_training_testing_and_validation_sets(data[0],labels)\n", + "input_shape = data[1] if neural_network_type == \"CNN1D\" else array_size" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "falldetect", + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}