{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":51753,"databundleVersionId":5692552,"sourceType":"competition"},{"sourceId":6267260,"sourceType":"datasetVersion","datasetId":3467979},{"sourceId":6275345,"sourceType":"datasetVersion","datasetId":3467976}],"dockerImageVersionId":30512,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"! pip install -q --no-index --find-links=file:///kaggle/input/contrails-weights/pip \\\n    segmentation_models_pytorch\n! cp -r /kaggle/input/contrails-src ./src","metadata":{"execution":{"iopub.status.busy":"2025-04-02T01:32:37.662415Z","iopub.execute_input":"2025-04-02T01:32:37.663142Z","iopub.status.idle":"2025-04-02T01:32:47.547991Z","shell.execute_reply.started":"2025-04-02T01:32:37.663114Z","shell.execute_reply":"2025-04-02T01:32:47.546847Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport sys\nimport yaml\nsys.path.append('/kaggle/working/src')\nimport unet5\nimport vit4\nimport unet1024\nimport util\nfrom submit import write_submission","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2025-04-02T01:32:47.55034Z","iopub.execute_input":"2025-04-02T01:32:47.551083Z","iopub.status.idle":"2025-04-02T01:32:53.446858Z","shell.execute_reply.started":"2025-04-02T01:32:47.551045Z","shell.execute_reply":"2025-04-02T01:32:53.445612Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Configuration","metadata":{}},{"cell_type":"code","source":"cfg = yaml.safe_load(\"\"\"\ninput:\n  weight: /kaggle/input/contrails-weights\n\nunet5:\n  batch_size: 1\n  models:\n    - name: maxvit_tiny\n      encoder: maxvit_tiny_tf_512.in1k\n      decoder_channels: [256, 128, 64, 32, 16]\n      w: 1.0\n      resize: 512\n      tta: d4prob\n      folds: [0,1,2,3,4]\n\nvit4:\n  batch_size: 2\n  models:\n    - name: vit4_1024\n      encoder: maxvit_tiny_tf_512.in1k\n      decoder_channels: [256, 128, 64, 32, 32]\n      w: 0.6465366913319027\n      #w: 1.0\n      resize: 512\n      tta: d4prob\n      folds: [5, 7]\n\nunet1024:\n  batch_size: 2\n  models:\n    - name: unet1024\n      encoder: maxvit_tiny_tf_512.in1k\n      decoder_channels: [256, 128, 64, 32, 16]\n      w: 0.4531613974630522\n      resize: 1024\n      tta: d4prob\n      folds: [3, 4]\n\"\"\")","metadata":{"execution":{"iopub.status.busy":"2025-04-02T01:32:53.44858Z","iopub.execute_input":"2025-04-02T01:32:53.448973Z","iopub.status.idle":"2025-04-02T01:32:53.46329Z","shell.execute_reply.started":"2025-04-02T01:32:53.448938Z","shell.execute_reply":"2025-04-02T01:32:53.462056Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Run","metadata":{}},{"cell_type":"code","source":"data_type = 'test'\n#data_type = 'validation'\ndebug=False\n\n# Unet3 (Ash-color 3-channel image)\n#preds = unet3.run(data_type, cfg, None, debug=debug)\n#preds = unet4.run(data_type, cfg, None, debug=debug)\n#preds = unet5.run(data_type, cfg, None, debug=debug)\n#preds = unet1024.run(data_type, cfg, None, debug=debug)\n\n# Ensemble\npreds = vit4.run(data_type, cfg, None, debug=debug)\nunet1024.run(data_type, cfg, preds, debug=debug)\n\n\nutil.check_preds_finite(preds)\n\n# Write submission.csv\n#th = 0.45\nth = 0.5\nsubmit = write_submission(preds, th, 'submission.csv')","metadata":{"execution":{"iopub.status.busy":"2025-04-02T01:32:53.464419Z","iopub.execute_input":"2025-04-02T01:32:53.464765Z","iopub.status.idle":"2025-04-02T01:33:28.366181Z","shell.execute_reply.started":"2025-04-02T01:32:53.464733Z","shell.execute_reply":"2025-04-02T01:33:28.36495Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"! tail submission.csv\n\nif data_type == 'validation':\n    ! python3 src/score.py submission.csv","metadata":{"execution":{"iopub.status.busy":"2025-04-02T01:33:28.369164Z","iopub.execute_input":"2025-04-02T01:33:28.369479Z","iopub.status.idle":"2025-04-02T01:33:29.396609Z","shell.execute_reply.started":"2025-04-02T01:33:28.369442Z","shell.execute_reply":"2025-04-02T01:33:29.395788Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import shutil\n\n# Sao chép thư mục chứa weights sang thư mục mới với tên \"model_contrails\"\nshutil.copytree('/kaggle/input/contrails-weights', 'model_contrails')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-02T01:33:29.398066Z","iopub.execute_input":"2025-04-02T01:33:29.398427Z","iopub.status.idle":"2025-04-02T01:34:08.772147Z","shell.execute_reply.started":"2025-04-02T01:33:29.398392Z","shell.execute_reply":"2025-04-02T01:34:08.771239Z"}},"outputs":[],"execution_count":null}]}