{"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-22T05:12:10.456869Z","iopub.execute_input":"2023-05-22T05:12:10.457391Z","iopub.status.idle":"2023-05-22T05:12:12.834393Z","shell.execute_reply.started":"2023-05-22T05:12:10.457351Z","shell.execute_reply":"2023-05-22T05:12:12.833323Z"},"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-22T05:12:42.712843Z","iopub.execute_input":"2023-05-22T05:12:42.714112Z","iopub.status.idle":"2023-05-22T05:12:42.721265Z","shell.execute_reply.started":"2023-05-22T05:12:42.714038Z","shell.execute_reply":"2023-05-22T05:12:42.719956Z"},"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-22T05:13:23.714614Z","iopub.execute_input":"2023-05-22T05:13:23.715076Z","iopub.status.idle":"2023-05-22T05:13:23.723308Z","shell.execute_reply.started":"2023-05-22T05:13:23.715039Z","shell.execute_reply":"2023-05-22T05:13:23.722104Z"},"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-22T05:13:40.316920Z","iopub.execute_input":"2023-05-22T05:13:40.317675Z","iopub.status.idle":"2023-05-22T05:13:40.322950Z","shell.execute_reply.started":"2023-05-22T05:13:40.317634Z","shell.execute_reply":"2023-05-22T05:13:40.321391Z"},"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-22T05:13:57.145296Z","iopub.execute_input":"2023-05-22T05:13:57.146142Z","iopub.status.idle":"2023-05-22T05:13:57.371884Z","shell.execute_reply.started":"2023-05-22T05:13:57.146078Z","shell.execute_reply":"2023-05-22T05:13:57.370868Z"},"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-22T05:14:18.355671Z","iopub.execute_input":"2023-05-22T05:14:18.356334Z","iopub.status.idle":"2023-05-22T05:14:18.361937Z","shell.execute_reply.started":"2023-05-22T05:14:18.356293Z","shell.execute_reply":"2023-05-22T05:14:18.360836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_tick_label_backbone = resnet50_fpn_fn(pretrained=False)\ny_tick_label_backbone","metadata":{"execution":{"iopub.status.busy":"2023-05-22T05:17:18.648519Z","iopub.execute_input":"2023-05-22T05:17:18.649578Z","iopub.status.idle":"2023-05-22T05:17:19.120621Z","shell.execute_reply.started":"2023-05-22T05:17:18.649521Z","shell.execute_reply":"2023-05-22T05:17:19.119401Z"},"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-22T05:15:23.123346Z","iopub.execute_input":"2023-05-22T05:15:23.124321Z","iopub.status.idle":"2023-05-22T05:15:23.131907Z","shell.execute_reply.started":"2023-05-22T05:15:23.124263Z","shell.execute_reply":"2023-05-22T05:15:23.130652Z"},"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-22T05:15:31.709743Z","iopub.execute_input":"2023-05-22T05:15:31.710149Z","iopub.status.idle":"2023-05-22T05:15:31.716067Z","shell.execute_reply.started":"2023-05-22T05:15:31.710090Z","shell.execute_reply":"2023-05-22T05:15:31.714834Z"},"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-22T05:15:47.954191Z","iopub.execute_input":"2023-05-22T05:15:47.954935Z","iopub.status.idle":"2023-05-22T05:15:47.961165Z","shell.execute_reply.started":"2023-05-22T05:15:47.954895Z","shell.execute_reply":"2023-05-22T05:15:47.960031Z"},"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-22T05:16:02.506809Z","iopub.execute_input":"2023-05-22T05:16:02.507226Z","iopub.status.idle":"2023-05-22T05:16:02.514111Z","shell.execute_reply.started":"2023-05-22T05:16:02.507187Z","shell.execute_reply":"2023-05-22T05:16:02.512937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_tick_label_model = get_model(num_classes=2, backbone=y_tick_label_backbone)\ny_tick_label_model","metadata":{"execution":{"iopub.status.busy":"2023-05-22T05:17:51.557589Z","iopub.execute_input":"2023-05-22T05:17:51.558527Z","iopub.status.idle":"2023-05-22T05:17:51.757449Z","shell.execute_reply.started":"2023-05-22T05:17:51.558486Z","shell.execute_reply":"2023-05-22T05:17:51.756167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_tick_label_model.load_state_dict(torch.load('/kaggle/input/b-m-g-a-extra-data/y_tick_label__6.pth'))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:25:45.759221Z","iopub.execute_input":"2023-05-22T06:25:45.759633Z","iopub.status.idle":"2023-05-22T06:25:45.935379Z","shell.execute_reply.started":"2023-05-22T06:25:45.759598Z","shell.execute_reply":"2023-05-22T06:25:45.934168Z"},"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-22T06:14:22.251483Z","iopub.execute_input":"2023-05-22T06:14:22.251862Z","iopub.status.idle":"2023-05-22T06:14:22.260350Z","shell.execute_reply.started":"2023-05-22T06:14:22.251825Z","shell.execute_reply":"2023-05-22T06:14:22.258947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_tick_label_model = y_tick_label_model.to(device)\ny_tick_label_model.eval();","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:14:23.417203Z","iopub.execute_input":"2023-05-22T06:14:23.417935Z","iopub.status.idle":"2023-05-22T06:14:23.428854Z","shell.execute_reply.started":"2023-05-22T06:14:23.417895Z","shell.execute_reply":"2023-05-22T06:14:23.427803Z"},"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-22T05:25:26.041489Z","iopub.execute_input":"2023-05-22T05:25:26.042326Z","iopub.status.idle":"2023-05-22T05:25:26.047983Z","shell.execute_reply.started":"2023-05-22T05:25:26.042281Z","shell.execute_reply":"2023-05-22T05:25:26.046887Z"},"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-22T05:25:38.113557Z","iopub.execute_input":"2023-05-22T05:25:38.114179Z","iopub.status.idle":"2023-05-22T05:25:38.121867Z","shell.execute_reply.started":"2023-05-22T05:25:38.114136Z","shell.execute_reply":"2023-05-22T05:25:38.120752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import albumentations as A\n\ny_tick_label_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-05-22T05:27:14.144373Z","iopub.execute_input":"2023-05-22T05:27:14.145445Z","iopub.status.idle":"2023-05-22T05:27:15.692263Z","shell.execute_reply.started":"2023-05-22T05:27:14.145403Z","shell.execute_reply":"2023-05-22T05:27:15.691213Z"},"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-22T05:27:21.657722Z","iopub.execute_input":"2023-05-22T05:27:21.658423Z","iopub.status.idle":"2023-05-22T05:27:21.664554Z","shell.execute_reply.started":"2023-05-22T05:27:21.658383Z","shell.execute_reply":"2023-05-22T05:27:21.663168Z"},"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-22T05:27:33.358200Z","iopub.execute_input":"2023-05-22T05:27:33.358743Z","iopub.status.idle":"2023-05-22T05:27:33.365286Z","shell.execute_reply.started":"2023-05-22T05:27:33.358701Z","shell.execute_reply":"2023-05-22T05:27:33.364030Z"},"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-22T05:27:39.854913Z","iopub.execute_input":"2023-05-22T05:27:39.855627Z","iopub.status.idle":"2023-05-22T05:27:39.870734Z","shell.execute_reply.started":"2023-05-22T05:27:39.855584Z","shell.execute_reply":"2023-05-22T05:27:39.869391Z"},"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-22T05:27:52.665723Z","iopub.execute_input":"2023-05-22T05:27:52.666114Z","iopub.status.idle":"2023-05-22T05:27:52.675750Z","shell.execute_reply.started":"2023-05-22T05:27:52.666063Z","shell.execute_reply":"2023-05-22T05:27:52.674619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BBox = namedtuple(\"BBox\", \"xmin, ymin, xmax, ymax\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T05:27:56.442625Z","iopub.execute_input":"2023-05-22T05:27:56.443574Z","iopub.status.idle":"2023-05-22T05:27:56.449340Z","shell.execute_reply.started":"2023-05-22T05:27:56.443517Z","shell.execute_reply":"2023-05-22T05:27:56.448136Z"},"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-22T05:28:24.859006Z","iopub.execute_input":"2023-05-22T05:28:24.859697Z","iopub.status.idle":"2023-05-22T05:28:24.871519Z","shell.execute_reply.started":"2023-05-22T05:28:24.859656Z","shell.execute_reply":"2023-05-22T05:28:24.870213Z"},"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-22T05:30:14.235927Z","iopub.execute_input":"2023-05-22T05:30:14.236346Z","iopub.status.idle":"2023-05-22T05:30:15.235213Z","shell.execute_reply.started":"2023-05-22T05:30:14.236311Z","shell.execute_reply":"2023-05-22T05:30:15.233904Z"},"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-22T05:30:26.439671Z","iopub.execute_input":"2023-05-22T05:30:26.440259Z","iopub.status.idle":"2023-05-22T05:30:27.534209Z","shell.execute_reply.started":"2023-05-22T05:30:26.440203Z","shell.execute_reply":"2023-05-22T05:30:27.532793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_path = train_path/'images'","metadata":{"execution":{"iopub.status.busy":"2023-05-22T05:30:38.238071Z","iopub.execute_input":"2023-05-22T05:30:38.238757Z","iopub.status.idle":"2023-05-22T05:30:38.244595Z","shell.execute_reply.started":"2023-05-22T05:30:38.238715Z","shell.execute_reply":"2023-05-22T05:30:38.243482Z"},"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/y-tick-label-detection-training\" target=\"_blank\">training notebook</a>'s \"Model Evaluation\" section.","metadata":{}},{"cell_type":"code","source":"random_sample = [\n    '606cecfc030f.jpg',\n    '659d2b57fa60.jpg',\n    '6906da4fa56a.jpg',\n    'd13586f30d95.jpg',\n    'a0e555df58f3.jpg',\n    '04f1727884b2.jpg',\n    '2cfe3fcb6722.jpg',\n    '5cbcc46a6eed.jpg'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:18:28.477192Z","iopub.execute_input":"2023-05-22T06:18:28.478045Z","iopub.status.idle":"2023-05-22T06:18:28.483751Z","shell.execute_reply.started":"2023-05-22T06:18:28.478003Z","shell.execute_reply":"2023-05-22T06:18:28.482544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from albumentations.pytorch.transforms import ToTensorV2\n\ny_tick_label_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])\ny_tick_label_transforms","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:18:31.336193Z","iopub.execute_input":"2023-05-22T06:18:31.336988Z","iopub.status.idle":"2023-05-22T06:18:31.348613Z","shell.execute_reply.started":"2023-05-22T06:18:31.336948Z","shell.execute_reply":"2023-05-22T06:18:31.347294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:18:33.940436Z","iopub.execute_input":"2023-05-22T06:18:33.941226Z","iopub.status.idle":"2023-05-22T06:18:33.946301Z","shell.execute_reply.started":"2023-05-22T06:18:33.941180Z","shell.execute_reply":"2023-05-22T06:18:33.945236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_threshold = 0.5","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:18:34.262305Z","iopub.execute_input":"2023-05-22T06:18:34.262907Z","iopub.status.idle":"2023-05-22T06:18:34.267889Z","shell.execute_reply.started":"2023-05-22T06:18:34.262864Z","shell.execute_reply":"2023-05-22T06:18:34.266739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_y_tick_label_bboxes(img_file_name):\n    img = Image.open(images_path/img_file_name)\n    img_arr = np.array(img)\n    transformed = y_tick_label_transforms(image=img_arr)\n    batched = transformed['image'].unsqueeze(0)\n    batched = batched.to(device)\n    with torch.no_grad():\n        out = y_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=y_tick_label_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-05-22T06:18:36.708078Z","iopub.execute_input":"2023-05-22T06:18:36.708804Z","iopub.status.idle":"2023-05-22T06:18:36.719901Z","shell.execute_reply.started":"2023-05-22T06:18:36.708763Z","shell.execute_reply":"2023-05-22T06:18:36.718664Z"},"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-22T06:18:37.016330Z","iopub.execute_input":"2023-05-22T06:18:37.017311Z","iopub.status.idle":"2023-05-22T06:18:37.027424Z","shell.execute_reply.started":"2023-05-22T06:18:37.017241Z","shell.execute_reply":"2023-05-22T06:18:37.026079Z"},"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-22T06:18:40.066014Z","iopub.execute_input":"2023-05-22T06:18:40.067198Z","iopub.status.idle":"2023-05-22T06:18:40.075403Z","shell.execute_reply.started":"2023-05-22T06:18:40.067145Z","shell.execute_reply":"2023-05-22T06:18:40.074156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:18:44.773077Z","iopub.execute_input":"2023-05-22T06:18:44.773817Z","iopub.status.idle":"2023-05-22T06:18:44.842319Z","shell.execute_reply.started":"2023-05-22T06:18:44.773774Z","shell.execute_reply":"2023-05-22T06:18:44.840926Z"},"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-22T05:52:05.104959Z","iopub.execute_input":"2023-05-22T05:52:05.105964Z","iopub.status.idle":"2023-05-22T05:52:05.131190Z","shell.execute_reply.started":"2023-05-22T05:52:05.105922Z","shell.execute_reply":"2023-05-22T05:52:05.130202Z"},"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-22T06:19:04.181893Z","iopub.execute_input":"2023-05-22T06:19:04.182635Z","iopub.status.idle":"2023-05-22T06:19:04.189809Z","shell.execute_reply.started":"2023-05-22T06:19:04.182594Z","shell.execute_reply":"2023-05-22T06:19:04.188664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:19:05.661329Z","iopub.execute_input":"2023-05-22T06:19:05.661714Z","iopub.status.idle":"2023-05-22T06:19:05.724632Z","shell.execute_reply.started":"2023-05-22T06:19:05.661679Z","shell.execute_reply":"2023-05-22T06:19:05.723458Z"},"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-22T05:53:32.819911Z","iopub.execute_input":"2023-05-22T05:53:32.820640Z","iopub.status.idle":"2023-05-22T05:53:32.845503Z","shell.execute_reply.started":"2023-05-22T05:53:32.820597Z","shell.execute_reply":"2023-05-22T05:53:32.844302Z"},"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-22T06:19:35.251956Z","iopub.execute_input":"2023-05-22T06:19:35.252567Z","iopub.status.idle":"2023-05-22T06:19:35.260039Z","shell.execute_reply.started":"2023-05-22T06:19:35.252525Z","shell.execute_reply":"2023-05-22T06:19:35.258941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:19:35.793800Z","iopub.execute_input":"2023-05-22T06:19:35.794487Z","iopub.status.idle":"2023-05-22T06:19:35.857601Z","shell.execute_reply.started":"2023-05-22T06:19:35.794444Z","shell.execute_reply":"2023-05-22T06:19:35.856451Z"},"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-22T05:55:23.464169Z","iopub.execute_input":"2023-05-22T05:55:23.464967Z","iopub.status.idle":"2023-05-22T05:55:23.502015Z","shell.execute_reply.started":"2023-05-22T05:55:23.464920Z","shell.execute_reply":"2023-05-22T05:55:23.500986Z"},"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-22T06:19:54.867770Z","iopub.execute_input":"2023-05-22T06:19:54.868491Z","iopub.status.idle":"2023-05-22T06:19:54.876630Z","shell.execute_reply.started":"2023-05-22T06:19:54.868439Z","shell.execute_reply":"2023-05-22T06:19:54.875620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:19:55.230793Z","iopub.execute_input":"2023-05-22T06:19:55.231218Z","iopub.status.idle":"2023-05-22T06:19:55.306080Z","shell.execute_reply.started":"2023-05-22T06:19:55.231178Z","shell.execute_reply":"2023-05-22T06:19:55.305127Z"},"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-22T05:56:23.973634Z","iopub.execute_input":"2023-05-22T05:56:23.974415Z","iopub.status.idle":"2023-05-22T05:56:24.008276Z","shell.execute_reply.started":"2023-05-22T05:56:23.974361Z","shell.execute_reply":"2023-05-22T05:56:24.007259Z"},"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-22T06:20:12.975933Z","iopub.execute_input":"2023-05-22T06:20:12.976652Z","iopub.status.idle":"2023-05-22T06:20:12.983516Z","shell.execute_reply.started":"2023-05-22T06:20:12.976610Z","shell.execute_reply":"2023-05-22T06:20:12.982368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:20:15.140955Z","iopub.execute_input":"2023-05-22T06:20:15.141693Z","iopub.status.idle":"2023-05-22T06:20:15.206963Z","shell.execute_reply.started":"2023-05-22T06:20:15.141650Z","shell.execute_reply":"2023-05-22T06:20:15.205776Z"},"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-22T05:57:40.676188Z","iopub.execute_input":"2023-05-22T05:57:40.676982Z","iopub.status.idle":"2023-05-22T05:57:40.708761Z","shell.execute_reply.started":"2023-05-22T05:57:40.676939Z","shell.execute_reply":"2023-05-22T05:57:40.707787Z"},"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-22T06:20:33.322677Z","iopub.execute_input":"2023-05-22T06:20:33.323090Z","iopub.status.idle":"2023-05-22T06:20:33.331646Z","shell.execute_reply.started":"2023-05-22T06:20:33.323053Z","shell.execute_reply":"2023-05-22T06:20:33.330158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:20:33.844704Z","iopub.execute_input":"2023-05-22T06:20:33.845695Z","iopub.status.idle":"2023-05-22T06:20:33.909844Z","shell.execute_reply.started":"2023-05-22T06:20:33.845641Z","shell.execute_reply":"2023-05-22T06:20:33.908806Z"},"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-22T05:58:33.092609Z","iopub.execute_input":"2023-05-22T05:58:33.093343Z","iopub.status.idle":"2023-05-22T05:58:33.122875Z","shell.execute_reply.started":"2023-05-22T05:58:33.093302Z","shell.execute_reply":"2023-05-22T05:58:33.121740Z"},"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-22T06:20:50.787537Z","iopub.execute_input":"2023-05-22T06:20:50.788292Z","iopub.status.idle":"2023-05-22T06:20:50.796475Z","shell.execute_reply.started":"2023-05-22T06:20:50.788250Z","shell.execute_reply":"2023-05-22T06:20:50.794973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:20:52.013342Z","iopub.execute_input":"2023-05-22T06:20:52.014431Z","iopub.status.idle":"2023-05-22T06:20:52.077566Z","shell.execute_reply.started":"2023-05-22T06:20:52.014391Z","shell.execute_reply":"2023-05-22T06:20:52.076461Z"},"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-22T05:59:42.377914Z","iopub.execute_input":"2023-05-22T05:59:42.378404Z","iopub.status.idle":"2023-05-22T05:59:42.415716Z","shell.execute_reply.started":"2023-05-22T05:59:42.378356Z","shell.execute_reply":"2023-05-22T05:59:42.414700Z"},"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-22T06:21:09.930998Z","iopub.execute_input":"2023-05-22T06:21:09.931607Z","iopub.status.idle":"2023-05-22T06:21:09.939064Z","shell.execute_reply.started":"2023-05-22T06:21:09.931567Z","shell.execute_reply":"2023-05-22T06:21:09.937949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:21:11.976873Z","iopub.execute_input":"2023-05-22T06:21:11.977312Z","iopub.status.idle":"2023-05-22T06:21:12.041463Z","shell.execute_reply.started":"2023-05-22T06:21:11.977272Z","shell.execute_reply":"2023-05-22T06:21:12.040360Z"},"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-22T06:00:38.404386Z","iopub.execute_input":"2023-05-22T06:00:38.405351Z","iopub.status.idle":"2023-05-22T06:00:38.431978Z","shell.execute_reply.started":"2023-05-22T06:00:38.405297Z","shell.execute_reply":"2023-05-22T06:00:38.430791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference on 5 Top Loss Images","metadata":{}},{"cell_type":"markdown","source":"Let's run inference on the 5 top loss images from the <a href=\"https://www.kaggle.com/code/sambitmukherjee/y-tick-label-detection-training\" target=\"_blank\">training notebook</a>'s \"Model Evaluation\" section.","metadata":{}},{"cell_type":"code","source":"img_file_name = '0e46c988beac.jpg'","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:21:34.530170Z","iopub.execute_input":"2023-05-22T06:21:34.530905Z","iopub.status.idle":"2023-05-22T06:21:34.536169Z","shell.execute_reply.started":"2023-05-22T06:21:34.530863Z","shell.execute_reply":"2023-05-22T06:21:34.534806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:21:37.278781Z","iopub.execute_input":"2023-05-22T06:21:37.279515Z","iopub.status.idle":"2023-05-22T06:21:37.342376Z","shell.execute_reply.started":"2023-05-22T06:21:37.279474Z","shell.execute_reply":"2023-05-22T06:21:37.341170Z"},"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-22T06:06:28.743928Z","iopub.execute_input":"2023-05-22T06:06:28.744972Z","iopub.status.idle":"2023-05-22T06:06:28.775244Z","shell.execute_reply.started":"2023-05-22T06:06:28.744928Z","shell.execute_reply":"2023-05-22T06:06:28.774032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = 'd0f1d33c137f.jpg'","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:22:04.200517Z","iopub.execute_input":"2023-05-22T06:22:04.201446Z","iopub.status.idle":"2023-05-22T06:22:04.206629Z","shell.execute_reply.started":"2023-05-22T06:22:04.201388Z","shell.execute_reply":"2023-05-22T06:22:04.205474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:22:06.487020Z","iopub.execute_input":"2023-05-22T06:22:06.488057Z","iopub.status.idle":"2023-05-22T06:22:06.558270Z","shell.execute_reply.started":"2023-05-22T06:22:06.488012Z","shell.execute_reply":"2023-05-22T06:22:06.557125Z"},"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-22T06:07:45.238523Z","iopub.execute_input":"2023-05-22T06:07:45.238995Z","iopub.status.idle":"2023-05-22T06:07:45.299076Z","shell.execute_reply.started":"2023-05-22T06:07:45.238948Z","shell.execute_reply":"2023-05-22T06:07:45.298130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = 'c681d45e7d37.jpg'","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:22:44.504451Z","iopub.execute_input":"2023-05-22T06:22:44.505266Z","iopub.status.idle":"2023-05-22T06:22:44.510237Z","shell.execute_reply.started":"2023-05-22T06:22:44.505216Z","shell.execute_reply":"2023-05-22T06:22:44.508985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:22:44.959003Z","iopub.execute_input":"2023-05-22T06:22:44.959718Z","iopub.status.idle":"2023-05-22T06:22:45.025077Z","shell.execute_reply.started":"2023-05-22T06:22:44.959676Z","shell.execute_reply":"2023-05-22T06:22:45.023880Z"},"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-22T06:09:37.112453Z","iopub.execute_input":"2023-05-22T06:09:37.112929Z","iopub.status.idle":"2023-05-22T06:09:37.155216Z","shell.execute_reply.started":"2023-05-22T06:09:37.112883Z","shell.execute_reply":"2023-05-22T06:09:37.154228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = '7dfde4a8afb2.jpg'","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:23:17.919090Z","iopub.execute_input":"2023-05-22T06:23:17.919519Z","iopub.status.idle":"2023-05-22T06:23:17.925151Z","shell.execute_reply.started":"2023-05-22T06:23:17.919484Z","shell.execute_reply":"2023-05-22T06:23:17.923622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:23:18.646719Z","iopub.execute_input":"2023-05-22T06:23:18.647716Z","iopub.status.idle":"2023-05-22T06:23:18.713552Z","shell.execute_reply.started":"2023-05-22T06:23:18.647669Z","shell.execute_reply":"2023-05-22T06:23:18.712363Z"},"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-22T06:10:40.393540Z","iopub.execute_input":"2023-05-22T06:10:40.394485Z","iopub.status.idle":"2023-05-22T06:10:40.425325Z","shell.execute_reply.started":"2023-05-22T06:10:40.394428Z","shell.execute_reply":"2023-05-22T06:10:40.424126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = '6627e6967a98.jpg'","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:24:31.225729Z","iopub.execute_input":"2023-05-22T06:24:31.226439Z","iopub.status.idle":"2023-05-22T06:24:31.231572Z","shell.execute_reply.started":"2023-05-22T06:24:31.226395Z","shell.execute_reply":"2023-05-22T06:24:31.230226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_y_tick_label_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T06:24:31.686596Z","iopub.execute_input":"2023-05-22T06:24:31.687465Z","iopub.status.idle":"2023-05-22T06:24:31.752640Z","shell.execute_reply.started":"2023-05-22T06:24:31.687416Z","shell.execute_reply":"2023-05-22T06:24:31.751564Z"},"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-22T06:11:56.740126Z","iopub.execute_input":"2023-05-22T06:11:56.740891Z","iopub.status.idle":"2023-05-22T06:11:56.777312Z","shell.execute_reply.started":"2023-05-22T06:11:56.740849Z","shell.execute_reply":"2023-05-22T06:11:56.776169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"print(\"That's all!\")","metadata":{},"execution_count":null,"outputs":[]}]}