{"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":31703,"databundleVersionId":2871752,"sourceType":"competition"},{"sourceId":3141691,"sourceType":"datasetVersion","datasetId":1738872},{"sourceId":8110798,"sourceType":"datasetVersion","datasetId":4791202}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# 🛠 Install Libraries","metadata":{}},{"cell_type":"code","source":"!pip install -qU wandb\n!pip install -qU bbox-utility \n!pip install -qU ultralytics\n","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:13:14.198186Z","iopub.execute_input":"2024-04-14T01:13:14.198660Z","iopub.status.idle":"2024-04-14T01:13:57.324363Z","shell.execute_reply.started":"2024-04-14T01:13:14.198629Z","shell.execute_reply":"2024-04-14T01:13:57.323013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 📚 Import Libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np\nfrom tqdm.notebook import tqdm\ntqdm.pandas()\nimport pandas as pd\nimport os\nimport cv2\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport glob\n\nimport shutil\nimport sys\nsys.path.append('../input/tensorflow-great-barrier-reef')\n\nfrom joblib import Parallel, delayed\n\nfrom IPython.display import display\n\nfrom ultralytics import YOLO\n\nimport random\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-14T01:14:08.110108Z","iopub.execute_input":"2024-04-14T01:14:08.111033Z","iopub.status.idle":"2024-04-14T01:14:14.699343Z","shell.execute_reply.started":"2024-04-14T01:14:08.110998Z","shell.execute_reply":"2024-04-14T01:14:14.698347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import wandb\n\ntry:\n    from kaggle_secrets import UserSecretsClient\n    user_secrets = UserSecretsClient()\n    api_key = user_secrets.get_secret(\"WANDB\")\n    wandb.login(key=api_key)\n    anonymous = None\nexcept:\n    wandb.login(anonymous='must')\n    print('To use your W&B account,\\nGo to Add-ons -> Secrets and provide your W&B access token. Use the Label name as WANDB. \\nGet your W&B access token from here: https://wandb.ai/authorize')","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:14:17.412769Z","iopub.execute_input":"2024-04-14T01:14:17.413304Z","iopub.status.idle":"2024-04-14T01:14:21.045515Z","shell.execute_reply.started":"2024-04-14T01:14:17.413274Z","shell.execute_reply":"2024-04-14T01:14:21.044393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 📖 Meta Data\n* `images/` - Folder containing training set photos of the form `image_name.tif`.\n* `images/TrainGroundTruth` - Folder containing training set txt files of the form `image_name.txt`.\n* `annotations` - The bounding boxes of any signature detections in a string format that can be evaluated directly with Python. A bounding box is described by the pixel coordinate `(x_min, y_min)` of its top left corner within the image together with its `(x_max, y_max)` of its lower right corner in pixels --> (XXYY format).","metadata":{}},{"cell_type":"code","source":"FOLD      = 1 # which fold to train\nDIM       = 3000 \nMODEL     = 'yolov5s'\nBATCH     = 4\nEPOCHS    = 15\nOPTMIZER  = 'Adam'\n\nPROJECT   = 'signature-detection' # w&b in yolov5\nNAME      = f'{MODEL}-dim{DIM}-fold{FOLD}' # w&b for yolov5\n\nREMOVE_NOBBOX = True # remove images with no bbox\nROOT_DIR  = '/kaggle/input/signature-detection-dataset/images'\nIMAGE_DIR = '/kaggle/images' # directory to save images\nLABEL_DIR = '/kaggle/labels' # directory to save labels","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:14:49.394906Z","iopub.execute_input":"2024-04-14T01:14:49.395799Z","iopub.status.idle":"2024-04-14T01:14:49.401470Z","shell.execute_reply.started":"2024-04-14T01:14:49.395766Z","shell.execute_reply":"2024-04-14T01:14:49.400389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Create Directories","metadata":{}},{"cell_type":"code","source":"!mkdir -p {IMAGE_DIR}\n!mkdir -p {LABEL_DIR}\n","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:14:54.877613Z","iopub.execute_input":"2024-04-14T01:14:54.877989Z","iopub.status.idle":"2024-04-14T01:14:56.829561Z","shell.execute_reply.started":"2024-04-14T01:14:54.877960Z","shell.execute_reply":"2024-04-14T01:14:56.828295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p {IMAGE_DIR}_test\n","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:15:58.909909Z","iopub.execute_input":"2024-04-14T01:15:58.910619Z","iopub.status.idle":"2024-04-14T01:15:59.876166Z","shell.execute_reply.started":"2024-04-14T01:15:58.910588Z","shell.execute_reply":"2024-04-14T01:15:59.874781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:15:07.963517Z","iopub.execute_input":"2024-04-14T01:15:07.963885Z","iopub.status.idle":"2024-04-14T01:15:07.968792Z","shell.execute_reply.started":"2024-04-14T01:15:07.963857Z","shell.execute_reply":"2024-04-14T01:15:07.967848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"glob.glob('/kaggle/*')","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:16:02.524905Z","iopub.execute_input":"2024-04-14T01:16:02.525815Z","iopub.status.idle":"2024-04-14T01:16:02.533333Z","shell.execute_reply.started":"2024-04-14T01:16:02.525767Z","shell.execute_reply":"2024-04-14T01:16:02.532291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"glob.glob('/kaggle/input/signature-detection-dataset/images/*.csv')","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:15:11.724181Z","iopub.execute_input":"2024-04-14T01:15:11.725045Z","iopub.status.idle":"2024-04-14T01:15:11.947458Z","shell.execute_reply.started":"2024-04-14T01:15:11.725012Z","shell.execute_reply":"2024-04-14T01:15:11.946484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(f'{ROOT_DIR}/Train_data.csv', names=['name', 'label', 'x_min', 'y_min', 'x_max', 'y_max'])\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:16:09.716723Z","iopub.execute_input":"2024-04-14T01:16:09.717098Z","iopub.status.idle":"2024-04-14T01:16:09.747927Z","shell.execute_reply.started":"2024-04-14T01:16:09.717071Z","shell.execute_reply":"2024-04-14T01:16:09.746942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv(f'{ROOT_DIR}/Test_data.csv', names=['name', 'label', 'x_min', 'y_min', 'x_max', 'y_max'])\ndf_test.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:16:13.999379Z","iopub.execute_input":"2024-04-14T01:16:14.000313Z","iopub.status.idle":"2024-04-14T01:16:14.021390Z","shell.execute_reply.started":"2024-04-14T01:16:14.000280Z","shell.execute_reply":"2024-04-14T01:16:14.020386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['annotations'] = df[['x_min', 'y_min', 'x_max', 'y_max']].apply(lambda row: [row['x_min'], row['y_min'], row['x_max'], row['y_max']], axis=1)\n\n# Drop the individual coordinate columns\ndf = df.drop(['x_min', 'y_min', 'x_max', 'y_max', 'label'], axis=1)\n\ndf['name'] = df['name'].str.replace('.tif', '')\n\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:16:17.296059Z","iopub.execute_input":"2024-04-14T01:16:17.296453Z","iopub.status.idle":"2024-04-14T01:16:17.342797Z","shell.execute_reply.started":"2024-04-14T01:16:17.296421Z","shell.execute_reply":"2024-04-14T01:16:17.341831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['annotations'] = df_test[['x_min', 'y_min', 'x_max', 'y_max']].apply(lambda row: [row['x_min'], row['y_min'], row['x_max'], row['y_max']], axis=1)\n\n# Drop the individual coordinate columns\ndf_test = df_test.drop(['x_min', 'y_min', 'x_max', 'y_max', 'label'], axis=1)\n\ndf_test['name'] = df_test['name'].str.replace('.tif', '')\n\ndf_test.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:16:20.509996Z","iopub.execute_input":"2024-04-14T01:16:20.510783Z","iopub.status.idle":"2024-04-14T01:16:20.530249Z","shell.execute_reply.started":"2024-04-14T01:16:20.510749Z","shell.execute_reply":"2024-04-14T01:16:20.529259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Get Paths","metadata":{}},{"cell_type":"code","source":"# Train Data\ndf['old_image_path'] = f'{ROOT_DIR}/'+df.name.astype(str)+'.tif'\ndf['image_path']  = f'{IMAGE_DIR}/'+df.name.astype(str)+'.tif'\ndf['old_label_path']  = f'/kaggle/input/signature-detection-dataset/images/TrainGroundTruth/'+df.name.astype(str)+'.txt'\ndf['label_path']  = f'{LABEL_DIR}/'+df.name.astype(str)+'.txt'\n\n# df['annotations'] = df['annotations'].progress_apply(eval)\ndisplay(df.head(4))","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:16:51.653768Z","iopub.execute_input":"2024-04-14T01:16:51.654755Z","iopub.status.idle":"2024-04-14T01:16:51.675013Z","shell.execute_reply.started":"2024-04-14T01:16:51.654721Z","shell.execute_reply":"2024-04-14T01:16:51.673910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Test Data\ndf_test['old_image_path'] = f'{ROOT_DIR}/'+df_test.name.astype(str)+'.tif'\ndf_test['image_path']  = f'{IMAGE_DIR}_test/'+df_test.name.astype(str)+'.tif'\ndf_test['old_label_path']  = f'/kaggle/input/signature-detection-dataset/images/TestGroundTruth/'+df_test.name.astype(str)+'.txt'\ndf_test['label_path']  = f'{LABEL_DIR}/'+df_test.name.astype(str)+'.txt'\n\n# df['annotations'] = df['annotations'].progress_apply(eval)\ndf_test.head(4)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:04.254821Z","iopub.execute_input":"2024-04-14T01:17:04.255184Z","iopub.status.idle":"2024-04-14T01:17:04.274371Z","shell.execute_reply.started":"2024-04-14T01:17:04.255157Z","shell.execute_reply":"2024-04-14T01:17:04.273307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['label_path'][0]","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:20.760638Z","iopub.execute_input":"2024-04-14T01:17:20.761046Z","iopub.status.idle":"2024-04-14T01:17:20.767610Z","shell.execute_reply.started":"2024-04-14T01:17:20.761014Z","shell.execute_reply":"2024-04-14T01:17:20.766681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🧹 Clean Data\n","metadata":{}},{"cell_type":"markdown","source":"# ✏️ Write Images\n* We need to copy the Images to Current Directory(`/kaggle/working`) as `/kaggle/input` doesn't have **write access** which is needed for **YOLOv5**.\n* We can make this process faster using **Joblib** which uses **Parallel** computing.","metadata":{}},{"cell_type":"code","source":"def make_copy(row):\n    shutil.copyfile(row.old_image_path, row.image_path)\n    return","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:23.741324Z","iopub.execute_input":"2024-04-14T01:17:23.742239Z","iopub.status.idle":"2024-04-14T01:17:23.746678Z","shell.execute_reply.started":"2024-04-14T01:17:23.742204Z","shell.execute_reply":"2024-04-14T01:17:23.745633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_paths = df.old_image_path.tolist()\n_ = Parallel(n_jobs=-1, backend='threading')(delayed(make_copy)(row) for _, row in tqdm(df.iterrows(), total=len(df)))","metadata":{"scrolled":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-04-14T01:17:31.968859Z","iopub.execute_input":"2024-04-14T01:17:31.969249Z","iopub.status.idle":"2024-04-14T01:17:33.446918Z","shell.execute_reply.started":"2024-04-14T01:17:31.969218Z","shell.execute_reply":"2024-04-14T01:17:33.446117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_paths_test = df_test.old_image_path.tolist()\n_ = Parallel(n_jobs=-1, backend='threading')(delayed(make_copy)(row) for _, row in tqdm(df_test.iterrows(), total=len(df_test)))","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:34.758638Z","iopub.execute_input":"2024-04-14T01:17:34.759553Z","iopub.status.idle":"2024-04-14T01:17:35.025718Z","shell.execute_reply.started":"2024-04-14T01:17:34.759518Z","shell.execute_reply":"2024-04-14T01:17:35.024817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🔨 Helper","metadata":{}},{"cell_type":"code","source":"# check https://github.com/awsaf49/bbox for source code of following utility functions\nfrom bbox.utils import coco2yolo, coco2voc, voc2yolo\nfrom bbox.utils import draw_bboxes, load_image\nfrom bbox.utils import clip_bbox, str2annot, annot2str","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:40.578988Z","iopub.execute_input":"2024-04-14T01:17:40.579361Z","iopub.status.idle":"2024-04-14T01:17:41.260488Z","shell.execute_reply.started":"2024-04-14T01:17:40.579333Z","shell.execute_reply":"2024-04-14T01:17:41.259575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_bbox(path):\n    bboxes = []\n    with open(path, 'r') as f:\n        for line in f:\n            line_split = line.strip().split(',')\n            (x1, y1, x2, y2) = line_split\n#             bbox = {'x1': int(x1), 'x2': int(x2), 'y1': int(y1), 'y2': int(y2)}\n            bbox = [int(x1), int(x2), int(y1), int(y2)]\n\n            bboxes.append(bbox)\n    return bboxes\n\ndef get_imgsize(row):\n    row['width'], row['height'] = imagesize.get(row['image_path'])\n    return row\n\nnp.random.seed(32)\ncolors = [(np.random.randint(255), np.random.randint(255), np.random.randint(255))\\\n          for idx in range(1)]","metadata":{"_kg_hide-input":false,"execution":{"iopub.status.busy":"2024-04-14T01:17:45.191770Z","iopub.execute_input":"2024-04-14T01:17:45.192350Z","iopub.status.idle":"2024-04-14T01:17:45.200136Z","shell.execute_reply.started":"2024-04-14T01:17:45.192318Z","shell.execute_reply":"2024-04-14T01:17:45.199105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Create BBox","metadata":{}},{"cell_type":"code","source":"df['bboxes'] = df.old_label_path.progress_apply(get_bbox)\ndf.head(2)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:47.449167Z","iopub.execute_input":"2024-04-14T01:17:47.450021Z","iopub.status.idle":"2024-04-14T01:17:51.301079Z","shell.execute_reply.started":"2024-04-14T01:17:47.449991Z","shell.execute_reply":"2024-04-14T01:17:51.300068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['num_bbox'] = df.bboxes.progress_apply(lambda x : len(x))","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:52.328201Z","iopub.execute_input":"2024-04-14T01:17:52.328584Z","iopub.status.idle":"2024-04-14T01:17:52.353102Z","shell.execute_reply.started":"2024-04-14T01:17:52.328554Z","shell.execute_reply":"2024-04-14T01:17:52.352162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['bboxes'] = df_test.old_label_path.progress_apply(get_bbox)\ndf_test.head(2)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:17:55.773353Z","iopub.execute_input":"2024-04-14T01:17:55.773741Z","iopub.status.idle":"2024-04-14T01:17:56.393653Z","shell.execute_reply.started":"2024-04-14T01:17:55.773713Z","shell.execute_reply":"2024-04-14T01:17:56.392596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Get Image-Size\n> All Images have same dimension, [Width, Height] =  `[1000, 1000]`","metadata":{}},{"cell_type":"code","source":"df['width']  = 1000\ndf['height'] = 1000\ndisplay(df.head(2))","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:18:04.305865Z","iopub.execute_input":"2024-04-14T01:18:04.306279Z","iopub.status.idle":"2024-04-14T01:18:04.325024Z","shell.execute_reply.started":"2024-04-14T01:18:04.306247Z","shell.execute_reply":"2024-04-14T01:18:04.323902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['width']  = 1000\ndf_test['height'] = 1000\ndf_test.head(2)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:18:07.173588Z","iopub.execute_input":"2024-04-14T01:18:07.173985Z","iopub.status.idle":"2024-04-14T01:18:07.192151Z","shell.execute_reply.started":"2024-04-14T01:18:07.173955Z","shell.execute_reply":"2024-04-14T01:18:07.191260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🏷️ Create Labels\nWe need to export our labels to **YOLO** format, with one `*.txt` file per image (if no objects in image, no `*.txt` file is required). The *.txt file specifications are:\n\n* One row per object\n* Each row is class `[x_center, y_center, width, height]` format.\n* Box coordinates must be in **normalized** `xywh` format (from `0 - 1`). If your boxes are in pixels, divide `x_center` and `width` by `image width`, and `y_center` and `height` by `image height`.\n* Class numbers are **zero-indexed** (start from `0`).\n\n\n","metadata":{}},{"cell_type":"code","source":"cnt = 0\nall_bboxes = []\nbboxes_info = []\nfor row_idx in tqdm(range(df.shape[0])):\n    row = df.iloc[row_idx]\n    image_height = row.height\n    image_width  = row.width\n    bboxes_voc  = np.array(row.bboxes).astype(np.float32).copy()\n\n#     print(bboxes_voc.shape)\n#     print(bboxes_voc[0])\n#     print(bboxes_voc[1])\n\n    tmp = bboxes_voc[:,1].copy()\n    bboxes_voc[:, 1] = bboxes_voc[:,2]\n    bboxes_voc[:,2] = tmp\n#     print(bboxes_voc[0])\n#     print(bboxes_voc[1])\n\n#     break\n    num_bbox     = len(bboxes_voc)\n    names        = ['sig']*num_bbox\n    labels       = np.array([0]*num_bbox)[..., None].astype(str)\n    ## Create Annotation(YOLO)\n    with open(row.label_path, 'w') as f:\n        if num_bbox<1:\n            annot = ''\n            f.write(annot)\n            cnt+=1\n            continue\n#         bboxes_voc  = coco2voc(bboxes_coco, image_height, image_width)\n        bboxes_voc  = clip_bbox(bboxes_voc, image_height, image_width)\n        bboxes_yolo = voc2yolo(bboxes_voc, image_height, image_width).astype(str)\n        all_bboxes.extend(bboxes_yolo.astype(float))\n        bboxes_info.extend([[row.name]]*len(bboxes_yolo))\n        annots = np.concatenate([labels, bboxes_yolo], axis=1)\n        string = annot2str(annots)\n        f.write(string)\nprint('Missing:',cnt)","metadata":{"_kg_hide-input":false,"execution":{"iopub.status.busy":"2024-04-14T01:20:41.515108Z","iopub.execute_input":"2024-04-14T01:20:41.515897Z","iopub.status.idle":"2024-04-14T01:20:41.804653Z","shell.execute_reply.started":"2024-04-14T01:20:41.515864Z","shell.execute_reply":"2024-04-14T01:20:41.803654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 📁 Create Folds\n> Number of samples aren't same in each fold which can create large variance in **Cross-Validation**.","metadata":{}},{"cell_type":"code","source":"# from sklearn.model_selection import GroupKFold\n# kf = GroupKFold(n_splits = 3)\n# df = df.reset_index(drop=True)\n# df['fold'] = -1\n# for fold, (train_idx, val_idx) in enumerate(kf.split(df, groups=df.name.tolist())):\n#     df.loc[val_idx, 'fold'] = fold\n# display(df.fold.value_counts())","metadata":{"execution":{"iopub.status.busy":"2024-04-13T22:29:49.882505Z","iopub.status.idle":"2024-04-13T22:29:49.882893Z","shell.execute_reply.started":"2024-04-13T22:29:49.882674Z","shell.execute_reply":"2024-04-13T22:29:49.882704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ⭕ BBox Distribution","metadata":{}},{"cell_type":"code","source":"bbox_df = pd.DataFrame(np.concatenate([bboxes_info, all_bboxes], axis=1),\n             columns=['name',\n                     'xmid','ymid','w','h'])\nbbox_df[['xmid','ymid','w','h']] = bbox_df[['xmid','ymid','w','h']].astype(float)\nbbox_df['area'] = bbox_df.w * bbox_df.h * 1000 * 1000\nbbox_df.name = bbox_df.name.astype(str)\nbbox_df = bbox_df.merge(df[['name']], on='name', how='left')\nbbox_df.fold = 0\nbbox_df.head(2)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:20:44.743274Z","iopub.execute_input":"2024-04-14T01:20:44.744194Z","iopub.status.idle":"2024-04-14T01:20:44.768564Z","shell.execute_reply.started":"2024-04-14T01:20:44.744160Z","shell.execute_reply":"2024-04-14T01:20:44.767483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cnt = 0\nall_bboxes_test = []\nbboxes_info_test = []\nfor row_idx in tqdm(range(df_test.shape[0])):\n    row = df_test.iloc[row_idx]\n    image_height = row.height\n    image_width  = row.width\n    bboxes_voc  = np.array(row.bboxes).astype(np.float32).copy()\n\n#     print(bboxes_voc.shape)\n#     print(bboxes_voc[0])\n#     print(bboxes_voc[1])\n\n    tmp = bboxes_voc[:,1].copy()\n    bboxes_voc[:, 1] = bboxes_voc[:,2]\n    bboxes_voc[:,2] = tmp\n#     print(bboxes_voc[0])\n#     print(bboxes_voc[1])\n\n#     break\n    num_bbox     = len(bboxes_voc)\n    names        = ['sig']*num_bbox\n    labels       = np.array([0]*num_bbox)[..., None].astype(str)\n    ## Create Annotation(YOLO)\n    with open(row.label_path, 'w') as f:\n        if num_bbox<1:\n            annot = ''\n            f.write(annot)\n            cnt+=1\n            continue\n#         bboxes_voc  = coco2voc(bboxes_coco, image_height, image_width)\n        bboxes_voc  = clip_bbox(bboxes_voc, image_height, image_width)\n        bboxes_yolo = voc2yolo(bboxes_voc, image_height, image_width).astype(str)\n        all_bboxes_test.extend(bboxes_yolo.astype(float))\n        bboxes_info_test.extend([[row.name]]*len(bboxes_yolo))\n        annots = np.concatenate([labels, bboxes_yolo], axis=1)\n        string = annot2str(annots)\n        f.write(string)\nprint('Missing:',cnt)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:20:46.521324Z","iopub.execute_input":"2024-04-14T01:20:46.521749Z","iopub.status.idle":"2024-04-14T01:20:46.592364Z","shell.execute_reply.started":"2024-04-14T01:20:46.521719Z","shell.execute_reply":"2024-04-14T01:20:46.591366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bbox_df_test = pd.DataFrame(np.concatenate([bboxes_info_test, all_bboxes_test], axis=1),\n             columns=['name',\n                     'xmid','ymid','w','h'])\nbbox_df_test[['xmid','ymid','w','h']] = bbox_df_test[['xmid','ymid','w','h']].astype(float)\nbbox_df_test['area'] = bbox_df_test.w * bbox_df_test.h * 1000 * 1000\nbbox_df_test.name = bbox_df_test.name.astype(str)\nbbox_df_test = bbox_df_test.merge(bbox_df_test[['name']], on='name', how='left')\n# bbox_df.fold = 0\nbbox_df_test.head(2)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:20:48.507208Z","iopub.execute_input":"2024-04-14T01:20:48.507562Z","iopub.status.idle":"2024-04-14T01:20:48.534861Z","shell.execute_reply.started":"2024-04-14T01:20:48.507536Z","shell.execute_reply":"2024-04-14T01:20:48.533771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bbox_df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:20:48.925527Z","iopub.execute_input":"2024-04-14T01:20:48.926259Z","iopub.status.idle":"2024-04-14T01:20:48.956449Z","shell.execute_reply.started":"2024-04-14T01:20:48.926226Z","shell.execute_reply":"2024-04-14T01:20:48.955340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## `x_center` Vs `y_center`","metadata":{}},{"cell_type":"code","source":"from scipy.stats import gaussian_kde\n\nall_bboxes = np.array(all_bboxes)\n\nx_val = all_bboxes[...,0]\ny_val = all_bboxes[...,1]\n\n# Calculate the point density\nxy = np.vstack([x_val,y_val])\nz = gaussian_kde(xy)(xy)\n\nfig, ax = plt.subplots(figsize = (10, 10))\n# ax.axis('off')\nax.scatter(x_val, y_val, c=z, s=100, cmap='viridis')\n# ax.set_xlabel('x_mid')\n# ax.set_ylabel('y_mid')\nplt.show()\n# print(len(all_bboxes))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:20:50.044008Z","iopub.execute_input":"2024-04-14T01:20:50.044783Z","iopub.status.idle":"2024-04-14T01:20:50.309636Z","shell.execute_reply.started":"2024-04-14T01:20:50.044751Z","shell.execute_reply":"2024-04-14T01:20:50.308580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## `width` Vs `height`","metadata":{}},{"cell_type":"code","source":"x_val = all_bboxes[...,2]\ny_val = all_bboxes[...,3]\n\n# Calculate the point density\nxy = np.vstack([x_val,y_val])\nz = gaussian_kde(xy)(xy)\n\nfig, ax = plt.subplots(figsize = (10, 10))\n# ax.axis('off')\nax.scatter(x_val, y_val, c=z, s=100, cmap='viridis')\n# ax.set_xlabel('bbox_width')\n# ax.set_ylabel('bbox_height')\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:20:57.488378Z","iopub.execute_input":"2024-04-14T01:20:57.488758Z","iopub.status.idle":"2024-04-14T01:20:57.752541Z","shell.execute_reply.started":"2024-04-14T01:20:57.488731Z","shell.execute_reply":"2024-04-14T01:20:57.751606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Area","metadata":{}},{"cell_type":"code","source":"import matplotlib as mpl\nimport seaborn as sns\n\nf, ax = plt.subplots(figsize=(12, 6))\nsns.despine(f)\n\nsns.histplot(\n    bbox_df,\n    x=\"area\",\n    multiple=\"stack\",\n    palette=\"viridis\",\n    edgecolor=\".3\",\n    linewidth=.5,\n    log_scale=True,\n)\nax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())\nax.set_xticks([500, 1000, 2000, 5000, 10000]);","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:21:01.335292Z","iopub.execute_input":"2024-04-14T01:21:01.336171Z","iopub.status.idle":"2024-04-14T01:21:01.732331Z","shell.execute_reply.started":"2024-04-14T01:21:01.336141Z","shell.execute_reply":"2024-04-14T01:21:01.731342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🌈 Visualization","metadata":{}},{"cell_type":"code","source":"df2 = df[(df.num_bbox>0)].sample(100) # takes samples with bbox\ny = 3; x = 2\nplt.figure(figsize=(12.8*x, 7.2*y))\nfor idx in range(x*y):\n    row = df2.iloc[idx]\n    img           = load_image(row.image_path)\n    image_height  = row.height\n    image_width   = row.width\n    with open(row.label_path) as f:\n        annot = str2annot(f.read())\n    bboxes_yolo = annot[...,1:]\n    labels      = annot[..., 0].astype(int).tolist()\n    names         = ['sig']*len(bboxes_yolo)\n    plt.subplot(y, x, idx+1)\n    plt.imshow(draw_bboxes(img = img,\n                           bboxes = bboxes_yolo, \n                           classes = names,\n                           class_ids = labels,\n                           class_name = True, \n                           colors = colors, \n                           bbox_format = 'yolo',\n                           line_thickness = 2))\n    plt.axis('OFF')\nplt.tight_layout()\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:21:04.883947Z","iopub.execute_input":"2024-04-14T01:21:04.884917Z","iopub.status.idle":"2024-04-14T01:21:06.558287Z","shell.execute_reply.started":"2024-04-14T01:21:04.884882Z","shell.execute_reply":"2024-04-14T01:21:06.557427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🍚 Dataset","metadata":{}},{"cell_type":"code","source":"df['fold'] = 1\nfold_indices = df.sample(frac=0.2).index\ndf.loc[fold_indices, 'fold'] = 0\n","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:21:12.015489Z","iopub.execute_input":"2024-04-14T01:21:12.016331Z","iopub.status.idle":"2024-04-14T01:21:12.024324Z","shell.execute_reply.started":"2024-04-14T01:21:12.016301Z","shell.execute_reply":"2024-04-14T01:21:12.023466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_files = []\nval_files   = []\ntrain_df = df.query(\"fold!=@FOLD\")\nvalid_df = df.query(\"fold==@FOLD\")\ntrain_files += list(train_df.image_path.unique())\nval_files += list(valid_df.image_path.unique())\nlen(train_files), len(val_files)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:21:14.394293Z","iopub.execute_input":"2024-04-14T01:21:14.394959Z","iopub.status.idle":"2024-04-14T01:21:14.416046Z","shell.execute_reply.started":"2024-04-14T01:21:14.394927Z","shell.execute_reply":"2024-04-14T01:21:14.414996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ⚙️ Configuration\nThe dataset config file requires\n1. The dataset root directory path and relative paths to `train / val / test` image directories (or *.txt files with image paths)\n2. The number of classes `nc` and \n3. A list of class `names`:`['sig']`","metadata":{}},{"cell_type":"code","source":"import yaml\n\ncwd = '/kaggle/working/'\n\nwith open(os.path.join( cwd , 'train.txt'), 'w') as f:\n    for path in train_df.image_path.tolist():\n        f.write(path+'\\n')\n            \nwith open(os.path.join(cwd , 'val.txt'), 'w') as f:\n    for path in valid_df.image_path.tolist():\n        f.write(path+'\\n')\n\ndata = dict(\n    path  = '/kaggle/working',\n    train =  os.path.join( cwd , 'train.txt') ,\n    val   =  os.path.join( cwd , 'val.txt' ),\n    nc    = 1,\n    names = ['sig'],\n    )\n\nwith open(os.path.join( cwd , 'gbr.yaml'), 'w') as outfile:\n    yaml.dump(data, outfile, default_flow_style=False)\n\nf = open(os.path.join( cwd , 'gbr.yaml'), 'r')\nprint('\\nyaml:')\nprint(f.read())","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:21:22.347042Z","iopub.execute_input":"2024-04-14T01:21:22.347798Z","iopub.status.idle":"2024-04-14T01:21:22.359174Z","shell.execute_reply.started":"2024-04-14T01:21:22.347768Z","shell.execute_reply":"2024-04-14T01:21:22.358264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%writefile /kaggle/working/hyp.yaml\nlr0: 0.01  # initial learning rate (SGD=1E-2, Adam=1E-3)\nlrf: 0.1  # final OneCycleLR learning rate (lr0 * lrf)\nmomentum: 0.937  # SGD momentum/Adam beta1\nweight_decay: 0.0005  # optimizer weight decay 5e-4\nwarmup_epochs: 3.0  # warmup epochs (fractions ok)\nwarmup_momentum: 0.8  # warmup initial momentum\nwarmup_bias_lr: 0.1  # warmup initial bias lr\nbox: 0.05  # box loss gain\ncls: 0.5  # cls loss gain\ncls_pw: 1.0  # cls BCELoss positive_weight\nobj: 1.0  # obj loss gain (scale with pixels)\nobj_pw: 1.0  # obj BCELoss positive_weight\niou_t: 0.20  # IoU training threshold\nanchor_t: 4.0  # anchor-multiple threshold\n# anchors: 3  # anchors per output layer (0 to ignore)\nfl_gamma: 0.0  # focal loss gamma (efficientDet default gamma=1.5)\nhsv_h: 0.015  # image HSV-Hue augmentation (fraction)\nhsv_s: 0.7  # image HSV-Saturation augmentation (fraction)\nhsv_v: 0.4  # image HSV-Value augmentation (fraction)\ndegrees: 0.0  # image rotation (+/- deg)\ntranslate: 0.10  # image translation (+/- fraction)\nscale: 0.5  # image scale (+/- gain)\nshear: 0.0  # image shear (+/- deg)\nperspective: 0.0  # image perspective (+/- fraction), range 0-0.001\nflipud: 0.5  # image flip up-down (probability)\nfliplr: 0.5  # image flip left-right (probability)\nmosaic: 0.5  # image mosaic (probability)\nmixup: 0.5 # image mixup (probability)\ncopy_paste: 0.0  # segment copy-paste (probability)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:21:38.911427Z","iopub.execute_input":"2024-04-14T01:21:38.911802Z","iopub.status.idle":"2024-04-14T01:21:38.919303Z","shell.execute_reply.started":"2024-04-14T01:21:38.911775Z","shell.execute_reply":"2024-04-14T01:21:38.918396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!git clone https://github.com/ultralytics/yolov5.git # clone\n%cd yolov5\n%pip install -qr requirements.txt  # install\n\nimport torch\nimport utils\ndisplay = utils.notebook_init()  # checks","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:21:49.514428Z","iopub.execute_input":"2024-04-14T01:21:49.515273Z","iopub.status.idle":"2024-04-14T01:22:10.230848Z","shell.execute_reply.started":"2024-04-14T01:21:49.515244Z","shell.execute_reply":"2024-04-14T01:22:10.229852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = YOLO('yolov8x.pt')\n","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:46:20.429319Z","iopub.execute_input":"2024-04-14T01:46:20.430266Z","iopub.status.idle":"2024-04-14T01:46:20.622178Z","shell.execute_reply.started":"2024-04-14T01:46:20.430223Z","shell.execute_reply":"2024-04-14T01:46:20.621306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # model.train()\n# model.train(data = \"/kaggle/working/gbr.yaml\",\n#             epochs = 3,\n#             seed = 23,\n#             batch = 8,\n#             workers = 8)","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:46:35.535908Z","iopub.execute_input":"2024-04-14T01:46:35.536311Z","iopub.status.idle":"2024-04-14T01:46:35.541708Z","shell.execute_reply.started":"2024-04-14T01:46:35.536278Z","shell.execute_reply":"2024-04-14T01:46:35.540733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🚅 Training","metadata":{}},{"cell_type":"code","source":"!python train.py --img {DIM}\\\n--batch {BATCH}\\\n--epochs 5\\\n--optimizer {OPTMIZER}\\\n--data /kaggle/working/gbr.yaml\\\n# --hyp /kaggle/working/hyp.yaml\\\n--weights {MODEL}.pt\\\n--project {PROJECT} --name {NAME} --entity ml-colabs\\\n--exist-ok","metadata":{"_kg_hide-output":false,"execution":{"iopub.status.busy":"2024-04-14T01:29:01.129283Z","iopub.execute_input":"2024-04-14T01:29:01.130091Z","iopub.status.idle":"2024-04-14T01:37:40.519125Z","shell.execute_reply.started":"2024-04-14T01:29:01.130057Z","shell.execute_reply":"2024-04-14T01:37:40.517877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Output Files","metadata":{}},{"cell_type":"code","source":"glob.glob('runs/train/exp/*/*')","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:42:12.291736Z","iopub.execute_input":"2024-04-14T01:42:12.292159Z","iopub.status.idle":"2024-04-14T01:42:12.300109Z","shell.execute_reply.started":"2024-04-14T01:42:12.292125Z","shell.execute_reply":"2024-04-14T01:42:12.299150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"OUTPUT_DIR = 'runs/train/exp/'\n# OUTPUT_DIR = '{}/{}'.format(PROJECT, NAME)\n!ls {OUTPUT_DIR}","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:39:24.184979Z","iopub.execute_input":"2024-04-14T01:39:24.185811Z","iopub.status.idle":"2024-04-14T01:39:25.193825Z","shell.execute_reply.started":"2024-04-14T01:39:24.185770Z","shell.execute_reply":"2024-04-14T01:39:25.192720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 📈 Class Distribution","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize = (10,10))\nplt.axis('off')\nplt.imshow(plt.imread(f'{OUTPUT_DIR}/labels_correlogram.jpg'));","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:39:30.250180Z","iopub.execute_input":"2024-04-14T01:39:30.250762Z","iopub.status.idle":"2024-04-14T01:39:31.222524Z","shell.execute_reply.started":"2024-04-14T01:39:30.250723Z","shell.execute_reply":"2024-04-14T01:39:31.221570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (10,10))\nplt.axis('off')\nplt.imshow(plt.imread(f'{OUTPUT_DIR}/labels.jpg'));","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:39:36.662908Z","iopub.execute_input":"2024-04-14T01:39:36.663279Z","iopub.status.idle":"2024-04-14T01:39:37.370592Z","shell.execute_reply.started":"2024-04-14T01:39:36.663250Z","shell.execute_reply":"2024-04-14T01:39:37.369562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🔭 Batch Image","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize = (10, 10))\nplt.imshow(plt.imread(f'{OUTPUT_DIR}/train_batch0.jpg'))\n\nplt.figure(figsize = (10, 10))\nplt.imshow(plt.imread(f'{OUTPUT_DIR}/train_batch1.jpg'))\n\nplt.figure(figsize = (10, 10))\nplt.imshow(plt.imread(f'{OUTPUT_DIR}/train_batch2.jpg'))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:39:51.246195Z","iopub.execute_input":"2024-04-14T01:39:51.246614Z","iopub.status.idle":"2024-04-14T01:39:54.368537Z","shell.execute_reply.started":"2024-04-14T01:39:51.246582Z","shell.execute_reply":"2024-04-14T01:39:54.367563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## GT Vs Pred","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(3, 2, figsize = (2*9,3*5), constrained_layout = True)\nfor row in range(3):\n    ax[row][0].imshow(plt.imread(f'{OUTPUT_DIR}/val_batch{row}_labels.jpg'))\n    ax[row][0].set_xticks([])\n    ax[row][0].set_yticks([])\n    ax[row][0].set_title(f'{OUTPUT_DIR}/val_batch{row}_labels.jpg', fontsize = 12)\n    \n    ax[row][1].imshow(plt.imread(f'{OUTPUT_DIR}/val_batch{row}_pred.jpg'))\n    ax[row][1].set_xticks([])\n    ax[row][1].set_yticks([])\n    ax[row][1].set_title(f'{OUTPUT_DIR}/val_batch{row}_pred.jpg', fontsize = 12)\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:40:10.197615Z","iopub.execute_input":"2024-04-14T01:40:10.198124Z","iopub.status.idle":"2024-04-14T01:40:13.642203Z","shell.execute_reply.started":"2024-04-14T01:40:10.198084Z","shell.execute_reply":"2024-04-14T01:40:13.641143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 🔍 Result","metadata":{}},{"cell_type":"markdown","source":"## Score Vs Epoch","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(30,15))\nplt.axis('off')\nplt.imshow(plt.imread(f'{OUTPUT_DIR}/results.png'));","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:40:31.260864Z","iopub.execute_input":"2024-04-14T01:40:31.261250Z","iopub.status.idle":"2024-04-14T01:40:32.843605Z","shell.execute_reply.started":"2024-04-14T01:40:31.261219Z","shell.execute_reply":"2024-04-14T01:40:32.842725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Confusion Matrix","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(12,10))\nplt.axis('off')\nplt.imshow(plt.imread(f'{OUTPUT_DIR}/confusion_matrix.png'));","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:40:38.488266Z","iopub.execute_input":"2024-04-14T01:40:38.489171Z","iopub.status.idle":"2024-04-14T01:40:40.115979Z","shell.execute_reply.started":"2024-04-14T01:40:38.489137Z","shell.execute_reply":"2024-04-14T01:40:40.114930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Metrics","metadata":{}},{"cell_type":"code","source":"for metric in ['F1', 'PR', 'P', 'R']:\n    print(f'Metric: {metric}')\n    plt.figure(figsize=(12,10))\n    plt.axis('off')\n    plt.imshow(plt.imread(f'{OUTPUT_DIR}/{metric}_curve.png'));\n    plt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-04-14T01:40:49.313904Z","iopub.execute_input":"2024-04-14T01:40:49.314248Z","iopub.status.idle":"2024-04-14T01:40:52.122466Z","shell.execute_reply.started":"2024-04-14T01:40:49.314225Z","shell.execute_reply":"2024-04-14T01:40:52.121330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Test data","metadata":{}},{"cell_type":"code","source":"!python  detect.py --weights 'runs/train/exp/weights/best.pt' --source /kaggle/images_test/ \\\n# --data /kaggle/working/gbr.yaml\\\n# --weights {MODEL}.pt\\\n# --project {PROJECT} --name test \\\n--classes 1\\\n--imgsz 1000\\\n--exist-ok","metadata":{"execution":{"iopub.status.busy":"2024-04-14T01:44:40.094110Z","iopub.execute_input":"2024-04-14T01:44:40.094733Z","iopub.status.idle":"2024-04-14T01:44:53.999485Z","shell.execute_reply.started":"2024-04-14T01:44:40.094691Z","shell.execute_reply":"2024-04-14T01:44:53.998303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}