{"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":"none","dataSources":[{"sourceId":71549,"databundleVersionId":8561470,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":9297927,"sourceType":"datasetVersion","datasetId":5247413},{"sourceId":105707,"sourceType":"modelInstanceVersion","isSourceIdPinned":false,"modelInstanceId":88581,"modelId":78231}],"dockerImageVersionId":30733,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!git clone https://github.com/rapotekhin/RSNA2024.git\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:12:11.646117Z","iopub.execute_input":"2025-12-15T00:12:11.646365Z","iopub.status.idle":"2025-12-15T00:12:13.1516Z","shell.execute_reply.started":"2025-12-15T00:12:11.646343Z","shell.execute_reply":"2025-12-15T00:12:13.150544Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working/RSNA2024\n!ls","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:12:13.153975Z","iopub.execute_input":"2025-12-15T00:12:13.154336Z","iopub.status.idle":"2025-12-15T00:12:14.151625Z","shell.execute_reply.started":"2025-12-15T00:12:13.154301Z","shell.execute_reply":"2025-12-15T00:12:14.150464Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:12:13.153975Z","iopub.execute_input":"2025-12-15T00:12:13.154336Z","iopub.status.idle":"2025-12-15T00:12:14.151625Z","shell.execute_reply.started":"2025-12-15T00:12:13.154301Z","shell.execute_reply":"2025-12-15T00:12:14.150464Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install -r requirements.txt\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:12:14.153106Z","iopub.execute_input":"2025-12-15T00:12:14.153384Z","iopub.status.idle":"2025-12-15T00:14:39.105632Z","shell.execute_reply.started":"2025-12-15T00:12:14.153359Z","shell.execute_reply":"2025-12-15T00:14:39.104613Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%bash\ncd /kaggle/working/RSNA2024\n\nCLEARML_OFFLINE_MODE=1 TMPDIR=/dev/shm python - << 'PY'\nimport sys, os\nsys.path.insert(0, \".\")\n\nsys.argv = [\n    \"train.py\",\n    \"--data_dir\", \"/kaggle/input/rsna-2024-lumbar-spine-degenerative-classification\",\n    \"--workdir\", \"/kaggle/working/workdir\",\n    \"--epochs\", \"20\", # tt\n    \"--batch_size\", \"2\",\n    \"--accumulation_steps\", \"2\",\n    \"--num_workers\", \"0\",\n]\n\n# ✅ patch pandas.read_csv để chỉ lấy ít dòng -> giảm dataset -> giảm cache output\nimport pandas as pd\n_real_read_csv = pd.read_csv\ndef _patched_read_csv(path, *args, **kwargs):\n    df = _real_read_csv(path, *args, **kwargs)\n    if str(path).endswith(\"train.csv\"):\n        df = df.sample(n=min(300, len(df)), random_state=42).reset_index(drop=True)  # <= đổi 300 thành 100/200 nếu muốn nhẹ hơn\n    return df\npd.read_csv = _patched_read_csv\n\nimport config\nconfig.args.num_workers = int(config.args.num_workers)\nconfig.args.batch_size = int(config.args.batch_size)\nconfig.args.epochs = int(config.args.epochs)\nconfig.args.accumulation_steps = int(config.args.accumulation_steps)\n\n# ✅ giảm kích thước ảnh\nconfig.args.image_size = (32, 128, 256)\n\n# ✅ đưa cache sang RAM để không ăn /kaggle/working\nconfig.args.cache_dir = \"/dev/shm/rsna_cache\"\n\nimport runpy\nrunpy.run_path(\"train.py\", run_name=\"__main__\")\nPY\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:14:39.107804Z","iopub.execute_input":"2025-12-15T00:14:39.108093Z","iopub.status.idle":"2025-12-15T00:40:46.244412Z","shell.execute_reply.started":"2025-12-15T00:14:39.108065Z","shell.execute_reply":"2025-12-15T00:40:46.243122Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!cp \"/kaggle/working/workdir/SEResNext101_custom_[no_resample]_[augs1]_32x128x256/model_best.pth\" \\\n    \"/kaggle/working/model_best.pth\"\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:40:46.245689Z","iopub.execute_input":"2025-12-15T00:40:46.24633Z","iopub.status.idle":"2025-12-15T00:40:47.384287Z","shell.execute_reply.started":"2025-12-15T00:40:46.246298Z","shell.execute_reply":"2025-12-15T00:40:47.383133Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls -lh /kaggle/working/model_best.pth\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:40:47.385785Z","iopub.execute_input":"2025-12-15T00:40:47.386051Z","iopub.status.idle":"2025-12-15T00:40:48.373135Z","shell.execute_reply.started":"2025-12-15T00:40:47.386027Z","shell.execute_reply":"2025-12-15T00:40:48.372267Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%bash\nls -lh /kaggle/working/model_best.pth\nzip -j /kaggle/working/model_best.zip /kaggle/working/model_best.pth\nls -lh /kaggle/working/model_best.zip\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-15T00:40:48.374676Z","iopub.execute_input":"2025-12-15T00:40:48.375524Z","iopub.status.idle":"2025-12-15T00:40:59.004381Z","shell.execute_reply.started":"2025-12-15T00:40:48.375485Z","shell.execute_reply":"2025-12-15T00:40:59.003678Z"}},"outputs":[],"execution_count":null}]}