{"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-05-29T12:34:32.188075Z","iopub.execute_input":"2023-05-29T12:34:32.188902Z","iopub.status.idle":"2023-05-29T12:34:34.507566Z","shell.execute_reply.started":"2023-05-29T12:34:32.188861Z","shell.execute_reply":"2023-05-29T12:34:34.506512Z"},"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-05-29T12:34:40.378410Z","iopub.execute_input":"2023-05-29T12:34:40.379725Z","iopub.status.idle":"2023-05-29T12:34:40.386401Z","shell.execute_reply.started":"2023-05-29T12:34:40.379671Z","shell.execute_reply":"2023-05-29T12:34:40.385193Z"},"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-05-29T12:34:55.282303Z","iopub.execute_input":"2023-05-29T12:34:55.283265Z","iopub.status.idle":"2023-05-29T12:34:55.292514Z","shell.execute_reply.started":"2023-05-29T12:34:55.283208Z","shell.execute_reply":"2023-05-29T12:34:55.291330Z"},"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-05-29T12:34:55.840102Z","iopub.execute_input":"2023-05-29T12:34:55.842398Z","iopub.status.idle":"2023-05-29T12:34:55.850217Z","shell.execute_reply.started":"2023-05-29T12:34:55.842353Z","shell.execute_reply":"2023-05-29T12:34:55.849076Z"},"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-05-29T12:34:58.066041Z","iopub.execute_input":"2023-05-29T12:34:58.066442Z","iopub.status.idle":"2023-05-29T12:34:58.299241Z","shell.execute_reply.started":"2023-05-29T12:34:58.066405Z","shell.execute_reply":"2023-05-29T12:34:58.298033Z"},"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-05-29T12:34:58.442097Z","iopub.execute_input":"2023-05-29T12:34:58.443081Z","iopub.status.idle":"2023-05-29T12:34:58.449051Z","shell.execute_reply.started":"2023-05-29T12:34:58.443033Z","shell.execute_reply":"2023-05-29T12:34:58.447717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_tick_label_backbone = resnet50_fpn_fn(pretrained=False)\nx_tick_label_backbone","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:34:58.866491Z","iopub.execute_input":"2023-05-29T12:34:58.867570Z","iopub.status.idle":"2023-05-29T12:34:59.370953Z","shell.execute_reply.started":"2023-05-29T12:34:58.867511Z","shell.execute_reply":"2023-05-29T12:34:59.369784Z"},"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-05-29T12:35:07.678299Z","iopub.execute_input":"2023-05-29T12:35:07.679010Z","iopub.status.idle":"2023-05-29T12:35:07.685514Z","shell.execute_reply.started":"2023-05-29T12:35:07.678968Z","shell.execute_reply":"2023-05-29T12:35:07.684367Z"},"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-05-29T12:35:09.977661Z","iopub.execute_input":"2023-05-29T12:35:09.978681Z","iopub.status.idle":"2023-05-29T12:35:09.985110Z","shell.execute_reply.started":"2023-05-29T12:35:09.978626Z","shell.execute_reply":"2023-05-29T12:35:09.984019Z"},"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-05-29T12:35:10.252723Z","iopub.execute_input":"2023-05-29T12:35:10.253074Z","iopub.status.idle":"2023-05-29T12:35:10.259414Z","shell.execute_reply.started":"2023-05-29T12:35:10.253040Z","shell.execute_reply":"2023-05-29T12:35:10.258131Z"},"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-05-29T12:35:12.266108Z","iopub.execute_input":"2023-05-29T12:35:12.266724Z","iopub.status.idle":"2023-05-29T12:35:12.273556Z","shell.execute_reply.started":"2023-05-29T12:35:12.266685Z","shell.execute_reply":"2023-05-29T12:35:12.272235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_tick_label_model = get_model(num_classes=2, backbone=x_tick_label_backbone)\nx_tick_label_model","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:35:12.743327Z","iopub.execute_input":"2023-05-29T12:35:12.744015Z","iopub.status.idle":"2023-05-29T12:35:12.961233Z","shell.execute_reply.started":"2023-05-29T12:35:12.743976Z","shell.execute_reply":"2023-05-29T12:35:12.960087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_tick_label_model.load_state_dict(torch.load('/kaggle/input/b-m-g-a-extra-data/x_tick_label_6.pth'))\n# x_tick_label_model.load_state_dict(torch.load('/kaggle/input/b-m-g-a-extra-data/x_tick_label__9.pth'))","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:50:28.198355Z","iopub.execute_input":"2023-05-29T12:50:28.199410Z","iopub.status.idle":"2023-05-29T12:50:30.008225Z","shell.execute_reply.started":"2023-05-29T12:50:28.199355Z","shell.execute_reply":"2023-05-29T12:50:30.007073Z"},"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-05-29T12:50:30.010265Z","iopub.execute_input":"2023-05-29T12:50:30.010552Z","iopub.status.idle":"2023-05-29T12:50:30.018313Z","shell.execute_reply.started":"2023-05-29T12:50:30.010523Z","shell.execute_reply":"2023-05-29T12:50:30.017196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_tick_label_model = x_tick_label_model.to(device)\nx_tick_label_model.eval();","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:50:30.020080Z","iopub.execute_input":"2023-05-29T12:50:30.020828Z","iopub.status.idle":"2023-05-29T12:50:30.031622Z","shell.execute_reply.started":"2023-05-29T12:50:30.020788Z","shell.execute_reply":"2023-05-29T12:50:30.030636Z"},"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-05-29T12:36:00.549633Z","iopub.execute_input":"2023-05-29T12:36:00.550030Z","iopub.status.idle":"2023-05-29T12:36:00.555702Z","shell.execute_reply.started":"2023-05-29T12:36:00.549993Z","shell.execute_reply":"2023-05-29T12:36:00.554196Z"},"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-05-29T12:36:16.186882Z","iopub.execute_input":"2023-05-29T12:36:16.187386Z","iopub.status.idle":"2023-05-29T12:36:16.195110Z","shell.execute_reply.started":"2023-05-29T12:36:16.187346Z","shell.execute_reply":"2023-05-29T12:36:16.193860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import albumentations as A\n\nx_tick_label_tfms_list = [\n    A.LongestMaxSize(always_apply=False, p=1, max_size=896, interpolation=1),\n    A.PadIfNeeded(always_apply=False, p=1.0, min_height=896, min_width=896, 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-05-29T12:36:16.719229Z","iopub.execute_input":"2023-05-29T12:36:16.719591Z","iopub.status.idle":"2023-05-29T12:36:18.049876Z","shell.execute_reply.started":"2023-05-29T12:36:16.719556Z","shell.execute_reply":"2023-05-29T12:36:18.048645Z"},"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-05-29T12:36:18.778459Z","iopub.execute_input":"2023-05-29T12:36:18.779413Z","iopub.status.idle":"2023-05-29T12:36:18.787289Z","shell.execute_reply.started":"2023-05-29T12:36:18.779370Z","shell.execute_reply":"2023-05-29T12:36:18.786053Z"},"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-05-29T12:36:19.066609Z","iopub.execute_input":"2023-05-29T12:36:19.066952Z","iopub.status.idle":"2023-05-29T12:36:19.075602Z","shell.execute_reply.started":"2023-05-29T12:36:19.066919Z","shell.execute_reply":"2023-05-29T12:36:19.072915Z"},"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-05-29T12:36:21.040667Z","iopub.execute_input":"2023-05-29T12:36:21.041640Z","iopub.status.idle":"2023-05-29T12:36:21.050217Z","shell.execute_reply.started":"2023-05-29T12:36:21.041574Z","shell.execute_reply":"2023-05-29T12:36:21.049029Z"},"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-05-29T12:36:21.262408Z","iopub.execute_input":"2023-05-29T12:36:21.262765Z","iopub.status.idle":"2023-05-29T12:36:21.272307Z","shell.execute_reply.started":"2023-05-29T12:36:21.262731Z","shell.execute_reply":"2023-05-29T12:36:21.271174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BBox = namedtuple(\"BBox\", \"xmin, ymin, xmax, ymax\")","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:36:23.307501Z","iopub.execute_input":"2023-05-29T12:36:23.308451Z","iopub.status.idle":"2023-05-29T12:36:23.314355Z","shell.execute_reply.started":"2023-05-29T12:36:23.308395Z","shell.execute_reply":"2023-05-29T12:36:23.313150Z"},"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-05-29T12:36:23.580458Z","iopub.execute_input":"2023-05-29T12:36:23.580800Z","iopub.status.idle":"2023-05-29T12:36:23.592312Z","shell.execute_reply.started":"2023-05-29T12:36:23.580767Z","shell.execute_reply":"2023-05-29T12:36:23.591210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference on 8 Randomly Selected Images","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-05-29T12:36:27.309004Z","iopub.execute_input":"2023-05-29T12:36:27.309717Z","iopub.status.idle":"2023-05-29T12:36:28.276236Z","shell.execute_reply.started":"2023-05-29T12:36:27.309677Z","shell.execute_reply":"2023-05-29T12:36:28.274908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = path/'train'\n!ls {train_path}","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:36:28.279195Z","iopub.execute_input":"2023-05-29T12:36:28.279659Z","iopub.status.idle":"2023-05-29T12:36:29.244392Z","shell.execute_reply.started":"2023-05-29T12:36:28.279602Z","shell.execute_reply":"2023-05-29T12:36:29.243055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_path = train_path/'images'","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:36:29.987172Z","iopub.execute_input":"2023-05-29T12:36:29.988369Z","iopub.status.idle":"2023-05-29T12:36:29.997254Z","shell.execute_reply.started":"2023-05-29T12:36:29.988322Z","shell.execute_reply":"2023-05-29T12:36:29.996102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's run inference on the 8 randomly selected images in the <a href=\"https://www.kaggle.com/code/sambitmukherjee/x-tick-label-detection-training\" target=\"_blank\">training notebook</a>'s \"Model Evaluation\" section.","metadata":{}},{"cell_type":"code","source":"random_sample = [\n    '070fab0a5cbb.jpg',\n    'b95f5123f7e2.jpg',\n    'affe8a5ed69b.jpg',\n    '4c34d3420ad3.jpg',\n    'a0e555df58f3.jpg',\n    'e7f3392d436c.jpg',\n    'd5101ec46557.jpg',\n    '5cbcc46a6eed.jpg'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:43:58.049299Z","iopub.execute_input":"2023-05-29T12:43:58.049685Z","iopub.status.idle":"2023-05-29T12:43:58.055427Z","shell.execute_reply.started":"2023-05-29T12:43:58.049644Z","shell.execute_reply":"2023-05-29T12:43:58.053901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from albumentations.pytorch.transforms import ToTensorV2\n\nx_tick_label_transforms = A.Compose([\n    A.LongestMaxSize(always_apply=False, p=1, max_size=896, interpolation=1),\n    A.PadIfNeeded(always_apply=False, p=1.0, min_height=896, min_width=896, 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])\nx_tick_label_transforms","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:37:31.072752Z","iopub.execute_input":"2023-05-29T12:37:31.073161Z","iopub.status.idle":"2023-05-29T12:37:31.088734Z","shell.execute_reply.started":"2023-05-29T12:37:31.073099Z","shell.execute_reply":"2023-05-29T12:37:31.087495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:37:33.460223Z","iopub.execute_input":"2023-05-29T12:37:33.461385Z","iopub.status.idle":"2023-05-29T12:37:33.467539Z","shell.execute_reply.started":"2023-05-29T12:37:33.461328Z","shell.execute_reply":"2023-05-29T12:37:33.465323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_threshold = 0.5","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:37:33.828808Z","iopub.execute_input":"2023-05-29T12:37:33.829508Z","iopub.status.idle":"2023-05-29T12:37:33.834561Z","shell.execute_reply.started":"2023-05-29T12:37:33.829469Z","shell.execute_reply":"2023-05-29T12:37:33.833470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_x_tick_label_bboxes(img_file_name):\n    img = Image.open(images_path/img_file_name)\n    img_arr = np.array(img)\n    transformed = x_tick_label_transforms(image=img_arr)\n    batched = transformed['image'].unsqueeze(0)\n    batched = batched.to(device)\n    with torch.no_grad():\n        out = x_tick_label_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=x_tick_label_tfms_list, h_after=896, w_after=896)\n        postprocessed_bboxes.append(list(new_bbox))\n    return postprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:37:36.080739Z","iopub.execute_input":"2023-05-29T12:37:36.081135Z","iopub.status.idle":"2023-05-29T12:37:36.092030Z","shell.execute_reply.started":"2023-05-29T12:37:36.081082Z","shell.execute_reply":"2023-05-29T12:37:36.090896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_img_with_bbs(img_file_name, postprocessed_bboxes):\n    img = Image.open(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-05-29T12:37:36.285624Z","iopub.execute_input":"2023-05-29T12:37:36.285976Z","iopub.status.idle":"2023-05-29T12:37:36.293031Z","shell.execute_reply.started":"2023-05-29T12:37:36.285942Z","shell.execute_reply":"2023-05-29T12:37:36.291822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[0]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:44:08.067958Z","iopub.execute_input":"2023-05-29T12:44:08.068678Z","iopub.status.idle":"2023-05-29T12:44:08.076021Z","shell.execute_reply.started":"2023-05-29T12:44:08.068629Z","shell.execute_reply":"2023-05-29T12:44:08.074850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:44:08.373768Z","iopub.execute_input":"2023-05-29T12:44:08.374990Z","iopub.status.idle":"2023-05-29T12:44:08.460660Z","shell.execute_reply.started":"2023-05-29T12:44:08.374938Z","shell.execute_reply":"2023-05-29T12:44:08.459545Z"},"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-05-29T12:44:17.535097Z","iopub.execute_input":"2023-05-29T12:44:17.535600Z","iopub.status.idle":"2023-05-29T12:44:17.568481Z","shell.execute_reply.started":"2023-05-29T12:44:17.535556Z","shell.execute_reply":"2023-05-29T12:44:17.567498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[1]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:44:29.521049Z","iopub.execute_input":"2023-05-29T12:44:29.521820Z","iopub.status.idle":"2023-05-29T12:44:29.528597Z","shell.execute_reply.started":"2023-05-29T12:44:29.521780Z","shell.execute_reply":"2023-05-29T12:44:29.527539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:44:29.560474Z","iopub.execute_input":"2023-05-29T12:44:29.561068Z","iopub.status.idle":"2023-05-29T12:44:29.650002Z","shell.execute_reply.started":"2023-05-29T12:44:29.561033Z","shell.execute_reply":"2023-05-29T12:44:29.648828Z"},"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-05-29T12:44:38.838626Z","iopub.execute_input":"2023-05-29T12:44:38.839012Z","iopub.status.idle":"2023-05-29T12:44:38.862144Z","shell.execute_reply.started":"2023-05-29T12:44:38.838976Z","shell.execute_reply":"2023-05-29T12:44:38.861162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[2]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:44:48.216819Z","iopub.execute_input":"2023-05-29T12:44:48.217453Z","iopub.status.idle":"2023-05-29T12:44:48.226207Z","shell.execute_reply.started":"2023-05-29T12:44:48.217393Z","shell.execute_reply":"2023-05-29T12:44:48.224921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:44:48.315416Z","iopub.execute_input":"2023-05-29T12:44:48.317629Z","iopub.status.idle":"2023-05-29T12:44:48.411113Z","shell.execute_reply.started":"2023-05-29T12:44:48.317578Z","shell.execute_reply":"2023-05-29T12:44:48.409980Z"},"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-05-29T12:44:56.173261Z","iopub.execute_input":"2023-05-29T12:44:56.174222Z","iopub.status.idle":"2023-05-29T12:44:56.196356Z","shell.execute_reply.started":"2023-05-29T12:44:56.174165Z","shell.execute_reply":"2023-05-29T12:44:56.195192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[3]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:03.952005Z","iopub.execute_input":"2023-05-29T12:45:03.952722Z","iopub.status.idle":"2023-05-29T12:45:03.959423Z","shell.execute_reply.started":"2023-05-29T12:45:03.952681Z","shell.execute_reply":"2023-05-29T12:45:03.958347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:03.981251Z","iopub.execute_input":"2023-05-29T12:45:03.981541Z","iopub.status.idle":"2023-05-29T12:45:04.071152Z","shell.execute_reply.started":"2023-05-29T12:45:03.981513Z","shell.execute_reply":"2023-05-29T12:45:04.070157Z"},"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-05-29T12:45:11.707828Z","iopub.execute_input":"2023-05-29T12:45:11.708232Z","iopub.status.idle":"2023-05-29T12:45:11.742338Z","shell.execute_reply.started":"2023-05-29T12:45:11.708193Z","shell.execute_reply":"2023-05-29T12:45:11.741196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[4]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:20.728081Z","iopub.execute_input":"2023-05-29T12:45:20.729225Z","iopub.status.idle":"2023-05-29T12:45:20.738104Z","shell.execute_reply.started":"2023-05-29T12:45:20.729158Z","shell.execute_reply":"2023-05-29T12:45:20.736770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:20.740561Z","iopub.execute_input":"2023-05-29T12:45:20.740947Z","iopub.status.idle":"2023-05-29T12:45:20.832320Z","shell.execute_reply.started":"2023-05-29T12:45:20.740908Z","shell.execute_reply":"2023-05-29T12:45:20.831187Z"},"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-05-29T12:45:28.092049Z","iopub.execute_input":"2023-05-29T12:45:28.092795Z","iopub.status.idle":"2023-05-29T12:45:28.122930Z","shell.execute_reply.started":"2023-05-29T12:45:28.092754Z","shell.execute_reply":"2023-05-29T12:45:28.121854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[5]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:37.209400Z","iopub.execute_input":"2023-05-29T12:45:37.209992Z","iopub.status.idle":"2023-05-29T12:45:37.218268Z","shell.execute_reply.started":"2023-05-29T12:45:37.209947Z","shell.execute_reply":"2023-05-29T12:45:37.216835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:37.536074Z","iopub.execute_input":"2023-05-29T12:45:37.537002Z","iopub.status.idle":"2023-05-29T12:45:37.621481Z","shell.execute_reply.started":"2023-05-29T12:45:37.536966Z","shell.execute_reply":"2023-05-29T12:45:37.620379Z"},"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-05-29T12:45:45.384027Z","iopub.execute_input":"2023-05-29T12:45:45.384744Z","iopub.status.idle":"2023-05-29T12:45:45.408810Z","shell.execute_reply.started":"2023-05-29T12:45:45.384704Z","shell.execute_reply":"2023-05-29T12:45:45.407714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[6]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:52.487332Z","iopub.execute_input":"2023-05-29T12:45:52.487715Z","iopub.status.idle":"2023-05-29T12:45:52.494866Z","shell.execute_reply.started":"2023-05-29T12:45:52.487681Z","shell.execute_reply":"2023-05-29T12:45:52.493692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:45:52.763923Z","iopub.execute_input":"2023-05-29T12:45:52.764291Z","iopub.status.idle":"2023-05-29T12:45:52.849677Z","shell.execute_reply.started":"2023-05-29T12:45:52.764258Z","shell.execute_reply":"2023-05-29T12:45:52.848575Z"},"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-05-29T12:46:01.032264Z","iopub.execute_input":"2023-05-29T12:46:01.033323Z","iopub.status.idle":"2023-05-29T12:46:01.059490Z","shell.execute_reply.started":"2023-05-29T12:46:01.033279Z","shell.execute_reply":"2023-05-29T12:46:01.058407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = random_sample[7]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:46:07.962968Z","iopub.execute_input":"2023-05-29T12:46:07.963375Z","iopub.status.idle":"2023-05-29T12:46:07.970355Z","shell.execute_reply.started":"2023-05-29T12:46:07.963339Z","shell.execute_reply":"2023-05-29T12:46:07.969260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:46:07.972553Z","iopub.execute_input":"2023-05-29T12:46:07.973631Z","iopub.status.idle":"2023-05-29T12:46:08.064005Z","shell.execute_reply.started":"2023-05-29T12:46:07.973591Z","shell.execute_reply":"2023-05-29T12:46:08.062931Z"},"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-05-29T12:46:15.270170Z","iopub.execute_input":"2023-05-29T12:46:15.270570Z","iopub.status.idle":"2023-05-29T12:46:15.298454Z","shell.execute_reply.started":"2023-05-29T12:46:15.270535Z","shell.execute_reply":"2023-05-29T12:46:15.297291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference on 7 Top Loss Images","metadata":{}},{"cell_type":"markdown","source":"Let's run inference on the 7 top loss images from the <a href=\"https://www.kaggle.com/code/sambitmukherjee/x-tick-label-detection-training\" target=\"_blank\">training notebook</a>'s \"Model Evaluation\" section.","metadata":{}},{"cell_type":"code","source":"top_loss_images = [\n    'e832d98c37b2.jpg',\n    'a4dfb7b483fd.jpg',\n    '19cef86ee374.jpg',\n    '9566fffd6e0e.jpg',\n    '46ac53a6b82a.jpg',\n    '7e6e3c247c33.jpg',\n    'd1c4f30988ad.jpg', \n]","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:51:01.093732Z","iopub.execute_input":"2023-05-29T12:51:01.094438Z","iopub.status.idle":"2023-05-29T12:51:01.099960Z","shell.execute_reply.started":"2023-05-29T12:51:01.094397Z","shell.execute_reply":"2023-05-29T12:51:01.098535Z"},"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-05-29T12:51:02.410191Z","iopub.execute_input":"2023-05-29T12:51:02.411487Z","iopub.status.idle":"2023-05-29T12:51:02.416824Z","shell.execute_reply.started":"2023-05-29T12:51:02.411438Z","shell.execute_reply":"2023-05-29T12:51:02.415515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:51:02.795456Z","iopub.execute_input":"2023-05-29T12:51:02.795937Z","iopub.status.idle":"2023-05-29T12:51:02.912523Z","shell.execute_reply.started":"2023-05-29T12:51:02.795892Z","shell.execute_reply":"2023-05-29T12:51:02.906784Z"},"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-05-29T12:51:10.322884Z","iopub.execute_input":"2023-05-29T12:51:10.323289Z","iopub.status.idle":"2023-05-29T12:51:10.359758Z","shell.execute_reply.started":"2023-05-29T12:51:10.323251Z","shell.execute_reply":"2023-05-29T12:51:10.358752Z"},"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-05-29T12:51:17.069032Z","iopub.execute_input":"2023-05-29T12:51:17.069779Z","iopub.status.idle":"2023-05-29T12:51:17.074330Z","shell.execute_reply.started":"2023-05-29T12:51:17.069740Z","shell.execute_reply":"2023-05-29T12:51:17.073262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:51:17.223279Z","iopub.execute_input":"2023-05-29T12:51:17.223649Z","iopub.status.idle":"2023-05-29T12:51:17.319272Z","shell.execute_reply.started":"2023-05-29T12:51:17.223608Z","shell.execute_reply":"2023-05-29T12:51:17.318134Z"},"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-05-29T12:51:24.892630Z","iopub.execute_input":"2023-05-29T12:51:24.893013Z","iopub.status.idle":"2023-05-29T12:51:24.917076Z","shell.execute_reply.started":"2023-05-29T12:51:24.892977Z","shell.execute_reply":"2023-05-29T12:51:24.916029Z"},"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-05-29T12:51:46.487200Z","iopub.execute_input":"2023-05-29T12:51:46.488254Z","iopub.status.idle":"2023-05-29T12:51:46.493005Z","shell.execute_reply.started":"2023-05-29T12:51:46.488212Z","shell.execute_reply":"2023-05-29T12:51:46.491651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:51:46.651258Z","iopub.execute_input":"2023-05-29T12:51:46.651856Z","iopub.status.idle":"2023-05-29T12:51:46.739947Z","shell.execute_reply.started":"2023-05-29T12:51:46.651816Z","shell.execute_reply":"2023-05-29T12:51:46.738795Z"},"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-05-29T12:51:54.392052Z","iopub.execute_input":"2023-05-29T12:51:54.392793Z","iopub.status.idle":"2023-05-29T12:51:54.431400Z","shell.execute_reply.started":"2023-05-29T12:51:54.392752Z","shell.execute_reply":"2023-05-29T12:51:54.430204Z"},"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-05-29T12:52:08.178950Z","iopub.execute_input":"2023-05-29T12:52:08.179670Z","iopub.status.idle":"2023-05-29T12:52:08.185176Z","shell.execute_reply.started":"2023-05-29T12:52:08.179628Z","shell.execute_reply":"2023-05-29T12:52:08.183697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:52:08.434443Z","iopub.execute_input":"2023-05-29T12:52:08.435406Z","iopub.status.idle":"2023-05-29T12:52:08.523204Z","shell.execute_reply.started":"2023-05-29T12:52:08.435352Z","shell.execute_reply":"2023-05-29T12:52:08.522089Z"},"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-05-29T12:52:20.746493Z","iopub.execute_input":"2023-05-29T12:52:20.746885Z","iopub.status.idle":"2023-05-29T12:52:20.800841Z","shell.execute_reply.started":"2023-05-29T12:52:20.746850Z","shell.execute_reply":"2023-05-29T12:52:20.799811Z"},"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-05-29T12:52:26.349565Z","iopub.execute_input":"2023-05-29T12:52:26.350197Z","iopub.status.idle":"2023-05-29T12:52:26.354925Z","shell.execute_reply.started":"2023-05-29T12:52:26.350148Z","shell.execute_reply":"2023-05-29T12:52:26.353769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:52:26.493460Z","iopub.execute_input":"2023-05-29T12:52:26.494065Z","iopub.status.idle":"2023-05-29T12:52:26.590940Z","shell.execute_reply.started":"2023-05-29T12:52:26.494022Z","shell.execute_reply":"2023-05-29T12:52:26.589773Z"},"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-05-29T12:52:35.079592Z","iopub.execute_input":"2023-05-29T12:52:35.079992Z","iopub.status.idle":"2023-05-29T12:52:35.121795Z","shell.execute_reply.started":"2023-05-29T12:52:35.079954Z","shell.execute_reply":"2023-05-29T12:52:35.120798Z"},"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-05-29T12:53:27.048801Z","iopub.execute_input":"2023-05-29T12:53:27.049244Z","iopub.status.idle":"2023-05-29T12:53:27.054586Z","shell.execute_reply.started":"2023-05-29T12:53:27.049206Z","shell.execute_reply":"2023-05-29T12:53:27.053446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:53:27.498900Z","iopub.execute_input":"2023-05-29T12:53:27.500011Z","iopub.status.idle":"2023-05-29T12:53:27.588680Z","shell.execute_reply.started":"2023-05-29T12:53:27.499968Z","shell.execute_reply":"2023-05-29T12:53:27.587592Z"},"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-05-29T12:53:34.306122Z","iopub.execute_input":"2023-05-29T12:53:34.306645Z","iopub.status.idle":"2023-05-29T12:53:34.372182Z","shell.execute_reply.started":"2023-05-29T12:53:34.306599Z","shell.execute_reply":"2023-05-29T12:53:34.371089Z"},"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-05-29T12:53:50.135108Z","iopub.execute_input":"2023-05-29T12:53:50.135818Z","iopub.status.idle":"2023-05-29T12:53:50.141041Z","shell.execute_reply.started":"2023-05-29T12:53:50.135778Z","shell.execute_reply":"2023-05-29T12:53:50.139684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_x_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-29T12:53:50.277702Z","iopub.execute_input":"2023-05-29T12:53:50.278031Z","iopub.status.idle":"2023-05-29T12:53:50.363173Z","shell.execute_reply.started":"2023-05-29T12:53:50.277999Z","shell.execute_reply":"2023-05-29T12:53:50.362058Z"},"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-05-29T12:53:57.053451Z","iopub.execute_input":"2023-05-29T12:53:57.053910Z","iopub.status.idle":"2023-05-29T12:53:57.090178Z","shell.execute_reply.started":"2023-05-29T12:53:57.053867Z","shell.execute_reply":"2023-05-29T12:53:57.089085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"print(\"That's all!\")","metadata":{},"execution_count":null,"outputs":[]}]}