{"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":7541469,"sourceType":"datasetVersion","datasetId":4391569}],"dockerImageVersionId":30512,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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/labels/val\n!mkdir /kaggle/working/datasets/badlad/images\n!mkdir /kaggle/working/datasets/badlad/images/train\n!mkdir /kaggle/working/datasets/badlad/images/val\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":"2024-04-12T10:48:00.434531Z","iopub.execute_input":"2024-04-12T10:48:00.434924Z","iopub.status.idle":"2024-04-12T10:48:10.879677Z","shell.execute_reply.started":"2024-04-12T10:48:00.434890Z","shell.execute_reply":"2024-04-12T10:48:10.878386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from ultralytics import YOLO","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:10.882283Z","iopub.execute_input":"2024-04-12T10:48:10.882718Z","iopub.status.idle":"2024-04-12T10:48:12.623785Z","shell.execute_reply.started":"2024-04-12T10:48:10.882678Z","shell.execute_reply":"2024-04-12T10:48:12.622893Z"},"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":"2024-04-12T10:48:12.624880Z","iopub.execute_input":"2024-04-12T10:48:12.625500Z","iopub.status.idle":"2024-04-12T10:48:12.631939Z","shell.execute_reply.started":"2024-04-12T10:48:12.625468Z","shell.execute_reply":"2024-04-12T10:48:12.630909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/rsud20k-bangladesh-road-scene-understanding/rsud20k/labels/train\",\"/kaggle/working/datasets/badlad/labels/train\")","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:12.633252Z","iopub.execute_input":"2024-04-12T10:48:12.633549Z","iopub.status.idle":"2024-04-12T10:48:13.395571Z","shell.execute_reply.started":"2024-04-12T10:48:12.633524Z","shell.execute_reply":"2024-04-12T10:48:13.394659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/rsud20k-bangladesh-road-scene-understanding/rsud20k/images/train\",\"/kaggle/working/datasets/badlad/images/train\")","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:13.398161Z","iopub.execute_input":"2024-04-12T10:48:13.398465Z","iopub.status.idle":"2024-04-12T10:48:14.427384Z","shell.execute_reply.started":"2024-04-12T10:48:13.398438Z","shell.execute_reply":"2024-04-12T10:48:14.426459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/rsud20k-bangladesh-road-scene-understanding/rsud20k/images/test\",\"/kaggle/working/datasets/badlad/images/test\")","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:14.428679Z","iopub.execute_input":"2024-04-12T10:48:14.428986Z","iopub.status.idle":"2024-04-12T10:48:14.730367Z","shell.execute_reply.started":"2024-04-12T10:48:14.428957Z","shell.execute_reply":"2024-04-12T10:48:14.729464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/rsud20k-bangladesh-road-scene-understanding/rsud20k/labels/val\",\"/kaggle/working/datasets/badlad/labels/val\")","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:14.731775Z","iopub.execute_input":"2024-04-12T10:48:14.732488Z","iopub.status.idle":"2024-04-12T10:48:14.783641Z","shell.execute_reply.started":"2024-04-12T10:48:14.732450Z","shell.execute_reply":"2024-04-12T10:48:14.782788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_in_folder_symlink(\"/kaggle/input/rsud20k-bangladesh-road-scene-understanding/rsud20k/images/val\",\"/kaggle/working/datasets/badlad/images/val\")","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:14.784877Z","iopub.execute_input":"2024-04-12T10:48:14.785221Z","iopub.status.idle":"2024-04-12T10:48:14.834371Z","shell.execute_reply.started":"2024-04-12T10:48:14.785188Z","shell.execute_reply":"2024-04-12T10:48:14.833482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !tree -d","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:14.835548Z","iopub.execute_input":"2024-04-12T10:48:14.835903Z","iopub.status.idle":"2024-04-12T10:48:14.840114Z","shell.execute_reply.started":"2024-04-12T10:48:14.835869Z","shell.execute_reply":"2024-04-12T10:48:14.839192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!git clone https://github.com/touch3080/ultralytics  # clone\n\n!pip install -r '/kaggle/working/yolov5/requirements.txt'","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:14.841331Z","iopub.execute_input":"2024-04-12T10:48:14.841676Z","iopub.status.idle":"2024-04-12T10:48:19.267117Z","shell.execute_reply.started":"2024-04-12T10:48:14.841623Z","shell.execute_reply":"2024-04-12T10:48:19.265839Z"},"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/val  # val images (relative to 'path') 128 images\ntest:  images/test\n\n# Classes\nnames:\n    0: person\n    1: rickshaw\n    2: rickshaw van\n    3: auto rickshaw\n    4: truck\n    5: pickup truck\n    6: private car\n    7: motorcycle\n    8: bicycle\n    9: bus\n    10: micro bus\n    11: covered van\n    12: human hauler\n\"\"\"\n\nwith open(\"yolov5.yaml\", mode=\"w\") as f:\n    f.write(file_content)","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:19.268901Z","iopub.execute_input":"2024-04-12T10:48:19.269250Z","iopub.status.idle":"2024-04-12T10:48:19.275745Z","shell.execute_reply.started":"2024-04-12T10:48:19.269211Z","shell.execute_reply":"2024-04-12T10:48:19.274870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -U ray[tune]","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:19.276954Z","iopub.execute_input":"2024-04-12T10:48:19.277274Z","iopub.status.idle":"2024-04-12T10:48:30.713509Z","shell.execute_reply.started":"2024-04-12T10:48:19.277244Z","shell.execute_reply":"2024-04-12T10:48:30.712317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import wandb\nwandb.init(mode=\"disabled\")","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:30.715135Z","iopub.execute_input":"2024-04-12T10:48:30.715556Z","iopub.status.idle":"2024-04-12T10:48:31.689649Z","shell.execute_reply.started":"2024-04-12T10:48:30.715514Z","shell.execute_reply":"2024-04-12T10:48:31.688713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install ultralytics","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:31.692594Z","iopub.execute_input":"2024-04-12T10:48:31.693124Z","iopub.status.idle":"2024-04-12T10:48:42.843733Z","shell.execute_reply.started":"2024-04-12T10:48:31.693095Z","shell.execute_reply":"2024-04-12T10:48:42.842668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from ultralytics import YOLO\n\n# Load a model\nmodel = YOLO('yolov8n.pt') \nmodel.train(data=\"/kaggle/working/yolov5.yaml\", epochs=4)","metadata":{"execution":{"iopub.status.busy":"2024-04-12T10:48:42.845152Z","iopub.execute_input":"2024-04-12T10:48:42.845487Z","iopub.status.idle":"2024-04-12T11:17:56.606366Z","shell.execute_reply.started":"2024-04-12T10:48:42.845456Z","shell.execute_reply":"2024-04-12T11:17:56.605164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import ultralytics","metadata":{"execution":{"iopub.status.busy":"2024-04-12T11:17:56.608503Z","iopub.execute_input":"2024-04-12T11:17:56.608864Z","iopub.status.idle":"2024-04-12T11:17:56.614155Z","shell.execute_reply.started":"2024-04-12T11:17:56.608826Z","shell.execute_reply":"2024-04-12T11:17:56.613249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from ultralytics import YOLO","metadata":{"execution":{"iopub.status.busy":"2024-04-12T11:17:56.616343Z","iopub.execute_input":"2024-04-12T11:17:56.616878Z","iopub.status.idle":"2024-04-12T11:17:56.638414Z","shell.execute_reply.started":"2024-04-12T11:17:56.616840Z","shell.execute_reply":"2024-04-12T11:17:56.637529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}