{"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":67836,"databundleVersionId":7527339,"sourceType":"competition"},{"sourceId":10146,"sourceType":"modelInstanceVersion","modelInstanceId":8267}],"dockerImageVersionId":30648,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"%%sh\ngit clone https://github.com/meituan/YOLOv6\ncd YOLOv6\npip install -r requirements.txt >> /dev/null","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-15T13:04:33.635657Z","iopub.execute_input":"2024-02-15T13:04:33.636472Z","iopub.status.idle":"2024-02-15T13:04:50.917169Z","shell.execute_reply.started":"2024-02-15T13:04:33.636433Z","shell.execute_reply":"2024-02-15T13:04:50.916272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! mkdir images\nSOURCE_DIR = \"/kaggle/input/dl-enigma-10-sust-cse-carnival-2024/dlenigma1/BadODD/images/test/\"\n! cp -r {SOURCE_DIR}/* images/","metadata":{"execution":{"iopub.status.busy":"2024-02-15T13:04:50.918834Z","iopub.execute_input":"2024-02-15T13:04:50.919176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd YOLOv6\nOUTPUT_DIR = \"/kaggle/working/\"\nWEIGHTS = '/kaggle/input/qwerty_yolov6/pytorch/yolo_full/1/yolov6_weight.pt'\n! python tools/infer.py --img-size 1280 1280 --save-txt --source /kaggle/working/images/ --save-dir {OUTPUT_DIR} --weights {WEIGHTS}  --not-save-img\n%cd ..","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\n\ndef convert_coord(x, y, w, h):\n    return x - w/2, y - h/2, w, h\n\ndef process(row):\n    image_id = row[\"ImageID\"]\n    f = f\"/kaggle/working/labels/{image_id}.txt\"\n    \n    if not os.path.exists(f):\n        return \"0 0 0 0 0 0\"\n    \n    with open(f) as f:\n        pred = []\n        for line in f:\n            cls, x, y, w, h, conf = [float(i) for i in line.split()]\n            x, y, w, h = convert_coord(x, y, w, h)\n\n            pred.append(f\"{cls} {conf} {x} {y} {w} {h}\")\n    return \",\".join(pred)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tqdm\nimport pandas as pd\n\ntqdm.tqdm.pandas()\n\nsubmit = pd.read_csv('/kaggle/input/dl-enigma-10-sust-cse-carnival-2024/dlenigma1/sample_submission.csv')\n\npred = submit.progress_apply(process, axis=1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit[\"PredictionString_pred\"] = pred","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}