{"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":"import warnings\nimport os\nimport cv2\n\nimport glob\nimport shutil\nimport sys\nimport torch\nfrom PIL import Image\nimport matplotlib.pyplot as plt\nwarnings.filterwarnings(\"ignore\")\nimport numpy as np\nfrom tqdm.notebook import tqdm\ntqdm.pandas()\nimport pandas as pd\n\nfrom tqdm.notebook import tqdm\n\nimport ast\nsys.path.append('../input/ensemble-boxes-104/ensemble_boxes-1.0.4')\nfrom ensemble_boxes import *","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:31:50.764539Z","iopub.execute_input":"2022-02-13T00:31:50.765491Z","iopub.status.idle":"2022-02-13T00:31:53.073232Z","shell.execute_reply.started":"2022-02-13T00:31:50.765365Z","shell.execute_reply":"2022-02-13T00:31:53.072378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p /root/.config/Ultralytics\n!cp /kaggle/input/yolo-arial/Arial.ttf /root/.config/Ultralytics/","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:31:53.075863Z","iopub.execute_input":"2022-02-13T00:31:53.076375Z","iopub.status.idle":"2022-02-13T00:31:54.569762Z","shell.execute_reply.started":"2022-02-13T00:31:53.076337Z","shell.execute_reply":"2022-02-13T00:31:54.568564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Yolov5x","metadata":{}},{"cell_type":"code","source":"def voc2yolo(bboxes, image_height=720, image_width=1280):\n    \"\"\"\n    voc  => [x1, y1, x2, y1]\n    yolo => [xmid, ymid, w, h] (normalized)\n    \"\"\"\n    bboxes = bboxes.copy().astype(float) # otherwise all value will be 0 as voc_pascal dtype is np.int\n    bboxes[..., [0, 2]] = bboxes[..., [0, 2]]/ image_width\n    bboxes[..., [1, 3]] = bboxes[..., [1, 3]]/ image_height\n    w = bboxes[..., 2] - bboxes[..., 0]\n    h = bboxes[..., 3] - bboxes[..., 1]\n    bboxes[..., 0] = bboxes[..., 0] + w/2\n    bboxes[..., 1] = bboxes[..., 1] + h/2\n    bboxes[..., 2] = w\n    bboxes[..., 3] = h\n    return bboxes\n\ndef yolo2voc(bboxes, image_height=720, image_width=1280):\n    \"\"\"\n    yolo => [xmid, ymid, w, h] (normalized)\n    voc  => [x1, y1, x2, y1]\n\n    \"\"\"\n    bboxes = bboxes.copy().astype(float) # otherwise all value will be 0 as voc_pascal dtype is np.int\n    bboxes[..., [0, 2]] = bboxes[..., [0, 2]]* image_width\n    bboxes[..., [1, 3]] = bboxes[..., [1, 3]]* image_height\n    bboxes[..., [0, 1]] = bboxes[..., [0, 1]] - bboxes[..., [2, 3]]/2\n    bboxes[..., [2, 3]] = bboxes[..., [0, 1]] + bboxes[..., [2, 3]]\n    return bboxes\n\ndef coco2yolo(bboxes, image_height=720, image_width=1280):\n    \"\"\"\n    coco => [xmin, ymin, w, h]\n    yolo => [xmid, ymid, w, h] (normalized)\n    \"\"\"\n    bboxes = bboxes.copy().astype(float) # otherwise all value will be 0 as voc_pascal dtype is np.int\n    # normolizinig\n    bboxes[..., [0, 2]]= bboxes[..., [0, 2]]/ image_width\n    bboxes[..., [1, 3]]= bboxes[..., [1, 3]]/ image_height\n    # converstion (xmin, ymin) => (xmid, ymid)\n    bboxes[..., [0, 1]] = bboxes[..., [0, 1]] + bboxes[..., [2, 3]]/2\n    return bboxes\n\ndef yolo2coco(bboxes, image_height=720, image_width=1280):\n    \"\"\"\n    yolo => [xmid, ymid, w, h] (normalized)\n    coco => [xmin, ymin, w, h]\n    \"\"\"\n    bboxes = bboxes.copy().astype(float) # otherwise all value will be 0 as voc_pascal dtype is np.int\n    # denormalizing\n    bboxes[..., [0, 2]]= bboxes[..., [0, 2]]* image_width\n    bboxes[..., [1, 3]]= bboxes[..., [1, 3]]* image_height\n    # converstion (xmid, ymid) => (xmin, ymin)\n    bboxes[..., [0, 1]] = bboxes[..., [0, 1]] - bboxes[..., [2, 3]]/2\n    return bboxes\n\ndef voc2coco(bboxes, image_height=720, image_width=1280):\n    bboxes  = voc2yolo(bboxes, image_height, image_width)\n    bboxes  = yolo2coco(bboxes, image_height, image_width)\n    return bboxes\n\ndef load_image(image_path):\n    return cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)\n\ndef plot_one_box(x, img, color=None, label=None, line_thickness=None):\n    # Plots one bounding box on image img\n    tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1  # line/font thickness\n    color = color or [random.randint(0, 255) for _ in range(3)]\n    c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))\n    cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)\n    if label:\n        tf = max(tl - 1, 1)  # font thickness\n        t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0]\n        c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3\n        cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA)  # filled\n        cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)\n\ndef draw_bboxes(img, bboxes, classes, class_ids, colors = None, show_classes = None, bbox_format = 'yolo', class_name = False, line_thickness = 2):\n\n    image = img.copy()\n    show_classes = classes if show_classes is None else show_classes\n    colors = (0, 255 ,0) if colors is None else colors\n\n    if bbox_format == 'yolo':\n\n        for idx in range(len(bboxes)):\n\n            bbox  = bboxes[idx]\n            cls   = classes[idx]\n            cls_id = class_ids[idx]\n            color = colors[cls_id] if type(colors) is list else colors\n\n            if cls in show_classes:\n\n                x1 = round(float(bbox[0])*image.shape[1])\n                y1 = round(float(bbox[1])*image.shape[0])\n                w  = round(float(bbox[2])*image.shape[1]/2) #w/2\n                h  = round(float(bbox[3])*image.shape[0]/2)\n\n                voc_bbox = (x1-w, y1-h, x1+w, y1+h)\n                plot_one_box(voc_bbox,\n                             image,\n                             color = color,\n                             label = cls if class_name else str(get_label(cls)),\n                             line_thickness = line_thickness)\n\n    elif bbox_format == 'coco':\n\n        for idx in range(len(bboxes)):\n\n            bbox  = bboxes[idx]\n            cls   = classes[idx]\n            cls_id = class_ids[idx]\n            color = colors[cls_id] if type(colors) is list else colors\n\n            if cls in show_classes:\n                x1 = int(round(bbox[0]))\n                y1 = int(round(bbox[1]))\n                w  = int(round(bbox[2]))\n                h  = int(round(bbox[3]))\n\n                voc_bbox = (x1, y1, x1+w, y1+h)\n                plot_one_box(voc_bbox,\n                             image,\n                             color = color,\n                             label = cls if class_name else str(cls_id),\n                             line_thickness = line_thickness)\n\n    elif bbox_format == 'voc_pascal':\n\n        for idx in range(len(bboxes)):\n\n            bbox  = bboxes[idx]\n            cls   = classes[idx]\n            cls_id = class_ids[idx]\n            color = colors[cls_id] if type(colors) is list else colors\n\n            if cls in show_classes:\n                x1 = int(round(bbox[0]))\n                y1 = int(round(bbox[1]))\n                x2 = int(round(bbox[2]))\n                y2 = int(round(bbox[3]))\n                voc_bbox = (x1, y1, x2, y2)\n                plot_one_box(voc_bbox,\n                             image,\n                             color = color,\n                             label = cls if class_name else str(cls_id),\n                             line_thickness = line_thickness)\n    else:\n        raise ValueError('wrong bbox format')\n\n    return image\n\ndef show_img(img, bboxes, bbox_format='yolo', bbox_colors = None):\n    names  = ['starfish']*len(bboxes)\n    labels = [0]*len(bboxes)\n    img    = draw_bboxes(img = img,\n                           bboxes = bboxes,\n                           classes = names,\n                           class_ids = labels,\n                           class_name = True,\n                           colors = colors if bbox_colors is None else bbox_colors,\n                           bbox_format = bbox_format,\n                           line_thickness = 2)\n    return Image.fromarray(img).resize((800, 400))\n\ndef get_bbox(annots):\n    bboxes = [list(annot.values()) for annot in annots]\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)]\n\n\ndef load_model(ckpt_path, conf=0.25, iou=0.50):\n    model = torch.hub.load('/kaggle/input/yolov5',\n                           'custom',\n                           path=ckpt_path,\n                           source='local',\n                           force_reload=True)  # local repo\n    model.conf = conf  # NMS confidence threshold\n    model.iou  = iou  # NMS IoU threshold\n    return model\n\ndef predict(model, img, size=768, augment=False):\n    height, width = img.shape[:2]\n    results = model(img, size=size, augment=augment)  # custom inference size\n    preds   = results.pandas().xyxy[0]\n    bboxes  = preds[['xmin','ymin','xmax','ymax']].values\n    if len(bboxes):\n        bboxes  = voc2coco(bboxes,height,width).astype(int)\n        confs   = preds.confidence.values\n        classes  = preds.name.values\n        return bboxes, confs,classes\n    else:\n        return [],[],[]\n\ndef format_prediction(bboxes, confs):\n    annot = ''\n    if len(bboxes)>0:\n        for idx in range(len(bboxes)):\n            xmin, ymin, w, h = bboxes[idx]\n            conf             = confs[idx]\n            annot += f'{conf} {xmin} {ymin} {w} {h}'\n            annot +=' '\n        annot = annot.strip(' ')\n    return annot\n\n","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:31:54.571281Z","iopub.execute_input":"2022-02-13T00:31:54.571541Z","iopub.status.idle":"2022-02-13T00:31:54.634657Z","shell.execute_reply.started":"2022-02-13T00:31:54.571507Z","shell.execute_reply":"2022-02-13T00:31:54.633801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ensemble","metadata":{}},{"cell_type":"code","source":"CKPT_PATH1 = '../input/greatbarrierreef/yolov5xexp6.pt'\nCONF1      = 0.29\nIOU1       = 0.40\nCKPT_PATH2 = '../input/greatbarrierreef/yolov5xver275.pt'\nCONF2      = 0.29\nIOU2       = 0.40\nCKPT_PATH3 = '../input/greatbarrierreef/yolov5xver28.pt'\nCONF3      = 0.29\nIOU3       = 0.40\n\nCKPT_PATH4 = '../input/greatbarrierreef/yolov5xfold0exp9.pt'\nCONF4      = 0.29\nIOU4       = 0.40\nCKPT_PATH5 = '../input/greatbarrierreef/yolov5xfold1exp7.pt'\nCONF5      = 0.29\nIOU5       = 0.40\nCKPT_PATH6 = '../input/greatbarrierreef/yolov5xfold2exp5.pt'\nCONF6      = 0.29\nIOU6       = 0.40\nCKPT_PATH7 = '../input/greatbarrierreef/yolov5xfold3exp8.pt'\nCONF7      = 0.29\nIOU7       = 0.40\nCKPT_PATH8 = '../input/greatbarrierreef/yolov5xfold4exp1.pt'\nCONF8      = 0.29\nIOU8       = 0.40\n\nCKPT_PATH9 = '../input/greatbarrierreef/fold0ver22.pt'\nCONF9      = 0.29\nIOU9       = 0.40\nCKPT_PATH10 = '../input/greatbarrierreef/fold1ver21.pt'\nCONF10      = 0.29\nIOU10       = 0.40\nCKPT_PATH11 = '../input/greatbarrierreef/fold2ver23.pt'\nCONF11      = 0.29\nIOU11       = 0.40\nCKPT_PATH12 = '../input/greatbarrierreef/fold3ver14.pt'\nCONF12      = 0.29\nIOU12       = 0.40\nCKPT_PATH13 = '../input/greatbarrierreef/fold4ver11.pt'\nCONF13      = 0.29\nIOU13       = 0.40\n\nCKPT_PATH14 = '../input/greatbarrierreef/fold0ver26v.pt'\nCONF14      = 0.29\nIOU14       = 0.40\nCKPT_PATH15 = '../input/greatbarrierreef/fold1ver25v.pt'\nCONF15      = 0.29\nIOU15       = 0.40\nCKPT_PATH16 = '../input/greatbarrierreef/fold2ver27v.pt'\nCONF16      = 0.29\nIOU16       = 0.40\n\n\nCKPT_PATH17 = '../input/greatbarrierreef/fold0ver19.pt'\nCONF17      = 0.29\nIOU17       = 0.40\nCKPT_PATH18 = '../input/greatbarrierreef/fold1ver17.pt'\nCONF18      = 0.29\nIOU18       = 0.40\nCKPT_PATH19 = '../input/greatbarrierreef/fold1ver20.pt'\nCONF19      = 0.29\nIOU19       = 0.40\nCKPT_PATH20 = '../input/greatbarrierreef/v5x_L9_HP_FP_RO_FOLD4.pt'\nCONF20      = 0.29\nIOU20       = 0.40\n\nCKPT_PATH21 = '../input/greatbarrierreef/yolov5xver29.pt'\nCONF21      = 0.29\nIOU21       = 0.40\nCKPT_PATH22 = '../input/greatbarrierreef/yolov5xver30.pt'\nCONF22      = 0.29\nIOU22       = 0.40\nCKPT_PATH23 = '../input/greatbarrierreef/yolov5xver31.pt'\nCONF23      = 0.29\nIOU23       = 0.40\nCKPT_PATH24 = '../input/greatbarrierreef/yolov5xver32.pt'\nCONF24      = 0.29\nIOU24       = 0.40\n\n\n#--------------------------------------------------------------------------\nmodel1 = load_model(CKPT_PATH1, conf=CONF1, iou=IOU1) \nmodel2 = load_model(CKPT_PATH2, conf=CONF2, iou=IOU2)\nmodel3 = load_model(CKPT_PATH3, conf=CONF3, iou=IOU3)\n\nmodel4 = load_model(CKPT_PATH4, conf=CONF4, iou=IOU4) \nmodel5 = load_model(CKPT_PATH5, conf=CONF5, iou=IOU5)\nmodel6 = load_model(CKPT_PATH6, conf=CONF6, iou=IOU6)\nmodel7 = load_model(CKPT_PATH7, conf=CONF7, iou=IOU7) \nmodel8 = load_model(CKPT_PATH8, conf=CONF8, iou=IOU8)\n\nmodel9 = load_model(CKPT_PATH9, conf=CONF9, iou=IOU9) \nmodel10 = load_model(CKPT_PATH10, conf=CONF10, iou=IOU10)\nmodel11 = load_model(CKPT_PATH11, conf=CONF11, iou=IOU11)\nmodel12 = load_model(CKPT_PATH12, conf=CONF12, iou=IOU12) \nmodel13 = load_model(CKPT_PATH13, conf=CONF13, iou=IOU13)\n\nmodel14 = load_model(CKPT_PATH14, conf=CONF14, iou=IOU14) \nmodel15 = load_model(CKPT_PATH15, conf=CONF15, iou=IOU15)\nmodel16 = load_model(CKPT_PATH16, conf=CONF16, iou=IOU16)\n\nmodel17 = load_model(CKPT_PATH17, conf=CONF17, iou=IOU17) \nmodel18 = load_model(CKPT_PATH18, conf=CONF18, iou=IOU18)\nmodel19 = load_model(CKPT_PATH19, conf=CONF19, iou=IOU19)\nmodel20 = load_model(CKPT_PATH20, conf=CONF20, iou=IOU20) \n\nmodel21 = load_model(CKPT_PATH21, conf=CONF21, iou=IOU21) \nmodel22 = load_model(CKPT_PATH22, conf=CONF22, iou=IOU22)\nmodel23 = load_model(CKPT_PATH23, conf=CONF23, iou=IOU23)\nmodel24 = load_model(CKPT_PATH24, conf=CONF24, iou=IOU24) \n","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:31:54.637495Z","iopub.execute_input":"2022-02-13T00:31:54.637773Z","iopub.status.idle":"2022-02-13T00:33:06.146473Z","shell.execute_reply.started":"2022-02-13T00:31:54.637736Z","shell.execute_reply":"2022-02-13T00:33:06.145717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Check","metadata":{}},{"cell_type":"code","source":"\nTEST_IMAGE_PATH = \"/kaggle/input/tensorflow-great-barrier-reef/train_images/video_2/5747.jpg\"\nimg = cv2.imread(TEST_IMAGE_PATH)\n#--------------------------------------------------------------------------\nIMG_SIZE  = 1280\nAUGMENT   = False\n#--------------------------------------------------------------------------\nbboxes1, scores1 ,bbclasses1  = predict(model1, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes2, scores2 ,bbclasses2  = predict(model2, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes3, scores3 ,bbclasses3  = predict(model3, img, size=IMG_SIZE, augment=AUGMENT)\n\nbboxes4, scores4 ,bbclasses4  = predict(model4, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes5, scores5 ,bbclasses5  = predict(model5, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes6, scores6 ,bbclasses6  = predict(model6, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes7, scores7 ,bbclasses7  = predict(model7, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes8, scores8 ,bbclasses8  = predict(model8, img, size=IMG_SIZE, augment=AUGMENT)\n\nbboxes9, scores9 ,bbclasses9  = predict(model9, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes10, scores10 ,bbclasses10  = predict(model10, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes11, scores11 ,bbclasses11  = predict(model11, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes12, scores12 ,bbclasses12  = predict(model12, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes13, scores13 ,bbclasses13  = predict(model13, img, size=IMG_SIZE, augment=AUGMENT)\n\nbboxes14, scores14 ,bbclasses14  = predict(model14, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes15, scores15 ,bbclasses15  = predict(model15, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes16, scores16 ,bbclasses16  = predict(model16, img, size=IMG_SIZE, augment=AUGMENT)\n\nbboxes17, scores17 ,bbclasses17  = predict(model17, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes18, scores18 ,bbclasses18  = predict(model18, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes19, scores19 ,bbclasses19  = predict(model19, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes20, scores20 ,bbclasses20  = predict(model20, img, size=IMG_SIZE, augment=AUGMENT)\n\nbboxes21, scores21 ,bbclasses21  = predict(model21, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes22, scores22 ,bbclasses22  = predict(model22, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes23, scores23 ,bbclasses23  = predict(model23, img, size=IMG_SIZE, augment=AUGMENT)\nbboxes24, scores24 ,bbclasses24  = predict(model24, img, size=IMG_SIZE, augment=AUGMENT)\n\n#--------------------------------------------------------------------------\nout_image=draw_bboxes(img = img,\n                        bboxes = bboxes1, \n                        classes = [\"model1\"]*len(bboxes1),\n                        class_ids = [0]*len(bboxes1),\n                        class_name = True, \n                        colors = (0,0,130), \n                        bbox_format = 'coco',\n                        line_thickness = 2)\nout_image=draw_bboxes(img = out_image,\n                        bboxes = bboxes2, \n                        classes = [\"    model2\"]*len(bboxes2),\n                        class_ids = [0]*len(bboxes2),\n                        class_name = True, \n                        colors = (0,130,0), \n                        bbox_format = 'coco',\n                        line_thickness = 2)\nout_image=draw_bboxes(img = out_image,\n                        bboxes = bboxes3, \n                        classes = [\"     model3\"]*len(bboxes3),\n                        class_ids = [0]*len(bboxes3),\n                        class_name = True, \n                        colors = (255,0,0), \n                        bbox_format = 'coco',\n                        line_thickness = 2)\n\nout_image = cv2.cvtColor(out_image, cv2.COLOR_BGR2RGB)\ndisplay(Image.fromarray(out_image))\n\n\n\n\nbboxes1[:, 2] = bboxes1[:, 2] + bboxes1[:, 0]\nbboxes1[:, 3] = bboxes1[:, 3] + bboxes1[:, 1]\nbboxes2[:, 2] = bboxes2[:, 2] + bboxes2[:, 0]\nbboxes2[:, 3] = bboxes2[:, 3] + bboxes2[:, 1]\nbboxes3[:, 2] = bboxes3[:, 2] + bboxes3[:, 0]\nbboxes3[:, 3] = bboxes3[:, 3] + bboxes3[:, 1]\n\nbboxes4[:, 2] = bboxes4[:, 2] + bboxes4[:, 0]\nbboxes4[:, 3] = bboxes4[:, 3] + bboxes4[:, 1]\nbboxes5[:, 2] = bboxes5[:, 2] + bboxes5[:, 0]\nbboxes5[:, 3] = bboxes5[:, 3] + bboxes5[:, 1]\nbboxes6[:, 2] = bboxes6[:, 2] + bboxes6[:, 0]\nbboxes6[:, 3] = bboxes6[:, 3] + bboxes6[:, 1]\nbboxes7[:, 2] = bboxes7[:, 2] + bboxes7[:, 0]\nbboxes7[:, 3] = bboxes7[:, 3] + bboxes7[:, 1]\nbboxes8[:, 2] = bboxes8[:, 2] + bboxes8[:, 0]\nbboxes8[:, 3] = bboxes8[:, 3] + bboxes8[:, 1]\n\nbboxes9[:, 2] = bboxes9[:, 2] + bboxes9[:, 0]\nbboxes9[:, 3] = bboxes9[:, 3] + bboxes9[:, 1]\nbboxes10[:, 2] = bboxes10[:, 2] + bboxes10[:, 0]\nbboxes10[:, 3] = bboxes10[:, 3] + bboxes10[:, 1]\nbboxes11[:, 2] = bboxes11[:, 2] + bboxes11[:, 0]\nbboxes11[:, 3] = bboxes11[:, 3] + bboxes11[:, 1]\nbboxes12[:, 2] = bboxes12[:, 2] + bboxes12[:, 0]\nbboxes12[:, 3] = bboxes12[:, 3] + bboxes12[:, 1]\nbboxes13[:, 2] = bboxes13[:, 2] + bboxes13[:, 0]\nbboxes13[:, 3] = bboxes13[:, 3] + bboxes13[:, 1]\n\nbboxes14[:, 2] = bboxes14[:, 2] + bboxes14[:, 0]\nbboxes14[:, 3] = bboxes14[:, 3] + bboxes14[:, 1]\nbboxes15[:, 2] = bboxes15[:, 2] + bboxes15[:, 0]\nbboxes15[:, 3] = bboxes15[:, 3] + bboxes15[:, 1]\nbboxes16[:, 2] = bboxes16[:, 2] + bboxes16[:, 0]\nbboxes16[:, 3] = bboxes16[:, 3] + bboxes16[:, 1]\n\nbboxes17[:, 2] = bboxes17[:, 2] + bboxes17[:, 0]\nbboxes17[:, 3] = bboxes17[:, 3] + bboxes17[:, 1]\nbboxes18[:, 2] = bboxes18[:, 2] + bboxes18[:, 0]\nbboxes18[:, 3] = bboxes18[:, 3] + bboxes18[:, 1]\nbboxes19[:, 2] = bboxes19[:, 2] + bboxes19[:, 0]\nbboxes19[:, 3] = bboxes19[:, 3] + bboxes19[:, 1]\nbboxes20[:, 2] = bboxes20[:, 2] + bboxes20[:, 0]\nbboxes20[:, 3] = bboxes20[:, 3] + bboxes20[:, 1]\n\nbboxes21[:, 2] = bboxes21[:, 2] + bboxes21[:, 0]\nbboxes21[:, 3] = bboxes21[:, 3] + bboxes21[:, 1]\nbboxes22[:, 2] = bboxes22[:, 2] + bboxes22[:, 0]\nbboxes22[:, 3] = bboxes22[:, 3] + bboxes22[:, 1]\nbboxes23[:, 2] = bboxes23[:, 2] + bboxes23[:, 0]\nbboxes23[:, 3] = bboxes23[:, 3] + bboxes23[:, 1]\nbboxes24[:, 2] = bboxes24[:, 2] + bboxes24[:, 0]\nbboxes24[:, 3] = bboxes24[:, 3] + bboxes24[:, 1]","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:06.148124Z","iopub.execute_input":"2022-02-13T00:33:06.148797Z","iopub.status.idle":"2022-02-13T00:33:13.541489Z","shell.execute_reply.started":"2022-02-13T00:33:06.148753Z","shell.execute_reply":"2022-02-13T00:33:13.540622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Weighted-Boxes-Fusion","metadata":{}},{"cell_type":"code","source":"def run_wbf(bboxes, confs,classs, image_size, iou_thr=0.40, skip_box_thr=0.05, weights=None):\n    boxes =  [bbox/(image_size-1) for bbox in bboxes]\n    scores = [conf for conf in confs]    \n    labels = [np.ones(conf.shape[0]) for conf in confs]\n    boxes, scores, labels = weighted_boxes_fusion(boxes, scores, labels, weights=None, iou_thr=iou_thr, skip_box_thr=skip_box_thr)\n    boxes = boxes*(image_size-1)\n    return boxes, scores, labels","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:13.542645Z","iopub.execute_input":"2022-02-13T00:33:13.542954Z","iopub.status.idle":"2022-02-13T00:33:13.550436Z","shell.execute_reply.started":"2022-02-13T00:33:13.542909Z","shell.execute_reply":"2022-02-13T00:33:13.549858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#--------------------------------- Aug -----------------------------------------\niou_thr = 0.4\nskip_box_thr = 0.29\n#sigma = 0.01\n#weights = [1, 1 ,1]\n#weights = [1, 1 ,1, 1, 1, 1, 1, 1]\n#weights = [1, 1 ,1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1]\nweights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n#--------------------------------- List -----------------------------------------\nboxes_list=[bboxes1,bboxes2,bboxes3,bboxes4,bboxes5,bboxes6,bboxes7,bboxes8,bboxes9,bboxes10,bboxes11,bboxes12,bboxes13,bboxes14,bboxes15,bboxes16,bboxes17,bboxes18,bboxes19,bboxes20,bboxes21,bboxes22,bboxes23,bboxes24]\nscores_list=[scores1,scores2,scores3,scores4,scores5,scores6,scores7,scores8,scores9,scores10,scores11,scores12,scores13,scores14,scores15,scores16,scores17,scores18,scores19,scores20,scores21,scores22,scores23,scores24]\nlabels_list=[bbclasses1,bbclasses2,bbclasses3,bbclasses4,bbclasses5,bbclasses6,bbclasses7,bbclasses8,bbclasses9,bbclasses10,bbclasses11,bbclasses12,bbclasses13,bbclasses14,bbclasses15,bbclasses16,bbclasses17,bbclasses18,bbclasses19,bbclasses20,bbclasses21,bbclasses22,bbclasses23,bbclasses24]\n\n\n\n#####################################  WBF  #####################################\nboxes, scores, labels  = run_wbf(boxes_list, scores_list,labels_list,IMG_SIZE, iou_thr, skip_box_thr,weights=weights)\nboxes[:, 2] = boxes[:, 2] - boxes[:, 0]\nboxes[:, 3] = boxes[:, 3] - boxes[:, 1]\nout_image_esemble=draw_bboxes(img = img,\n                        bboxes = boxes, \n                        classes = [\"WBF\"]*len(boxes),\n                        class_ids = [0]*len(boxes),\n                        class_name = True, \n                        colors = (50,50,50), \n                        bbox_format = 'coco',\n                        line_thickness = 2)\nout_image_esemble = cv2.cvtColor(out_image_esemble, cv2.COLOR_BGR2RGB)\nprint(\"------------------------------  WBF   ---------------------------------------\")\ndisplay(Image.fromarray(out_image_esemble))","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:13.551660Z","iopub.execute_input":"2022-02-13T00:33:13.552042Z","iopub.status.idle":"2022-02-13T00:33:14.404282Z","shell.execute_reply.started":"2022-02-13T00:33:13.551996Z","shell.execute_reply":"2022-02-13T00:33:14.403589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scores","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:14.405514Z","iopub.execute_input":"2022-02-13T00:33:14.406268Z","iopub.status.idle":"2022-02-13T00:33:14.411792Z","shell.execute_reply.started":"2022-02-13T00:33:14.406226Z","shell.execute_reply":"2022-02-13T00:33:14.411194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference","metadata":{}},{"cell_type":"code","source":"%cd /kaggle/working/","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:14.413071Z","iopub.execute_input":"2022-02-13T00:33:14.413478Z","iopub.status.idle":"2022-02-13T00:33:14.422866Z","shell.execute_reply.started":"2022-02-13T00:33:14.413442Z","shell.execute_reply":"2022-02-13T00:33:14.422170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import greatbarrierreef\nenv = greatbarrierreef.make_env()   # initialize the environment\niter_test = env.iter_test()  ","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:14.425461Z","iopub.execute_input":"2022-02-13T00:33:14.426176Z","iopub.status.idle":"2022-02-13T00:33:14.456572Z","shell.execute_reply.started":"2022-02-13T00:33:14.426135Z","shell.execute_reply":"2022-02-13T00:33:14.455739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Method =\"WBF\" # NMS,Soft-NMS,NMW or WBF\nIMG_SIZE  = 1280\nAUGMENT   = False\n\niou_thr = 0.4\nskip_box_thr = 0.29\n#sigma = 0.01\n#weights = [1, 1 ,1]\n#weights = [1, 1 ,1, 1, 1, 1, 1, 1]\n#weights = [1, 1 ,1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1]\nweights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n\n#--------------------------------------------------------------------------\nmodel1 = load_model(CKPT_PATH1, conf=CONF1, iou=IOU1) \nmodel2 = load_model(CKPT_PATH2, conf=CONF2, iou=IOU2)\nmodel3 = load_model(CKPT_PATH3, conf=CONF3, iou=IOU3)\n\nmodel4 = load_model(CKPT_PATH4, conf=CONF4, iou=IOU4) \nmodel5 = load_model(CKPT_PATH5, conf=CONF5, iou=IOU5)\nmodel6 = load_model(CKPT_PATH6, conf=CONF6, iou=IOU6)\nmodel7 = load_model(CKPT_PATH7, conf=CONF7, iou=IOU7) \nmodel8 = load_model(CKPT_PATH8, conf=CONF8, iou=IOU8)\n\nmodel9 = load_model(CKPT_PATH9, conf=CONF9, iou=IOU9) \nmodel10 = load_model(CKPT_PATH10, conf=CONF10, iou=IOU10)\nmodel11 = load_model(CKPT_PATH11, conf=CONF11, iou=IOU11)\nmodel12 = load_model(CKPT_PATH12, conf=CONF12, iou=IOU12) \nmodel13 = load_model(CKPT_PATH13, conf=CONF13, iou=IOU13)\n\nmodel14 = load_model(CKPT_PATH14, conf=CONF14, iou=IOU14) \nmodel15 = load_model(CKPT_PATH15, conf=CONF15, iou=IOU15)\nmodel16 = load_model(CKPT_PATH16, conf=CONF16, iou=IOU16)\n\nmodel17 = load_model(CKPT_PATH17, conf=CONF17, iou=IOU17) \nmodel18 = load_model(CKPT_PATH18, conf=CONF18, iou=IOU18)\nmodel19 = load_model(CKPT_PATH19, conf=CONF19, iou=IOU19)\nmodel20 = load_model(CKPT_PATH20, conf=CONF20, iou=IOU20) \n\nmodel21 = load_model(CKPT_PATH21, conf=CONF21, iou=IOU21) \nmodel22 = load_model(CKPT_PATH22, conf=CONF22, iou=IOU22)\nmodel23 = load_model(CKPT_PATH23, conf=CONF23, iou=IOU23)\nmodel24 = load_model(CKPT_PATH24, conf=CONF24, iou=IOU24) \n\n#--------------------------------------------------------------------------\nfor idx, (img, pred_df) in enumerate(tqdm(iter_test)):\n    bboxes1, scores1,bbclasses1  = predict(model1, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes2, scores2,bbclasses2  = predict(model2, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes3, scores3,bbclasses3  = predict(model3, img, size=IMG_SIZE, augment=AUGMENT)\n    \n    bboxes4, scores4,bbclasses4  = predict(model4, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes5, scores5,bbclasses5  = predict(model5, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes6, scores6,bbclasses6  = predict(model6, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes7, scores7,bbclasses7  = predict(model7, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes8, scores8,bbclasses8  = predict(model8, img, size=IMG_SIZE, augment=AUGMENT)\n    \n    bboxes9, scores9 ,bbclasses9  = predict(model9, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes10, scores10 ,bbclasses10  = predict(model10, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes11, scores11 ,bbclasses11  = predict(model11, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes12, scores12 ,bbclasses12  = predict(model12, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes13, scores13 ,bbclasses13  = predict(model13, img, size=IMG_SIZE, augment=AUGMENT)\n    \n    bboxes14, scores14 ,bbclasses14  = predict(model14, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes15, scores15 ,bbclasses15  = predict(model15, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes16, scores16 ,bbclasses16  = predict(model16, img, size=IMG_SIZE, augment=AUGMENT)\n    \n    bboxes17, scores17 ,bbclasses17  = predict(model17, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes18, scores18 ,bbclasses18  = predict(model18, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes19, scores19 ,bbclasses19  = predict(model19, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes20, scores20 ,bbclasses20  = predict(model20, img, size=IMG_SIZE, augment=AUGMENT)\n\n    bboxes21, scores21 ,bbclasses21  = predict(model21, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes22, scores22 ,bbclasses22  = predict(model22, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes23, scores23 ,bbclasses23  = predict(model23, img, size=IMG_SIZE, augment=AUGMENT)\n    bboxes24, scores24 ,bbclasses24  = predict(model24, img, size=IMG_SIZE, augment=AUGMENT)\n    \n    \n    boxes_list=[]\n    scores_list=[]\n    labels_list=[]\n    \n    count = 0\n    \n    \n    if len(bboxes1)>0:\n        boxes_list.append(bboxes1)\n        scores_list.append(scores1)\n        labels_list.append(bbclasses1) \n        bboxes1[:, 2] = bboxes1[:, 2] + bboxes1[:, 0]\n        bboxes1[:, 3] = bboxes1[:, 3] + bboxes1[:, 1]\n        count = count + 1\n    if len(bboxes2)>0:\n        boxes_list.append(bboxes2)\n        scores_list.append(scores2)\n        labels_list.append(bbclasses2)\n        bboxes2[:, 2] = bboxes2[:, 2] + bboxes2[:, 0]\n        bboxes2[:, 3] = bboxes2[:, 3] + bboxes2[:, 1]\n        count = count + 1\n    if len(bboxes3)>0:\n        boxes_list.append(bboxes3)\n        scores_list.append(scores3)\n        labels_list.append(bbclasses3)\n        bboxes3[:, 2] = bboxes3[:, 2] + bboxes3[:, 0]\n        bboxes3[:, 3] = bboxes3[:, 3] + bboxes3[:, 1]\n        count = count + 1\n    \n    \n    if len(bboxes4)>0:\n        boxes_list.append(bboxes4)\n        scores_list.append(scores4)\n        labels_list.append(bbclasses4)\n        bboxes4[:, 2] = bboxes4[:, 2] + bboxes4[:, 0]\n        bboxes4[:, 3] = bboxes4[:, 3] + bboxes4[:, 1]\n        count = count + 1\n    if len(bboxes5)>0:\n        boxes_list.append(bboxes5)\n        scores_list.append(scores5)\n        labels_list.append(bbclasses5)\n        bboxes5[:, 2] = bboxes5[:, 2] + bboxes5[:, 0]\n        bboxes5[:, 3] = bboxes5[:, 3] + bboxes5[:, 1]\n        count = count + 1\n    if len(bboxes6)>0:\n        boxes_list.append(bboxes6)\n        scores_list.append(scores6)\n        labels_list.append(bbclasses6)\n        bboxes6[:, 2] = bboxes6[:, 2] + bboxes6[:, 0]\n        bboxes6[:, 3] = bboxes6[:, 3] + bboxes6[:, 1]\n        count = count + 1\n    if len(bboxes7)>0:\n        boxes_list.append(bboxes7)\n        scores_list.append(scores7)\n        labels_list.append(bbclasses7)\n        bboxes7[:, 2] = bboxes7[:, 2] + bboxes7[:, 0]\n        bboxes7[:, 3] = bboxes7[:, 3] + bboxes7[:, 1]\n        count = count + 1\n    if len(bboxes8)>0:\n        boxes_list.append(bboxes8)\n        scores_list.append(scores8)\n        labels_list.append(bbclasses8)\n        bboxes8[:, 2] = bboxes8[:, 2] + bboxes8[:, 0]\n        bboxes8[:, 3] = bboxes8[:, 3] + bboxes8[:, 1]\n        count = count + 1\n    \n    if len(bboxes9)>0:\n        boxes_list.append(bboxes9)\n        scores_list.append(scores9)\n        labels_list.append(bbclasses9)\n        bboxes9[:, 2] = bboxes9[:, 2] + bboxes9[:, 0]\n        bboxes9[:, 3] = bboxes9[:, 3] + bboxes9[:, 1]\n        count = count + 1\n    if len(bboxes10)>0:\n        boxes_list.append(bboxes10)\n        scores_list.append(scores10)\n        labels_list.append(bbclasses10)\n        bboxes10[:, 2] = bboxes10[:, 2] + bboxes10[:, 0]\n        bboxes10[:, 3] = bboxes10[:, 3] + bboxes10[:, 1]\n        count = count + 1\n    if len(bboxes11)>0:\n        boxes_list.append(bboxes11)\n        scores_list.append(scores11)\n        labels_list.append(bbclasses11)\n        bboxes11[:, 2] = bboxes11[:, 2] + bboxes11[:, 0]\n        bboxes11[:, 3] = bboxes11[:, 3] + bboxes11[:, 1]\n        count = count + 1\n    if len(bboxes12)>0:\n        boxes_list.append(bboxes12)\n        scores_list.append(scores12)\n        labels_list.append(bbclasses12)\n        bboxes12[:, 2] = bboxes12[:, 2] + bboxes12[:, 0]\n        bboxes12[:, 3] = bboxes12[:, 3] + bboxes12[:, 1]\n        count = count + 1\n    if len(bboxes13)>0:\n        boxes_list.append(bboxes13)\n        scores_list.append(scores13)\n        labels_list.append(bbclasses13)\n        bboxes13[:, 2] = bboxes13[:, 2] + bboxes13[:, 0]\n        bboxes13[:, 3] = bboxes13[:, 3] + bboxes13[:, 1]\n        count = count + 1\n    \n    if len(bboxes14)>0:\n        boxes_list.append(bboxes14)\n        scores_list.append(scores14)\n        labels_list.append(bbclasses14) \n        bboxes14[:, 2] = bboxes14[:, 2] + bboxes14[:, 0]\n        bboxes14[:, 3] = bboxes14[:, 3] + bboxes14[:, 1]\n        count = count + 1\n    if len(bboxes15)>0:\n        boxes_list.append(bboxes15)\n        scores_list.append(scores15)\n        labels_list.append(bbclasses15)\n        bboxes15[:, 2] = bboxes15[:, 2] + bboxes15[:, 0]\n        bboxes15[:, 3] = bboxes15[:, 3] + bboxes15[:, 1]\n        count = count + 1\n    if len(bboxes16)>0:\n        boxes_list.append(bboxes16)\n        scores_list.append(scores16)\n        labels_list.append(bbclasses16)\n        bboxes16[:, 2] = bboxes16[:, 2] + bboxes16[:, 0]\n        bboxes16[:, 3] = bboxes16[:, 3] + bboxes16[:, 1]\n        count = count + 1\n    \n    if len(bboxes17)>0:\n        boxes_list.append(bboxes17)\n        scores_list.append(scores17)\n        labels_list.append(bbclasses17)\n        bboxes17[:, 2] = bboxes17[:, 2] + bboxes17[:, 0]\n        bboxes17[:, 3] = bboxes17[:, 3] + bboxes17[:, 1]\n        count = count + 1\n    if len(bboxes18)>0:\n        boxes_list.append(bboxes18)\n        scores_list.append(scores18)\n        labels_list.append(bbclasses18)\n        bboxes18[:, 2] = bboxes18[:, 2] + bboxes18[:, 0]\n        bboxes18[:, 3] = bboxes18[:, 3] + bboxes18[:, 1]\n        count = count + 1\n    if len(bboxes19)>0:\n        boxes_list.append(bboxes19)\n        scores_list.append(scores19)\n        labels_list.append(bbclasses19)\n        bboxes19[:, 2] = bboxes19[:, 2] + bboxes19[:, 0]\n        bboxes19[:, 3] = bboxes19[:, 3] + bboxes19[:, 1]\n        count = count + 1\n    if len(bboxes20)>0:\n        boxes_list.append(bboxes20)\n        scores_list.append(scores20)\n        labels_list.append(bbclasses20)\n        bboxes20[:, 2] = bboxes20[:, 2] + bboxes20[:, 0]\n        bboxes20[:, 3] = bboxes20[:, 3] + bboxes20[:, 1]\n        count = count + 1\n    \n    if len(bboxes21)>0:\n        boxes_list.append(bboxes21)\n        scores_list.append(scores21)\n        labels_list.append(bbclasses21)\n        bboxes21[:, 2] = bboxes21[:, 2] + bboxes21[:, 0]\n        bboxes21[:, 3] = bboxes21[:, 3] + bboxes21[:, 1]\n        count = count + 1\n    if len(bboxes22)>0:\n        boxes_list.append(bboxes22)\n        scores_list.append(scores22)\n        labels_list.append(bbclasses22)\n        bboxes22[:, 2] = bboxes22[:, 2] + bboxes22[:, 0]\n        bboxes22[:, 3] = bboxes22[:, 3] + bboxes22[:, 1]\n        count = count + 1\n    if len(bboxes23)>0:\n        boxes_list.append(bboxes23)\n        scores_list.append(scores23)\n        labels_list.append(bbclasses23)\n        bboxes23[:, 2] = bboxes23[:, 2] + bboxes23[:, 0]\n        bboxes23[:, 3] = bboxes23[:, 3] + bboxes23[:, 1]\n        count = count + 1\n    if len(bboxes24)>0:\n        boxes_list.append(bboxes24)\n        scores_list.append(scores24)\n        labels_list.append(bbclasses24)\n        bboxes24[:, 2] = bboxes24[:, 2] + bboxes24[:, 0]\n        bboxes24[:, 3] = bboxes24[:, 3] + bboxes24[:, 1]\n        count = count + 1\n    \n\n    if count>11:\n    #if (len(bboxes1) + len(bboxes2) + len(bboxes3) + len(bboxes4) + len(bboxes5) + len(bboxes6) + len(bboxes7) + len(bboxes8) + len(bboxes9) + len(bboxes10) + len(bboxes11) + len(bboxes12) + len(bboxes13) + len(bboxes14) + len(bboxes15) + len(bboxes16) + len(bboxes17) + len(bboxes18) + len(bboxes19) + len(bboxes20) + len(bboxes21) + len(bboxes22) + len(bboxes23) + len(bboxes24))>0:\n       \n        boxes, scores, labels  = run_wbf(boxes_list, scores_list, labels_list, IMG_SIZE, iou_thr, skip_box_thr, weights=weights)\n\n        boxes[:, 2] = boxes[:, 2] - boxes[:, 0]\n        boxes[:, 3] = boxes[:, 3] - boxes[:, 1]\n    else: boxes=[]\n        \n    \n    predictions = []\n    for i in range(len(boxes)):\n        box = boxes[i]\n        score = scores[i]\n        if score > 0.05:\n            x_min = int(box[0])\n            y_min = int(box[1])\n            bbox_width = int(box[2])\n            bbox_height = int(box[3])\n            predictions.append('{:.2f} {} {} {} {}'.format(score, x_min, y_min, bbox_width, bbox_height))\n    \n    prediction_str = ' '.join(predictions)\n    pred_df['annotations'] = prediction_str\n    env.predict(pred_df)\n\n        \n    print(\"------------------------------  \" + Method +\"   ---------------------------------------\")\n    if idx<3:\n        display(show_img(img, boxes, bbox_format='coco'))","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:14.458138Z","iopub.execute_input":"2022-02-13T00:33:14.458815Z","iopub.status.idle":"2022-02-13T00:33:49.470259Z","shell.execute_reply.started":"2022-02-13T00:33:14.458770Z","shell.execute_reply":"2022-02-13T00:33:49.469536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = pd.read_csv('submission.csv')\nsub_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-13T00:33:49.471938Z","iopub.execute_input":"2022-02-13T00:33:49.472774Z","iopub.status.idle":"2022-02-13T00:33:49.488897Z","shell.execute_reply.started":"2022-02-13T00:33:49.472734Z","shell.execute_reply":"2022-02-13T00:33:49.488087Z"},"trusted":true},"execution_count":null,"outputs":[]}]}