{"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":"markdown","source":"# Recreate the Backbone","metadata":{}},{"cell_type":"code","source":"import torch\nimport torch.nn as nn","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:26:51.151185Z","iopub.execute_input":"2023-06-02T09:26:51.151768Z","iopub.status.idle":"2023-06-02T09:26:53.574343Z","shell.execute_reply.started":"2023-06-02T09:26:51.151730Z","shell.execute_reply":"2023-06-02T09:26:53.573210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/utils/torch_utils.py\ndef check_all_model_params_in_groups2(model, param_groups):\n    num_params = len([param for group in param_groups for param in group])\n    num_params_expected = len(list(model.parameters()))\n\n    if num_params != num_params_expected:\n        raise RuntimeError(f\"{num_params_expected} params in model, but only {num_params} in parameter group.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:26:59.587035Z","iopub.execute_input":"2023-06-02T09:26:59.587558Z","iopub.status.idle":"2023-06-02T09:26:59.594283Z","shell.execute_reply.started":"2023-06-02T09:26:59.587522Z","shell.execute_reply":"2023-06-02T09:26:59.593179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/faster_rcnn/backbones/resnet_fpn_utils.py\ndef param_groups(model):\n    body = model.body\n\n    layers = []\n    layers += [nn.Sequential(body.conv1, body.bn1)]\n    layers += [getattr(body, l) for l in list(body) if l.startswith(\"layer\")]\n    layers += [model.fpn]\n\n    _param_groups = [list(layer.parameters()) for layer in layers]\n    check_all_model_params_in_groups2(model, _param_groups)\n\n    return _param_groups","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:05.463053Z","iopub.execute_input":"2023-06-02T09:27:05.463983Z","iopub.status.idle":"2023-06-02T09:27:05.472101Z","shell.execute_reply.started":"2023-06-02T09:27:05.463906Z","shell.execute_reply":"2023-06-02T09:27:05.470652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/faster_rcnn/backbones/resnet_fpn_utils.py\nfrom types import MethodType\n\ndef patch_param_groups(model):\n    model.param_groups = MethodType(param_groups, model)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:09.503682Z","iopub.execute_input":"2023-06-02T09:27:09.504077Z","iopub.status.idle":"2023-06-02T09:27:09.510139Z","shell.execute_reply.started":"2023-06-02T09:27:09.504043Z","shell.execute_reply":"2023-06-02T09:27:09.508877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/faster_rcnn/backbones/resnet_fpn_configs.py\nfrom torchvision.models.detection.backbone_utils import resnet_fpn_backbone\n\ndef _resnet_fpn(name, pretrained=True, **kwargs):\n    model = resnet_fpn_backbone(backbone_name=name, pretrained=pretrained, **kwargs)\n    patch_param_groups(model)\n\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:14.262578Z","iopub.execute_input":"2023-06-02T09:27:14.263744Z","iopub.status.idle":"2023-06-02T09:27:14.511546Z","shell.execute_reply.started":"2023-06-02T09:27:14.263700Z","shell.execute_reply":"2023-06-02T09:27:14.510480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/faster_rcnn/backbones/resnet_fpn_configs.py\ndef resnet50_fpn_fn(pretrained=True, **kwargs):\n    return _resnet_fpn(\"resnet50\", pretrained=pretrained, **kwargs)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:18.935926Z","iopub.execute_input":"2023-06-02T09:27:18.936678Z","iopub.status.idle":"2023-06-02T09:27:18.942652Z","shell.execute_reply.started":"2023-06-02T09:27:18.936638Z","shell.execute_reply":"2023-06-02T09:27:18.941156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"line_backbone = resnet50_fpn_fn(pretrained=False)\nline_backbone","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:30.995798Z","iopub.execute_input":"2023-06-02T09:27:30.996418Z","iopub.status.idle":"2023-06-02T09:27:31.500029Z","shell.execute_reply.started":"2023-06-02T09:27:30.996377Z","shell.execute_reply":"2023-06-02T09:27:31.498904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Recreate the Model","metadata":{}},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/utils.py\ndef patch_param_groups2(model, head_layers, backbone_param_groups):\n    def param_groups2(model):\n        head_param_groups = [list(layer.parameters()) for layer in head_layers]\n\n        _param_groups = backbone_param_groups + head_param_groups\n        check_all_model_params_in_groups2(model, _param_groups)\n\n        return _param_groups\n\n    model.param_groups = MethodType(param_groups2, model)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:39.500600Z","iopub.execute_input":"2023-06-02T09:27:39.501778Z","iopub.status.idle":"2023-06-02T09:27:39.508615Z","shell.execute_reply.started":"2023-06-02T09:27:39.501728Z","shell.execute_reply":"2023-06-02T09:27:39.507374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/utils.py\ndef patch_rcnn_param_groups(model):\n    return patch_param_groups2(model=model, head_layers=[model.rpn, model.roi_heads], backbone_param_groups=model.backbone.param_groups())","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:41.023197Z","iopub.execute_input":"2023-06-02T09:27:41.024178Z","iopub.status.idle":"2023-06-02T09:27:41.030387Z","shell.execute_reply.started":"2023-06-02T09:27:41.024118Z","shell.execute_reply":"2023-06-02T09:27:41.029148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/utils.py\ndef _noop_normalize(image):\n    return image\n\ndef _noop_resize(image, target):\n    return image, target\n\ndef remove_internal_model_transforms(model):\n    model.transform.normalize = _noop_normalize\n    model.transform.resize = _noop_resize","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:44.925180Z","iopub.execute_input":"2023-06-02T09:27:44.925578Z","iopub.status.idle":"2023-06-02T09:27:44.932016Z","shell.execute_reply.started":"2023-06-02T09:27:44.925541Z","shell.execute_reply":"2023-06-02T09:27:44.930728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/faster_rcnn/model.py\nfrom torchvision.models.detection.faster_rcnn import FasterRCNN\n\ndef get_model(num_classes, backbone, remove_internal_transforms=True, **faster_rcnn_kwargs):\n    model = FasterRCNN(backbone, num_classes=num_classes, **faster_rcnn_kwargs)\n\n    patch_rcnn_param_groups(model=model)\n\n    if remove_internal_transforms:\n        remove_internal_model_transforms(model)\n\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:27:49.936034Z","iopub.execute_input":"2023-06-02T09:27:49.936995Z","iopub.status.idle":"2023-06-02T09:27:49.943424Z","shell.execute_reply.started":"2023-06-02T09:27:49.936921Z","shell.execute_reply":"2023-06-02T09:27:49.942317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"line_model = get_model(num_classes=2, backbone=line_backbone)\nline_model","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:28:05.143538Z","iopub.execute_input":"2023-06-02T09:28:05.144057Z","iopub.status.idle":"2023-06-02T09:28:05.365689Z","shell.execute_reply.started":"2023-06-02T09:28:05.144018Z","shell.execute_reply":"2023-06-02T09:28:05.364519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# line_model.load_state_dict(torch.load('/kaggle/input/b-m-g-a-extra-data/line__3.pth'))\nline_model.load_state_dict(torch.load('/kaggle/input/b-m-g-a-extra-data/line__5.pth'))","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:29:05.595815Z","iopub.execute_input":"2023-06-02T09:29:05.596602Z","iopub.status.idle":"2023-06-02T09:29:10.825327Z","shell.execute_reply.started":"2023-06-02T09:29:05.596561Z","shell.execute_reply":"2023-06-02T09:29:10.824273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\ndevice","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:29:13.898815Z","iopub.execute_input":"2023-06-02T09:29:13.899554Z","iopub.status.idle":"2023-06-02T09:29:13.906769Z","shell.execute_reply.started":"2023-06-02T09:29:13.899511Z","shell.execute_reply":"2023-06-02T09:29:13.905663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"line_model = line_model.to(device)\nline_model.eval();","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:29:30.678896Z","iopub.execute_input":"2023-06-02T09:29:30.679613Z","iopub.status.idle":"2023-06-02T09:29:30.746631Z","shell.execute_reply.started":"2023-06-02T09:29:30.679572Z","shell.execute_reply":"2023-06-02T09:29:30.745599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Postprocessing Functions","metadata":{}},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/utils/imageio.py\nfrom collections import namedtuple\n\nImgSize = namedtuple(\"ImgSize\", \"width, height\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:32:57.927007Z","iopub.execute_input":"2023-06-02T09:32:57.927739Z","iopub.status.idle":"2023-06-02T09:32:57.933085Z","shell.execute_reply.started":"2023-06-02T09:32:57.927699Z","shell.execute_reply":"2023-06-02T09:32:57.931875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/utils/imageio.py\nimport PIL\nimport numpy as np\n\ndef get_img_size_from_data(data):\n    \"\"\"\n    Returns image size.\n    If the data is a NumPy array, it is expected to be in the format (h, w) or (h, w, c).\n    \"\"\"\n    assert isinstance(data, (PIL.Image.Image, np.ndarray))\n\n    if isinstance(data, PIL.Image.Image):\n        width, height = data.size\n    else:\n        height, width, *_ = data.shape\n\n    return ImgSize(width=width, height=height)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:33:06.476444Z","iopub.execute_input":"2023-06-02T09:33:06.477544Z","iopub.status.idle":"2023-06-02T09:33:06.485004Z","shell.execute_reply.started":"2023-06-02T09:33:06.477491Z","shell.execute_reply":"2023-06-02T09:33:06.483783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import albumentations as A\n\nline_tfms_list = [\n    A.LongestMaxSize(always_apply=False, p=1, max_size=640, interpolation=1),\n    A.PadIfNeeded(always_apply=False, p=1.0, min_height=640, min_width=640, pad_height_divisor=None, pad_width_divisor=None, border_mode=0, value=[124, 116, 104], mask_value=None),\n    A.Normalize(always_apply=False, p=1.0, mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225), max_pixel_value=255.0)\n]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:33:56.403465Z","iopub.execute_input":"2023-06-02T09:33:56.404471Z","iopub.status.idle":"2023-06-02T09:33:57.744708Z","shell.execute_reply.started":"2023-06-02T09:33:56.404414Z","shell.execute_reply":"2023-06-02T09:33:57.743698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/tfms/albumentations/albumentations_helpers.py\ndef get_transform(tfms_list, t):\n    \"\"\"\n    Extract transform `t` from `tfms_list`.\n    \n    Parameters\n    ----------\n    tfms_list: list of albumentations transforms.\n    t: name (str) of the transform to look for and return from within `tfms_list`.\n    \n    Returns\n    -------\n    The `t` transform if found inside `tfms_list`, otherwise `None`.\n    \"\"\"\n    for el in tfms_list:\n        if t in str(type(el)):\n            return el\n    return None","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:34:14.895547Z","iopub.execute_input":"2023-06-02T09:34:14.895948Z","iopub.status.idle":"2023-06-02T09:34:14.902246Z","shell.execute_reply.started":"2023-06-02T09:34:14.895898Z","shell.execute_reply":"2023-06-02T09:34:14.900985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/tfms/albumentations/albumentations_helpers.py\ndef py3round(number):\n    \"\"\"\n    Unified rounding in all Python versions. Used by Albumentations.\n    \n    Parameters\n    ----------\n    number: float to round.\n    \n    Returns\n    -------\n    Rounded number.\n    \"\"\"\n    if abs(round(number) - number) == 0.5:\n        return int(2.0 * round(number / 2.0))\n\n    return int(round(number))","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:34:19.474677Z","iopub.execute_input":"2023-06-02T09:34:19.475077Z","iopub.status.idle":"2023-06-02T09:34:19.481426Z","shell.execute_reply.started":"2023-06-02T09:34:19.475040Z","shell.execute_reply":"2023-06-02T09:34:19.479922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/tfms/albumentations/albumentations_helpers.py\ndef func_max_size(height, width, max_size, func):\n    \"\"\"\n    Calculate rescaled height and width of the image in question w.r.t. to a specific size.\n    \n    Parameters\n    ----------\n    height: height of the image in question.\n    width: width of the image in question.\n    max_size: size w.r.t. the image needs to be rescaled (resized).\n    func: min/max. Whether to compare max_size to the smallest/longest of the image dims.\n    \n    Returns\n    -------\n    Rescaled height and width.\n    \"\"\"\n    scale = max_size / float(func(width, height))\n\n    if scale != 1.0:\n        height, width = tuple(py3round(dim * scale) for dim in (height, width))\n    return height, width","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:34:23.675786Z","iopub.execute_input":"2023-06-02T09:34:23.676435Z","iopub.status.idle":"2023-06-02T09:34:23.686039Z","shell.execute_reply.started":"2023-06-02T09:34:23.676381Z","shell.execute_reply":"2023-06-02T09:34:23.684733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/tfms/albumentations/albumentations_helpers.py\ndef get_size_without_padding(tfms_list, before_tfm_img_size, height, width):\n    \"\"\"\n    Infer the height and width of the pre-processed image after removing padding.\n    \n    Parameters\n    ----------\n    tfms_list: list of albumentations transforms applied to the `before_tfm_img` image before passing it to the model for inference.\n    before_tfm_img_size: original image size before being pre-processed for inference.\n    height: height of output image from icevision `predict` function.\n    width: width of output image from icevision `predict` function.\n    \n    Returns\n    -------\n    height and width of the image coming out of the inference pipeline, after removing padding.\n    \"\"\"\n    if get_transform(tfms_list, \"Pad\") is not None:\n\n        t = get_transform(tfms_list, \"SmallestMaxSize\")\n        if t is not None:\n            presize = t.max_size\n            height, width = func_max_size(before_tfm_img_size.height, before_tfm_img_size.width, presize, min)\n\n        t = get_transform(tfms_list, \"LongestMaxSize\")\n        if t is not None:\n            size = t.max_size\n            height, width = func_max_size(before_tfm_img_size.height, before_tfm_img_size.width, size, max)\n\n    return height, width","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:34:27.867039Z","iopub.execute_input":"2023-06-02T09:34:27.867417Z","iopub.status.idle":"2023-06-02T09:34:27.879177Z","shell.execute_reply.started":"2023-06-02T09:34:27.867384Z","shell.execute_reply":"2023-06-02T09:34:27.877995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BBox = namedtuple(\"BBox\", \"xmin, ymin, xmax, ymax\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:34:28.388044Z","iopub.execute_input":"2023-06-02T09:34:28.388424Z","iopub.status.idle":"2023-06-02T09:34:28.396017Z","shell.execute_reply.started":"2023-06-02T09:34:28.388384Z","shell.execute_reply":"2023-06-02T09:34:28.394839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Original source: https://github.com/airctic/icevision/blob/master/icevision/models/inference.py\ndef postprocess_bbox(img_size, bbox, transforms, h_after, w_after):\n    \"\"\"\n    Post-process predicted bbox to adjust coordinates to input image size.\n    \n    Parameters\n    ----------\n    img_size: original image size, before any model-pre-processing done.\n    bbox: predicted bbox.\n    transforms: list of model-pre-processing transforms.\n    h_after: height of image after model-pre-processing transforms.\n    w_after: width of image after model-pre-processing transforms.\n    \n    Returns\n    -------\n    Tuple with (xmin, ymin, xmax, ymax) rescaled and re-adjusted to match the original image size.\n    \"\"\"\n    h_after, w_after = get_size_without_padding(transforms, img_size, h_after, w_after)\n    pad = np.abs(h_after - w_after) // 2\n\n    h_scale, w_scale = h_after / img_size.height, w_after / img_size.width\n    if h_after < w_after:\n        xmin, xmax, ymin, ymax = (\n            int(bbox.xmin),\n            int(bbox.xmax),\n            int(bbox.ymin) - pad,\n            int(bbox.ymax) - pad,\n        )\n    else:\n        xmin, xmax, ymin, ymax = (\n            int(bbox.xmin) - pad,\n            int(bbox.xmax) - pad,\n            int(bbox.ymin),\n            int(bbox.ymax),\n        )\n\n    xmin, xmax, ymin, ymax = (\n        max(xmin, 0),\n        min(xmax, w_after),\n        max(ymin, 0),\n        min(ymax, h_after),\n    )\n    xmin, xmax, ymin, ymax = (\n        int(xmin / w_scale),\n        int(xmax / w_scale),\n        int(ymin / h_scale),\n        int(ymax / h_scale),\n    )\n\n    return xmin, ymin, xmax, ymax","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:34:35.742828Z","iopub.execute_input":"2023-06-02T09:34:35.743532Z","iopub.status.idle":"2023-06-02T09:34:35.756556Z","shell.execute_reply.started":"2023-06-02T09:34:35.743492Z","shell.execute_reply":"2023-06-02T09:34:35.755193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Creating a DataFrame","metadata":{}},{"cell_type":"code","source":"from pathlib import Path\n\npath = Path('/kaggle/input/benetech-making-graphs-accessible')\n!ls {path}","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:35:40.292559Z","iopub.execute_input":"2023-06-02T09:35:40.293620Z","iopub.status.idle":"2023-06-02T09:35:41.259103Z","shell.execute_reply.started":"2023-06-02T09:35:40.293565Z","shell.execute_reply":"2023-06-02T09:35:41.257822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = path/'train'\n!ls {train_path}","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:35:50.251975Z","iopub.execute_input":"2023-06-02T09:35:50.253113Z","iopub.status.idle":"2023-06-02T09:35:51.216348Z","shell.execute_reply.started":"2023-06-02T09:35:50.253047Z","shell.execute_reply":"2023-06-02T09:35:51.215077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"annotations_path = train_path/'annotations'\nimages_path = train_path/'images'","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:35:59.893777Z","iopub.execute_input":"2023-06-02T09:35:59.894337Z","iopub.status.idle":"2023-06-02T09:35:59.903428Z","shell.execute_reply.started":"2023-06-02T09:35:59.894286Z","shell.execute_reply":"2023-06-02T09:35:59.902184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.notebook import tqdm\nimport json\n\nimg_file_names = []\nsources = []\nchart_types = []\n\nfor file_path in tqdm(sorted(annotations_path.glob(\"*.json\"))):\n    with open(file_path, \"r\") as json_file:\n        json_file_name = str(file_path).split(\"/\")[-1]\n        without_ext = json_file_name.split(\".\")[0]\n        img_file_name = without_ext + \".jpg\"\n        img_file_names.append(img_file_name)\n        data = json.load(json_file)\n        sources.append(data['source'])\n        chart_types.append(data['chart-type'])\n\nlen(img_file_names), len(sources), len(chart_types)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:36:12.269159Z","iopub.execute_input":"2023-06-02T09:36:12.269751Z","iopub.status.idle":"2023-06-02T09:41:47.821229Z","shell.execute_reply.started":"2023-06-02T09:36:12.269712Z","shell.execute_reply":"2023-06-02T09:41:47.820109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\ndf = pd.DataFrame({'img_file_name': img_file_names, 'source': sources, 'chart_type': chart_types})\ndf","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:41:51.536523Z","iopub.execute_input":"2023-06-02T09:41:51.536900Z","iopub.status.idle":"2023-06-02T09:41:51.587250Z","shell.execute_reply.started":"2023-06-02T09:41:51.536865Z","shell.execute_reply":"2023-06-02T09:41:51.586017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"line_df = df.loc[df['chart_type'] == 'line'].reset_index(drop=True)\nline_df","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:42:16.800481Z","iopub.execute_input":"2023-06-02T09:42:16.801116Z","iopub.status.idle":"2023-06-02T09:42:16.836350Z","shell.execute_reply.started":"2023-06-02T09:42:16.801076Z","shell.execute_reply":"2023-06-02T09:42:16.835386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference on 8 Randomly Selected Images","metadata":{}},{"cell_type":"markdown","source":"Let's run inference on 8 randomly chosen images.","metadata":{}},{"cell_type":"code","source":"line_df = line_df.sample(frac=1, random_state=42, ignore_index=True)\nsample_df = line_df.iloc[:8]\nsample_df","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:43:21.510106Z","iopub.execute_input":"2023-06-02T09:43:21.510834Z","iopub.status.idle":"2023-06-02T09:43:21.532304Z","shell.execute_reply.started":"2023-06-02T09:43:21.510787Z","shell.execute_reply":"2023-06-02T09:43:21.531351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from albumentations.pytorch.transforms import ToTensorV2\n\nline_transforms = A.Compose([\n    A.LongestMaxSize(always_apply=False, p=1, max_size=640, interpolation=1),\n    A.PadIfNeeded(always_apply=False, p=1.0, min_height=640, min_width=640, pad_height_divisor=None, pad_width_divisor=None, border_mode=0, value=[124, 116, 104], mask_value=None),\n    A.Normalize(always_apply=False, p=1.0, mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225), max_pixel_value=255.0), \n    ToTensorV2()\n])\nline_transforms","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:44:00.806391Z","iopub.execute_input":"2023-06-02T09:44:00.806863Z","iopub.status.idle":"2023-06-02T09:44:00.822554Z","shell.execute_reply.started":"2023-06-02T09:44:00.806822Z","shell.execute_reply":"2023-06-02T09:44:00.821323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:44:08.021360Z","iopub.execute_input":"2023-06-02T09:44:08.022003Z","iopub.status.idle":"2023-06-02T09:44:08.027678Z","shell.execute_reply.started":"2023-06-02T09:44:08.021956Z","shell.execute_reply":"2023-06-02T09:44:08.026443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_threshold = 0.5","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:44:10.634486Z","iopub.execute_input":"2023-06-02T09:44:10.635303Z","iopub.status.idle":"2023-06-02T09:44:10.640377Z","shell.execute_reply.started":"2023-06-02T09:44:10.635259Z","shell.execute_reply":"2023-06-02T09:44:10.639106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extra_data_path = Path('/kaggle/input/b-m-g-a-extra-data')\nline_images_path = extra_data_path/'line_all_24932'","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:48:21.388926Z","iopub.execute_input":"2023-06-02T09:48:21.389918Z","iopub.status.idle":"2023-06-02T09:48:21.394808Z","shell.execute_reply.started":"2023-06-02T09:48:21.389875Z","shell.execute_reply":"2023-06-02T09:48:21.393271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_line_bboxes(img_file_name):\n    img = Image.open(line_images_path/img_file_name)\n    img_arr = np.array(img)\n    transformed = line_transforms(image=img_arr)\n    batched = transformed['image'].unsqueeze(0)\n    batched = batched.to(device)\n    with torch.no_grad():\n        out = line_model(batched)\n    first_out = out[0]\n    first_out['boxes'] = first_out['boxes'][first_out['scores'] > score_threshold]\n    postprocessed_bboxes = []\n    for box in first_out['boxes']:\n        bbox = BBox(box[0].item(), box[1].item(), box[2].item(), box[3].item())\n        new_bbox = postprocess_bbox(img_size=ImgSize(width=img.size[0], height=img.size[1]), bbox=bbox, transforms=line_tfms_list, h_after=640, w_after=640)\n        postprocessed_bboxes.append(list(new_bbox))\n    return postprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:48:57.608517Z","iopub.execute_input":"2023-06-02T09:48:57.608996Z","iopub.status.idle":"2023-06-02T09:48:57.624817Z","shell.execute_reply.started":"2023-06-02T09:48:57.608955Z","shell.execute_reply":"2023-06-02T09:48:57.623640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_img_with_bbs(img_file_name, postprocessed_bboxes):\n    img = Image.open(line_images_path/img_file_name)\n    img_arr = np.array(img)\n    for i in range(len(postprocessed_bboxes)):\n        start_point = postprocessed_bboxes[i][0], postprocessed_bboxes[i][1]\n        end_point = postprocessed_bboxes[i][2], postprocessed_bboxes[i][3]\n        cv2.rectangle(img_arr, start_point, end_point, color=(0, 0, 255), thickness=1)\n    img_with_bbs = Image.fromarray(img_arr)\n    return img_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:49:05.032830Z","iopub.execute_input":"2023-06-02T09:49:05.033537Z","iopub.status.idle":"2023-06-02T09:49:05.041073Z","shell.execute_reply.started":"2023-06-02T09:49:05.033496Z","shell.execute_reply":"2023-06-02T09:49:05.039774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][0]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:49:08.872772Z","iopub.execute_input":"2023-06-02T09:49:08.873499Z","iopub.status.idle":"2023-06-02T09:49:08.880634Z","shell.execute_reply.started":"2023-06-02T09:49:08.873458Z","shell.execute_reply":"2023-06-02T09:49:08.879488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:49:09.283674Z","iopub.execute_input":"2023-06-02T09:49:09.284045Z","iopub.status.idle":"2023-06-02T09:49:09.356804Z","shell.execute_reply.started":"2023-06-02T09:49:09.284010Z","shell.execute_reply":"2023-06-02T09:49:09.355704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:49:12.332554Z","iopub.execute_input":"2023-06-02T09:49:12.334248Z","iopub.status.idle":"2023-06-02T09:49:12.364018Z","shell.execute_reply.started":"2023-06-02T09:49:12.334196Z","shell.execute_reply":"2023-06-02T09:49:12.362878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][1]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:49:46.050856Z","iopub.execute_input":"2023-06-02T09:49:46.051850Z","iopub.status.idle":"2023-06-02T09:49:46.059092Z","shell.execute_reply.started":"2023-06-02T09:49:46.051803Z","shell.execute_reply":"2023-06-02T09:49:46.058013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:49:46.532375Z","iopub.execute_input":"2023-06-02T09:49:46.533015Z","iopub.status.idle":"2023-06-02T09:49:46.601635Z","shell.execute_reply.started":"2023-06-02T09:49:46.532961Z","shell.execute_reply":"2023-06-02T09:49:46.600439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:49:48.099848Z","iopub.execute_input":"2023-06-02T09:49:48.100862Z","iopub.status.idle":"2023-06-02T09:49:48.142022Z","shell.execute_reply.started":"2023-06-02T09:49:48.100822Z","shell.execute_reply":"2023-06-02T09:49:48.140865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][2]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:50:11.770642Z","iopub.execute_input":"2023-06-02T09:50:11.771164Z","iopub.status.idle":"2023-06-02T09:50:11.778681Z","shell.execute_reply.started":"2023-06-02T09:50:11.771123Z","shell.execute_reply":"2023-06-02T09:50:11.776912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:50:17.735217Z","iopub.execute_input":"2023-06-02T09:50:17.735594Z","iopub.status.idle":"2023-06-02T09:50:17.804771Z","shell.execute_reply.started":"2023-06-02T09:50:17.735560Z","shell.execute_reply":"2023-06-02T09:50:17.803701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:50:21.214098Z","iopub.execute_input":"2023-06-02T09:50:21.215194Z","iopub.status.idle":"2023-06-02T09:50:21.248312Z","shell.execute_reply.started":"2023-06-02T09:50:21.215134Z","shell.execute_reply":"2023-06-02T09:50:21.247009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][3]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:50:59.593980Z","iopub.execute_input":"2023-06-02T09:50:59.594468Z","iopub.status.idle":"2023-06-02T09:50:59.605603Z","shell.execute_reply.started":"2023-06-02T09:50:59.594420Z","shell.execute_reply":"2023-06-02T09:50:59.604387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:06.356245Z","iopub.execute_input":"2023-06-02T09:51:06.359766Z","iopub.status.idle":"2023-06-02T09:51:06.440839Z","shell.execute_reply.started":"2023-06-02T09:51:06.359718Z","shell.execute_reply":"2023-06-02T09:51:06.439796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:06.883093Z","iopub.execute_input":"2023-06-02T09:51:06.883470Z","iopub.status.idle":"2023-06-02T09:51:06.925592Z","shell.execute_reply.started":"2023-06-02T09:51:06.883433Z","shell.execute_reply":"2023-06-02T09:51:06.924404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][4]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:29.902589Z","iopub.execute_input":"2023-06-02T09:51:29.903291Z","iopub.status.idle":"2023-06-02T09:51:29.911808Z","shell.execute_reply.started":"2023-06-02T09:51:29.903249Z","shell.execute_reply":"2023-06-02T09:51:29.910525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:37.771069Z","iopub.execute_input":"2023-06-02T09:51:37.771886Z","iopub.status.idle":"2023-06-02T09:51:37.841462Z","shell.execute_reply.started":"2023-06-02T09:51:37.771843Z","shell.execute_reply":"2023-06-02T09:51:37.840340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:37.948069Z","iopub.execute_input":"2023-06-02T09:51:37.948461Z","iopub.status.idle":"2023-06-02T09:51:37.990689Z","shell.execute_reply.started":"2023-06-02T09:51:37.948427Z","shell.execute_reply":"2023-06-02T09:51:37.989626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][5]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:48.878554Z","iopub.execute_input":"2023-06-02T09:51:48.879744Z","iopub.status.idle":"2023-06-02T09:51:48.887630Z","shell.execute_reply.started":"2023-06-02T09:51:48.879695Z","shell.execute_reply":"2023-06-02T09:51:48.886389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:54.201505Z","iopub.execute_input":"2023-06-02T09:51:54.202009Z","iopub.status.idle":"2023-06-02T09:51:54.283515Z","shell.execute_reply.started":"2023-06-02T09:51:54.201924Z","shell.execute_reply":"2023-06-02T09:51:54.282518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:51:54.564476Z","iopub.execute_input":"2023-06-02T09:51:54.564832Z","iopub.status.idle":"2023-06-02T09:51:54.622789Z","shell.execute_reply.started":"2023-06-02T09:51:54.564800Z","shell.execute_reply":"2023-06-02T09:51:54.621788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][6]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:52:10.899552Z","iopub.execute_input":"2023-06-02T09:52:10.900055Z","iopub.status.idle":"2023-06-02T09:52:10.911449Z","shell.execute_reply.started":"2023-06-02T09:52:10.900007Z","shell.execute_reply":"2023-06-02T09:52:10.910285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:52:16.564991Z","iopub.execute_input":"2023-06-02T09:52:16.565528Z","iopub.status.idle":"2023-06-02T09:52:16.632811Z","shell.execute_reply.started":"2023-06-02T09:52:16.565486Z","shell.execute_reply":"2023-06-02T09:52:16.631526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:52:16.698997Z","iopub.execute_input":"2023-06-02T09:52:16.699879Z","iopub.status.idle":"2023-06-02T09:52:16.732094Z","shell.execute_reply.started":"2023-06-02T09:52:16.699830Z","shell.execute_reply":"2023-06-02T09:52:16.731006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = sample_df['img_file_name'][7]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:52:27.208985Z","iopub.execute_input":"2023-06-02T09:52:27.209718Z","iopub.status.idle":"2023-06-02T09:52:27.217253Z","shell.execute_reply.started":"2023-06-02T09:52:27.209677Z","shell.execute_reply":"2023-06-02T09:52:27.216011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:52:34.923845Z","iopub.execute_input":"2023-06-02T09:52:34.924857Z","iopub.status.idle":"2023-06-02T09:52:34.994027Z","shell.execute_reply.started":"2023-06-02T09:52:34.924816Z","shell.execute_reply":"2023-06-02T09:52:34.992841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:52:35.445702Z","iopub.execute_input":"2023-06-02T09:52:35.446766Z","iopub.status.idle":"2023-06-02T09:52:35.489850Z","shell.execute_reply.started":"2023-06-02T09:52:35.446717Z","shell.execute_reply":"2023-06-02T09:52:35.488863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference on 10 Top Loss Images","metadata":{}},{"cell_type":"markdown","source":"Let's run inference on the 10 top loss images from the <a href=\"https://www.kaggle.com/code/sambitmukherjee/line-detection-training\" target=\"_blank\">training notebook</a>'s \"Model Evaluation\" section.","metadata":{}},{"cell_type":"code","source":"top_loss_images = [\n    'c030b3e1913d.jpg', \n    '11376f3d0424.jpg', \n    '95812fbd6f6d.jpg', \n    'fcb7801cf77e.jpg', \n    'feaf96b0be5b.jpg', \n    '770ef89c8d56.jpg', \n    '0b533907be09.jpg', \n    '502e1f43e762.jpg', \n    'ef327fad7d34.jpg',\n    'b5fec685e2e8.jpg'\n]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:53:26.834024Z","iopub.execute_input":"2023-06-02T09:53:26.834415Z","iopub.status.idle":"2023-06-02T09:53:26.840363Z","shell.execute_reply.started":"2023-06-02T09:53:26.834377Z","shell.execute_reply":"2023-06-02T09:53:26.838864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[0]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:53:34.167236Z","iopub.execute_input":"2023-06-02T09:53:34.167859Z","iopub.status.idle":"2023-06-02T09:53:34.173332Z","shell.execute_reply.started":"2023-06-02T09:53:34.167819Z","shell.execute_reply":"2023-06-02T09:53:34.171883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:53:40.461422Z","iopub.execute_input":"2023-06-02T09:53:40.462423Z","iopub.status.idle":"2023-06-02T09:53:40.533659Z","shell.execute_reply.started":"2023-06-02T09:53:40.462365Z","shell.execute_reply":"2023-06-02T09:53:40.532553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:53:41.005449Z","iopub.execute_input":"2023-06-02T09:53:41.006051Z","iopub.status.idle":"2023-06-02T09:53:41.041533Z","shell.execute_reply.started":"2023-06-02T09:53:41.006011Z","shell.execute_reply":"2023-06-02T09:53:41.040337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[1]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:53:56.786039Z","iopub.execute_input":"2023-06-02T09:53:56.786427Z","iopub.status.idle":"2023-06-02T09:53:56.792035Z","shell.execute_reply.started":"2023-06-02T09:53:56.786391Z","shell.execute_reply":"2023-06-02T09:53:56.790746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:04.704715Z","iopub.execute_input":"2023-06-02T09:54:04.705226Z","iopub.status.idle":"2023-06-02T09:54:04.783877Z","shell.execute_reply.started":"2023-06-02T09:54:04.705177Z","shell.execute_reply":"2023-06-02T09:54:04.782826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:05.205891Z","iopub.execute_input":"2023-06-02T09:54:05.206853Z","iopub.status.idle":"2023-06-02T09:54:05.239150Z","shell.execute_reply.started":"2023-06-02T09:54:05.206798Z","shell.execute_reply":"2023-06-02T09:54:05.237997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[2]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:11.070517Z","iopub.execute_input":"2023-06-02T09:54:11.070904Z","iopub.status.idle":"2023-06-02T09:54:11.076448Z","shell.execute_reply.started":"2023-06-02T09:54:11.070866Z","shell.execute_reply":"2023-06-02T09:54:11.075310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:16.774382Z","iopub.execute_input":"2023-06-02T09:54:16.774830Z","iopub.status.idle":"2023-06-02T09:54:16.846355Z","shell.execute_reply.started":"2023-06-02T09:54:16.774781Z","shell.execute_reply":"2023-06-02T09:54:16.845003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:16.903416Z","iopub.execute_input":"2023-06-02T09:54:16.903725Z","iopub.status.idle":"2023-06-02T09:54:16.934742Z","shell.execute_reply.started":"2023-06-02T09:54:16.903694Z","shell.execute_reply":"2023-06-02T09:54:16.933572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[3]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:28.245227Z","iopub.execute_input":"2023-06-02T09:54:28.246203Z","iopub.status.idle":"2023-06-02T09:54:28.251226Z","shell.execute_reply.started":"2023-06-02T09:54:28.246161Z","shell.execute_reply":"2023-06-02T09:54:28.249868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:33.559797Z","iopub.execute_input":"2023-06-02T09:54:33.560743Z","iopub.status.idle":"2023-06-02T09:54:33.627295Z","shell.execute_reply.started":"2023-06-02T09:54:33.560688Z","shell.execute_reply":"2023-06-02T09:54:33.626089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:33.629712Z","iopub.execute_input":"2023-06-02T09:54:33.630559Z","iopub.status.idle":"2023-06-02T09:54:33.661132Z","shell.execute_reply.started":"2023-06-02T09:54:33.630513Z","shell.execute_reply":"2023-06-02T09:54:33.660004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[4]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:38.906226Z","iopub.execute_input":"2023-06-02T09:54:38.907326Z","iopub.status.idle":"2023-06-02T09:54:38.913126Z","shell.execute_reply.started":"2023-06-02T09:54:38.907254Z","shell.execute_reply":"2023-06-02T09:54:38.911638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:44.570696Z","iopub.execute_input":"2023-06-02T09:54:44.571212Z","iopub.status.idle":"2023-06-02T09:54:44.639294Z","shell.execute_reply.started":"2023-06-02T09:54:44.571170Z","shell.execute_reply":"2023-06-02T09:54:44.638208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:45.092245Z","iopub.execute_input":"2023-06-02T09:54:45.093250Z","iopub.status.idle":"2023-06-02T09:54:45.117246Z","shell.execute_reply.started":"2023-06-02T09:54:45.093202Z","shell.execute_reply":"2023-06-02T09:54:45.116090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[5]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:54:52.957134Z","iopub.execute_input":"2023-06-02T09:54:52.958171Z","iopub.status.idle":"2023-06-02T09:54:52.963196Z","shell.execute_reply.started":"2023-06-02T09:54:52.958130Z","shell.execute_reply":"2023-06-02T09:54:52.962083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:00.296383Z","iopub.execute_input":"2023-06-02T09:55:00.297174Z","iopub.status.idle":"2023-06-02T09:55:00.363298Z","shell.execute_reply.started":"2023-06-02T09:55:00.297133Z","shell.execute_reply":"2023-06-02T09:55:00.361713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:00.448335Z","iopub.execute_input":"2023-06-02T09:55:00.449174Z","iopub.status.idle":"2023-06-02T09:55:00.478703Z","shell.execute_reply.started":"2023-06-02T09:55:00.449128Z","shell.execute_reply":"2023-06-02T09:55:00.477571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[6]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:07.122678Z","iopub.execute_input":"2023-06-02T09:55:07.123189Z","iopub.status.idle":"2023-06-02T09:55:07.128254Z","shell.execute_reply.started":"2023-06-02T09:55:07.123149Z","shell.execute_reply":"2023-06-02T09:55:07.126987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:12.425691Z","iopub.execute_input":"2023-06-02T09:55:12.426445Z","iopub.status.idle":"2023-06-02T09:55:12.496901Z","shell.execute_reply.started":"2023-06-02T09:55:12.426403Z","shell.execute_reply":"2023-06-02T09:55:12.495890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:12.958152Z","iopub.execute_input":"2023-06-02T09:55:12.958728Z","iopub.status.idle":"2023-06-02T09:55:12.985538Z","shell.execute_reply.started":"2023-06-02T09:55:12.958682Z","shell.execute_reply":"2023-06-02T09:55:12.984365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[7]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:32.500097Z","iopub.execute_input":"2023-06-02T09:55:32.501189Z","iopub.status.idle":"2023-06-02T09:55:32.506736Z","shell.execute_reply.started":"2023-06-02T09:55:32.501142Z","shell.execute_reply":"2023-06-02T09:55:32.505114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:41.797441Z","iopub.execute_input":"2023-06-02T09:55:41.798371Z","iopub.status.idle":"2023-06-02T09:55:41.869692Z","shell.execute_reply.started":"2023-06-02T09:55:41.798318Z","shell.execute_reply":"2023-06-02T09:55:41.868529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:55:53.328304Z","iopub.execute_input":"2023-06-02T09:55:53.328776Z","iopub.status.idle":"2023-06-02T09:55:53.361272Z","shell.execute_reply.started":"2023-06-02T09:55:53.328729Z","shell.execute_reply":"2023-06-02T09:55:53.360099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[8]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:56:21.126853Z","iopub.execute_input":"2023-06-02T09:56:21.127618Z","iopub.status.idle":"2023-06-02T09:56:21.132368Z","shell.execute_reply.started":"2023-06-02T09:56:21.127575Z","shell.execute_reply":"2023-06-02T09:56:21.131155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:56:31.162868Z","iopub.execute_input":"2023-06-02T09:56:31.163592Z","iopub.status.idle":"2023-06-02T09:56:31.232473Z","shell.execute_reply.started":"2023-06-02T09:56:31.163552Z","shell.execute_reply":"2023-06-02T09:56:31.231329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:56:41.336088Z","iopub.execute_input":"2023-06-02T09:56:41.336570Z","iopub.status.idle":"2023-06-02T09:56:41.428282Z","shell.execute_reply.started":"2023-06-02T09:56:41.336521Z","shell.execute_reply":"2023-06-02T09:56:41.427244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[9]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:57:00.291231Z","iopub.execute_input":"2023-06-02T09:57:00.291632Z","iopub.status.idle":"2023-06-02T09:57:00.297088Z","shell.execute_reply.started":"2023-06-02T09:57:00.291595Z","shell.execute_reply":"2023-06-02T09:57:00.295799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_line_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:57:10.038288Z","iopub.execute_input":"2023-06-02T09:57:10.038905Z","iopub.status.idle":"2023-06-02T09:57:10.105667Z","shell.execute_reply.started":"2023-06-02T09:57:10.038866Z","shell.execute_reply":"2023-06-02T09:57:10.104552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_with_bbs = get_img_with_bbs(img_file_name, postprocessed_bboxes)\nimg_with_bbs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:57:21.040891Z","iopub.execute_input":"2023-06-02T09:57:21.041631Z","iopub.status.idle":"2023-06-02T09:57:21.076436Z","shell.execute_reply.started":"2023-06-02T09:57:21.041592Z","shell.execute_reply":"2023-06-02T09:57:21.075273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"print(\"That's all!\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T09:57:30.111077Z","iopub.execute_input":"2023-06-02T09:57:30.112057Z","iopub.status.idle":"2023-06-02T09:57:30.119076Z","shell.execute_reply.started":"2023-06-02T09:57:30.111998Z","shell.execute_reply":"2023-06-02T09:57:30.117728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}