{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":59093,"databundleVersionId":7469972,"sourceType":"competition"},{"sourceId":7852391,"sourceType":"datasetVersion","datasetId":4605218},{"sourceId":7991215,"sourceType":"datasetVersion","datasetId":4604394},{"sourceId":8067363,"sourceType":"datasetVersion","datasetId":4605034},{"sourceId":8022573,"sourceType":"datasetVersion","datasetId":4605070}],"dockerImageVersionId":30665,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Check hardware","metadata":{}},{"cell_type":"code","source":"!nvidia-smi","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-03T20:28:12.677155Z","iopub.execute_input":"2024-04-03T20:28:12.677572Z","iopub.status.idle":"2024-04-03T20:28:13.718640Z","shell.execute_reply.started":"2024-04-03T20:28:12.677541Z","shell.execute_reply":"2024-04-03T20:28:13.717447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!lscpu |grep 'Model name'\n#no.of cores each processor is having\n!lscpu | grep 'Core(s) per socket'\n#no.of threads each core is having\n!lscpu | grep 'Thread(s) per core'","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:28:13.720772Z","iopub.execute_input":"2024-04-03T20:28:13.721057Z","iopub.status.idle":"2024-04-03T20:28:16.763037Z","shell.execute_reply.started":"2024-04-03T20:28:13.721032Z","shell.execute_reply":"2024-04-03T20:28:16.761796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Enable inference","metadata":{}},{"cell_type":"code","source":"import os\nrun_inference = len(os.listdir('/kaggle/input/hms-harmful-brain-activity-classification/test_eegs')) > 1\nrun_inference\n\n# run_inference = True\n# run_inference","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:28:22.862049Z","iopub.execute_input":"2024-04-03T20:28:22.863059Z","iopub.status.idle":"2024-04-03T20:28:22.870453Z","shell.execute_reply.started":"2024-04-03T20:28:22.863020Z","shell.execute_reply":"2024-04-03T20:28:22.869124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Install packages","metadata":{}},{"cell_type":"code","source":"if run_inference:\n    !pip \\\n        install \\\n        --no-index \\\n        --find-links /kaggle/input/hms-packages/ \\\n        jsonargparse[signatures]==4.27.5 \\\n        lightning==2.2.0.post0 \\\n        natsort==8.4.0 \\\n        einops==0.7.0 \\\n        librosa==0.10.1 \\\n        justpyplot==0.1.1 \\\n        perf_timer==0.2.2 \\\n        PyWavelets==1.5.0 \\\n        albumentations==1.4.1 \\\n        torch-ema==0.3","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:28:24.116716Z","iopub.execute_input":"2024-04-03T20:28:24.117380Z","iopub.status.idle":"2024-04-03T20:28:45.738482Z","shell.execute_reply.started":"2024-04-03T20:28:24.117347Z","shell.execute_reply":"2024-04-03T20:28:45.737343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Setup env","metadata":{}},{"cell_type":"code","source":"import os\nos.environ['PYTHONPATH'] = \"/kaggle/input/hms-code/:\" + os.environ['PYTHONPATH']\nos.environ['LOGLEVEL'] = \"ERROR\"\n# os.environ['LOGLEVEL'] = \"INFO\"\n!echo $PYTHONPATH","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:28:45.740527Z","iopub.execute_input":"2024-04-03T20:28:45.740836Z","iopub.status.idle":"2024-04-03T20:28:46.680318Z","shell.execute_reply.started":"2024-04-03T20:28:45.740810Z","shell.execute_reply":"2024-04-03T20:28:46.679351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wandb disabled","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:28:46.681752Z","iopub.execute_input":"2024-04-03T20:28:46.682092Z","iopub.status.idle":"2024-04-03T20:28:48.795125Z","shell.execute_reply.started":"2024-04-03T20:28:46.682063Z","shell.execute_reply":"2024-04-03T20:28:48.794191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Build EEG spectrograms","metadata":{}},{"cell_type":"code","source":"if run_inference:\n    !python \\\n        /kaggle/input/hms-code/src/scripts/convert_eeg_to_spectrograms.py \\\n        /kaggle/input/hms-harmful-brain-activity-classification/test.csv \\\n        /kaggle/input/hms-harmful-brain-activity-classification/test_eegs \\\n        /kaggle/working/eeg_specs_test.npy","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:28:48.797652Z","iopub.execute_input":"2024-04-03T20:28:48.797974Z","iopub.status.idle":"2024-04-03T20:29:00.502995Z","shell.execute_reply.started":"2024-04-03T20:28:48.797930Z","shell.execute_reply":"2024-04-03T20:29:00.502049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Run validation to verify","metadata":{}},{"cell_type":"code","source":"# if run_inference:\n#     !python \\\n#         /kaggle/input/hms-code/run/main.py \\\n#         validate \\\n#         --config /kaggle/input/hms-code/run/configs/common.yaml \\\n#         --config /kaggle/input/hms-code/run/configs/timm_vit_tiny.yaml \\\n#         --trainer.precision '16-true' \\\n#         --data.init_args.num_workers 4 \\\n#         --data.init_args.dataset_dirpath /kaggle/input/hms-harmful-brain-activity-classification \\\n#         --data.init_args.cache_dir null \\\n#         --data.init_args.eeg_spectrograms_filepath /kaggle/input/hms-eeg-spectrograms-train/eeg_specs.npy \\\n#         --model.init_args.model_kwargs '{\"pretrained\": false, \"in_chans\": 1}' \\\n#         --ckpt_path /kaggle/input/hms-models/best_0.ckpt","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:29:00.504349Z","iopub.execute_input":"2024-04-03T20:29:00.504668Z","iopub.status.idle":"2024-04-03T20:29:00.509402Z","shell.execute_reply.started":"2024-04-03T20:29:00.504632Z","shell.execute_reply":"2024-04-03T20:29:00.508411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predict","metadata":{}},{"cell_type":"code","source":"if run_inference:\n    !for i in 0 1 2 3 4 5 9; do python \\\n        /kaggle/input/hms-code/run/main.py \\\n        predict \\\n        --config /kaggle/input/hms-code/run/configs/common.yaml \\\n        --config /kaggle/input/hms-code/run/configs/timm_vit_tiny.yaml \\\n        --trainer.precision '16-true' \\\n        --data.init_args.num_workers 4 \\\n        --data.init_args.dataset_dirpath /kaggle/input/hms-harmful-brain-activity-classification \\\n        --data.init_args.cache_dir null \\\n        --data.init_args.eeg_spectrograms_filepath /kaggle/working/eeg_specs_test.npy \\\n        --model.init_args.model_kwargs '{\"pretrained\": false, \"in_chans\": 1}' \\\n        --model.init_args.tta true \\\n        --ckpt_path /kaggle/input/hms-models/ema-0.8_$i.ckpt; mv /kaggle/working/submission.csv /kaggle/working/submission_$i.csv; done\n    !python \\\n        /kaggle/input/hms-code/src/scripts/combine_submissions.py \\\n        /kaggle/working/submission_*.csv \\\n        --output /kaggle/working/submission.csv\nelse:\n    !cp /kaggle/input/hms-harmful-brain-activity-classification/sample_submission.csv ./submission.csv","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:29:00.510560Z","iopub.execute_input":"2024-04-03T20:29:00.510833Z","iopub.status.idle":"2024-04-03T20:31:17.152343Z","shell.execute_reply.started":"2024-04-03T20:29:00.510810Z","shell.execute_reply":"2024-04-03T20:31:17.151212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!head -10 /kaggle/working/submission.csv","metadata":{"execution":{"iopub.status.busy":"2024-04-03T20:31:17.153901Z","iopub.execute_input":"2024-04-03T20:31:17.154258Z","iopub.status.idle":"2024-04-03T20:31:18.124369Z","shell.execute_reply.started":"2024-04-03T20:31:17.154229Z","shell.execute_reply":"2024-04-03T20:31:18.123233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}