{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!rm -rf *\n!mkdir /kaggle/working/datasets\n!mkdir /kaggle/working/datasets/badlad\n!mkdir /kaggle/working/datasets/badlad/labels\n!mkdir /kaggle/working/datasets/badlad/labels/train\n!mkdir /kaggle/working/datasets/badlad/images\n!mkdir /kaggle/working/datasets/badlad/images/train\n!mkdir /kaggle/working/datasets/badlad/images/test\n# !ln -s /kaggle/input/dlsprint2/badlad/images /kaggle/working/datasets/badlad/images\n# !ln -s /kaggle/input/dlsprint2/badlad/labels/yolov8_format/train /kaggle/working/datasets/badlad/labels","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:34:33.049711Z","iopub.execute_input":"2023-06-25T04:34:33.050132Z","iopub.status.idle":"2023-06-25T04:34:41.004776Z","shell.execute_reply.started":"2023-06-25T04:34:33.050101Z","shell.execute_reply":"2023-06-25T04:34:41.003441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfrom tqdm import tqdm\n\ndef all_files_in_folder_symlink(source_dir, target_dir):\n    files = os.listdir(source_dir)\n\n    for file in tqdm(files):\n        source_file = os.path.join(source_dir, file)\n        target_file = os.path.join(target_dir, file)\n        os.symlink(source_file, target_file)\n\n    ","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:35:03.323288Z","iopub.execute_input":"2023-06-25T04:35:03.324403Z","iopub.status.idle":"2023-06-25T04:35:03.331951Z","shell.execute_reply.started":"2023-06-25T04:35:03.324350Z","shell.execute_reply":"2023-06-25T04:35:03.330905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/dlsprint2/badlad/labels/yolov8_format/train\",\"/kaggle/working/datasets/badlad/labels/train\")","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:35:03.335260Z","iopub.execute_input":"2023-06-25T04:35:03.336125Z","iopub.status.idle":"2023-06-25T04:35:04.562161Z","shell.execute_reply.started":"2023-06-25T04:35:03.336088Z","shell.execute_reply":"2023-06-25T04:35:04.561202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/dlsprint2/badlad/images/train\",\"/kaggle/working/datasets/badlad/images/train\")","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:35:40.664228Z","iopub.execute_input":"2023-06-25T04:35:40.665116Z","iopub.status.idle":"2023-06-25T04:35:41.651773Z","shell.execute_reply.started":"2023-06-25T04:35:40.665081Z","shell.execute_reply":"2023-06-25T04:35:41.650821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/dlsprint2/badlad/images/test\",\"/kaggle/working/datasets/badlad/images/test\")","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:35:50.581577Z","iopub.execute_input":"2023-06-25T04:35:50.581961Z","iopub.status.idle":"2023-06-25T04:35:51.481499Z","shell.execute_reply.started":"2023-06-25T04:35:50.581920Z","shell.execute_reply":"2023-06-25T04:35:51.480554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !tree -d","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:36:41.740005Z","iopub.execute_input":"2023-06-25T04:36:41.740936Z","iopub.status.idle":"2023-06-25T04:37:39.024299Z","shell.execute_reply.started":"2023-06-25T04:36:41.740897Z","shell.execute_reply":"2023-06-25T04:37:39.023179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install ultralytics -q","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:37:39.027311Z","iopub.execute_input":"2023-06-25T04:37:39.027710Z","iopub.status.idle":"2023-06-25T04:37:50.675452Z","shell.execute_reply.started":"2023-06-25T04:37:39.027673Z","shell.execute_reply":"2023-06-25T04:37:50.674215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"file_content = \"\"\"\npath: /kaggle/working/datasets/badlad  # dataset root dir\ntrain: images/train  # train images (relative to 'path') 128 images\nval: images/train  # val images (relative to 'path') 128 images\ntest:  images/test\n\n# Classes\nnames:\n  0: paragraph\n  1: text_box\n  2: image\n  3: table\n\n\n\"\"\"\n\nwith open(\"yolov8.yaml\", mode=\"w\") as f:\n    f.write(file_content)","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:37:53.191574Z","iopub.execute_input":"2023-06-25T04:37:53.192043Z","iopub.status.idle":"2023-06-25T04:37:53.199267Z","shell.execute_reply.started":"2023-06-25T04:37:53.192005Z","shell.execute_reply":"2023-06-25T04:37:53.198255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import wandb\nwandb.init(mode=\"disabled\")","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:37:56.424409Z","iopub.execute_input":"2023-06-25T04:37:56.424767Z","iopub.status.idle":"2023-06-25T04:37:56.456122Z","shell.execute_reply.started":"2023-06-25T04:37:56.424738Z","shell.execute_reply":"2023-06-25T04:37:56.455094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from ultralytics import YOLO\nmodel = YOLO(\"yolov8m-seg.pt\")\nmodel.train(data=\"/kaggle/working/yolov8.yaml\", epochs=3)","metadata":{"execution":{"iopub.status.busy":"2023-06-25T04:37:58.615195Z","iopub.execute_input":"2023-06-25T04:37:58.615902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}