{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":53666,"databundleVersionId":6589269,"sourceType":"competition"},{"sourceId":7193425,"sourceType":"datasetVersion","datasetId":4158512}],"dockerImageVersionId":30627,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"This is sample code to train my models.","metadata":{}},{"cell_type":"markdown","source":"### 0. Data Preparation \n- move some files to local. (this part is only necessary when you run code on kaggle notebook)\n- Change setting file if necessary.","metadata":{}},{"cell_type":"code","source":"RUN_ON_KAGGLE = True\n\nif RUN_ON_KAGGLE:\n    import gc\n    import json\n    from distutils.dir_util import copy_tree\n\n    _ = copy_tree(\"/kaggle/input/cmisleep-2ndplace-kmat\", \"/kaggle/working/kmat\")\n    %cd kmat","metadata":{"execution":{"iopub.status.busy":"2023-12-13T12:53:33.527116Z","iopub.execute_input":"2023-12-13T12:53:33.528046Z","iopub.status.idle":"2023-12-13T12:53:33.630369Z","shell.execute_reply.started":"2023-12-13T12:53:33.528011Z","shell.execute_reply":"2023-12-13T12:53:33.629491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\npath_setting = 'SETTINGS.json'\nsetting = json.load(open(path_setting))\nprint(\"default\")\nprint(setting)\n\nsetting[\"IS_DEBUG\"] = 'True' # Debug mode uses only 20% data, and train only 2 epochs.\n\nif RUN_ON_KAGGLE:\n    setting[\"train_path\"] = \"/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet\"\n    setting[\"train_target_path\"] = \"/kaggle/input/child-mind-institute-detect-sleep-states/train_events.csv\"\n    setting[\"test_path\"] = \"/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet\"\n    setting[\"sample_submission_path\"] = \"/kaggle/input/child-mind-institute-detect-sleep-states/sample_submission.csv\"\n        \nprint(\"changed into\")\nprint(setting)\njson.dump(setting, open(path_setting, 'w'))","metadata":{"execution":{"iopub.status.busy":"2023-12-13T12:56:03.870453Z","iopub.execute_input":"2023-12-13T12:56:03.871354Z","iopub.status.idle":"2023-12-13T12:56:03.879193Z","shell.execute_reply.started":"2023-12-13T12:56:03.871323Z","shell.execute_reply":"2023-12-13T12:56:03.878223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1. Prepare dataset for training\nMake npy files and label for training 1DCNN","metadata":{}},{"cell_type":"code","source":"%run src/make_dataset.ipynb","metadata":{"execution":{"iopub.status.busy":"2023-12-13T11:58:25.111028Z","iopub.execute_input":"2023-12-13T11:58:25.111791Z","iopub.status.idle":"2023-12-13T12:00:20.938887Z","shell.execute_reply.started":"2023-12-13T11:58:25.111738Z","shell.execute_reply":"2023-12-13T12:00:20.937923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2. Train 1DCNN\nTraining 1DCNN event detection model.\n(In debug mode, the loss values are large due to the small batch size.)","metadata":{}},{"cell_type":"code","source":"%run src/train_1dcnn.py","metadata":{"execution":{"iopub.status.busy":"2023-12-13T12:13:39.839665Z","iopub.execute_input":"2023-12-13T12:13:39.840580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### postprocess (peak detection and event classification)","metadata":{}},{"cell_type":"code","source":"%run src/make_dataset_2ndstage.ipynb","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3. Train lightGBM (2nd stage and 3rd stage)","metadata":{}},{"cell_type":"code","source":"%run src/stage2model.ipynb","metadata":{},"execution_count":null,"outputs":[]}]}