{"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-22T08:02:20.873453Z","iopub.execute_input":"2023-05-22T08:02:20.873838Z","iopub.status.idle":"2023-05-22T08:02:23.391136Z","shell.execute_reply.started":"2023-05-22T08:02:20.873801Z","shell.execute_reply":"2023-05-22T08:02:23.390062Z"},"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-22T08:02:36.316220Z","iopub.execute_input":"2023-05-22T08:02:36.317109Z","iopub.status.idle":"2023-05-22T08:02:36.324461Z","shell.execute_reply.started":"2023-05-22T08:02:36.317069Z","shell.execute_reply":"2023-05-22T08:02:36.323083Z"},"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-22T08:02:46.408510Z","iopub.execute_input":"2023-05-22T08:02:46.409511Z","iopub.status.idle":"2023-05-22T08:02:46.419396Z","shell.execute_reply.started":"2023-05-22T08:02:46.409456Z","shell.execute_reply":"2023-05-22T08:02:46.417867Z"},"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-22T08:02:54.891930Z","iopub.execute_input":"2023-05-22T08:02:54.892623Z","iopub.status.idle":"2023-05-22T08:02:54.898249Z","shell.execute_reply.started":"2023-05-22T08:02:54.892584Z","shell.execute_reply":"2023-05-22T08:02:54.897006Z"},"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-22T08:03:08.037352Z","iopub.execute_input":"2023-05-22T08:03:08.038371Z","iopub.status.idle":"2023-05-22T08:03:08.271402Z","shell.execute_reply.started":"2023-05-22T08:03:08.038322Z","shell.execute_reply":"2023-05-22T08:03:08.270339Z"},"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-22T08:03:19.346172Z","iopub.execute_input":"2023-05-22T08:03:19.346942Z","iopub.status.idle":"2023-05-22T08:03:19.352586Z","shell.execute_reply.started":"2023-05-22T08:03:19.346896Z","shell.execute_reply":"2023-05-22T08:03:19.351330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tick_mark_backbone = resnet50_fpn_fn(pretrained=False)\ntick_mark_backbone","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:03:42.551967Z","iopub.execute_input":"2023-05-22T08:03:42.552924Z","iopub.status.idle":"2023-05-22T08:03:43.053003Z","shell.execute_reply.started":"2023-05-22T08:03:42.552865Z","shell.execute_reply":"2023-05-22T08:03:43.051850Z"},"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-22T08:04:52.356624Z","iopub.execute_input":"2023-05-22T08:04:52.357033Z","iopub.status.idle":"2023-05-22T08:04:52.364732Z","shell.execute_reply.started":"2023-05-22T08:04:52.356998Z","shell.execute_reply":"2023-05-22T08:04:52.363357Z"},"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-22T08:05:12.470224Z","iopub.execute_input":"2023-05-22T08:05:12.470978Z","iopub.status.idle":"2023-05-22T08:05:12.476889Z","shell.execute_reply.started":"2023-05-22T08:05:12.470937Z","shell.execute_reply":"2023-05-22T08:05:12.475748Z"},"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-22T08:05:20.865915Z","iopub.execute_input":"2023-05-22T08:05:20.867119Z","iopub.status.idle":"2023-05-22T08:05:20.873883Z","shell.execute_reply.started":"2023-05-22T08:05:20.867068Z","shell.execute_reply":"2023-05-22T08:05:20.872503Z"},"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-22T08:05:42.320989Z","iopub.execute_input":"2023-05-22T08:05:42.321394Z","iopub.status.idle":"2023-05-22T08:05:42.327866Z","shell.execute_reply.started":"2023-05-22T08:05:42.321359Z","shell.execute_reply":"2023-05-22T08:05:42.326763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tick_mark_model = get_model(num_classes=2, backbone=tick_mark_backbone)\ntick_mark_model","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:06:39.620174Z","iopub.execute_input":"2023-05-22T08:06:39.621212Z","iopub.status.idle":"2023-05-22T08:06:39.820841Z","shell.execute_reply.started":"2023-05-22T08:06:39.621171Z","shell.execute_reply":"2023-05-22T08:06:39.819829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tick_mark_model.load_state_dict(torch.load('/kaggle/input/b-m-g-a-extra-data/tick_mark_5.pth'))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:07:31.941542Z","iopub.execute_input":"2023-05-22T08:07:31.942505Z","iopub.status.idle":"2023-05-22T08:07:37.134293Z","shell.execute_reply.started":"2023-05-22T08:07:31.942450Z","shell.execute_reply":"2023-05-22T08:07:37.133173Z"},"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-22T08:07:56.915764Z","iopub.execute_input":"2023-05-22T08:07:56.916403Z","iopub.status.idle":"2023-05-22T08:07:56.927720Z","shell.execute_reply.started":"2023-05-22T08:07:56.916351Z","shell.execute_reply":"2023-05-22T08:07:56.925209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tick_mark_model = tick_mark_model.to(device)\ntick_mark_model.eval();","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:08:27.620292Z","iopub.execute_input":"2023-05-22T08:08:27.621255Z","iopub.status.idle":"2023-05-22T08:08:27.631961Z","shell.execute_reply.started":"2023-05-22T08:08:27.621199Z","shell.execute_reply":"2023-05-22T08:08:27.630825Z"},"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-22T08:09:08.393987Z","iopub.execute_input":"2023-05-22T08:09:08.394400Z","iopub.status.idle":"2023-05-22T08:09:08.399562Z","shell.execute_reply.started":"2023-05-22T08:09:08.394362Z","shell.execute_reply":"2023-05-22T08:09:08.398459Z"},"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-22T08:09:50.352822Z","iopub.execute_input":"2023-05-22T08:09:50.353253Z","iopub.status.idle":"2023-05-22T08:09:50.360998Z","shell.execute_reply.started":"2023-05-22T08:09:50.353214Z","shell.execute_reply":"2023-05-22T08:09:50.359698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import albumentations as A\n\ntick_mark_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-22T08:10:10.015587Z","iopub.execute_input":"2023-05-22T08:10:10.016156Z","iopub.status.idle":"2023-05-22T08:10:11.678391Z","shell.execute_reply.started":"2023-05-22T08:10:10.016118Z","shell.execute_reply":"2023-05-22T08:10:11.677323Z"},"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-22T08:10:32.596764Z","iopub.execute_input":"2023-05-22T08:10:32.597748Z","iopub.status.idle":"2023-05-22T08:10:32.604116Z","shell.execute_reply.started":"2023-05-22T08:10:32.597694Z","shell.execute_reply":"2023-05-22T08:10:32.602910Z"},"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-22T08:10:40.484786Z","iopub.execute_input":"2023-05-22T08:10:40.485185Z","iopub.status.idle":"2023-05-22T08:10:40.491992Z","shell.execute_reply.started":"2023-05-22T08:10:40.485150Z","shell.execute_reply":"2023-05-22T08:10:40.490706Z"},"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-22T08:10:46.497233Z","iopub.execute_input":"2023-05-22T08:10:46.497964Z","iopub.status.idle":"2023-05-22T08:10:46.505086Z","shell.execute_reply.started":"2023-05-22T08:10:46.497925Z","shell.execute_reply":"2023-05-22T08:10:46.503517Z"},"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-22T08:10:55.814136Z","iopub.execute_input":"2023-05-22T08:10:55.814884Z","iopub.status.idle":"2023-05-22T08:10:55.823470Z","shell.execute_reply.started":"2023-05-22T08:10:55.814843Z","shell.execute_reply":"2023-05-22T08:10:55.822094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BBox = namedtuple(\"BBox\", \"xmin, ymin, xmax, ymax\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:11:01.269296Z","iopub.execute_input":"2023-05-22T08:11:01.270329Z","iopub.status.idle":"2023-05-22T08:11:01.276621Z","shell.execute_reply.started":"2023-05-22T08:11:01.270239Z","shell.execute_reply":"2023-05-22T08:11:01.275328Z"},"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-22T08:11:07.614852Z","iopub.execute_input":"2023-05-22T08:11:07.615367Z","iopub.status.idle":"2023-05-22T08:11:07.631705Z","shell.execute_reply.started":"2023-05-22T08:11:07.615320Z","shell.execute_reply":"2023-05-22T08:11:07.630500Z"},"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-22T08:11:27.120628Z","iopub.execute_input":"2023-05-22T08:11:27.121030Z","iopub.status.idle":"2023-05-22T08:11:28.120231Z","shell.execute_reply.started":"2023-05-22T08:11:27.120996Z","shell.execute_reply":"2023-05-22T08:11:28.118709Z"},"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-22T08:11:32.891719Z","iopub.execute_input":"2023-05-22T08:11:32.892740Z","iopub.status.idle":"2023-05-22T08:11:33.874298Z","shell.execute_reply.started":"2023-05-22T08:11:32.892677Z","shell.execute_reply":"2023-05-22T08:11:33.871443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_path = train_path/'images'","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:11:39.963674Z","iopub.execute_input":"2023-05-22T08:11:39.964825Z","iopub.status.idle":"2023-05-22T08:11:39.969586Z","shell.execute_reply.started":"2023-05-22T08:11:39.964767Z","shell.execute_reply":"2023-05-22T08:11:39.968461Z"},"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/tick-mark-detection-training\" target=\"_blank\">training notebook</a>'s \"Model Evaluation\" section.","metadata":{}},{"cell_type":"code","source":"random_sample = [\n    '4c107a4ba0df.jpg',\n    '18421d1954a7.jpg',\n    'cc58505dbbcd.jpg',\n    '861629cc110a.jpg',\n    'a0e555df58f3.jpg',\n    '191212215336.jpg',\n    '1736d86855e2.jpg',\n    '49d4c19d316d.jpg'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:12:01.280221Z","iopub.execute_input":"2023-05-22T08:12:01.280961Z","iopub.status.idle":"2023-05-22T08:12:01.286477Z","shell.execute_reply.started":"2023-05-22T08:12:01.280922Z","shell.execute_reply":"2023-05-22T08:12:01.285370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from albumentations.pytorch.transforms import ToTensorV2\n\ntick_mark_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])\ntick_mark_transforms","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:12:33.031229Z","iopub.execute_input":"2023-05-22T08:12:33.031980Z","iopub.status.idle":"2023-05-22T08:12:33.048626Z","shell.execute_reply.started":"2023-05-22T08:12:33.031942Z","shell.execute_reply":"2023-05-22T08:12:33.047137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:12:47.726215Z","iopub.execute_input":"2023-05-22T08:12:47.726766Z","iopub.status.idle":"2023-05-22T08:12:47.735984Z","shell.execute_reply.started":"2023-05-22T08:12:47.726708Z","shell.execute_reply":"2023-05-22T08:12:47.734621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_threshold = 0.5","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:12:59.458064Z","iopub.execute_input":"2023-05-22T08:12:59.458595Z","iopub.status.idle":"2023-05-22T08:12:59.464420Z","shell.execute_reply.started":"2023-05-22T08:12:59.458547Z","shell.execute_reply":"2023-05-22T08:12:59.463320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_tick_mark_bboxes(img_file_name):\n    img = Image.open(images_path/img_file_name)\n    img_arr = np.array(img)\n    transformed = tick_mark_transforms(image=img_arr)\n    batched = transformed['image'].unsqueeze(0)\n    batched = batched.to(device)\n    with torch.no_grad():\n        out = tick_mark_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=tick_mark_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-22T08:15:00.854744Z","iopub.execute_input":"2023-05-22T08:15:00.855189Z","iopub.status.idle":"2023-05-22T08:15:00.865916Z","shell.execute_reply.started":"2023-05-22T08:15:00.855153Z","shell.execute_reply":"2023-05-22T08:15:00.864618Z"},"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-22T08:15:27.835856Z","iopub.execute_input":"2023-05-22T08:15:27.836646Z","iopub.status.idle":"2023-05-22T08:15:27.844408Z","shell.execute_reply.started":"2023-05-22T08:15:27.836604Z","shell.execute_reply":"2023-05-22T08:15:27.843183Z"},"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-22T08:15:39.633907Z","iopub.execute_input":"2023-05-22T08:15:39.634630Z","iopub.status.idle":"2023-05-22T08:15:39.641590Z","shell.execute_reply.started":"2023-05-22T08:15:39.634590Z","shell.execute_reply":"2023-05-22T08:15:39.640462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:16:06.989001Z","iopub.execute_input":"2023-05-22T08:16:06.989524Z","iopub.status.idle":"2023-05-22T08:16:10.977327Z","shell.execute_reply.started":"2023-05-22T08:16:06.989478Z","shell.execute_reply":"2023-05-22T08:16:10.976128Z"},"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-22T08:16:28.354506Z","iopub.execute_input":"2023-05-22T08:16:28.354891Z","iopub.status.idle":"2023-05-22T08:16:28.393634Z","shell.execute_reply.started":"2023-05-22T08:16:28.354858Z","shell.execute_reply":"2023-05-22T08:16:28.392551Z"},"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-22T08:19:07.664037Z","iopub.execute_input":"2023-05-22T08:19:07.664811Z","iopub.status.idle":"2023-05-22T08:19:07.671400Z","shell.execute_reply.started":"2023-05-22T08:19:07.664765Z","shell.execute_reply":"2023-05-22T08:19:07.670336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:19:14.189362Z","iopub.execute_input":"2023-05-22T08:19:14.189753Z","iopub.status.idle":"2023-05-22T08:19:14.262014Z","shell.execute_reply.started":"2023-05-22T08:19:14.189719Z","shell.execute_reply":"2023-05-22T08:19:14.260959Z"},"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-22T08:19:44.174795Z","iopub.execute_input":"2023-05-22T08:19:44.175197Z","iopub.status.idle":"2023-05-22T08:19:44.209348Z","shell.execute_reply.started":"2023-05-22T08:19:44.175163Z","shell.execute_reply":"2023-05-22T08:19:44.207291Z"},"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-22T08:20:00.127922Z","iopub.execute_input":"2023-05-22T08:20:00.128424Z","iopub.status.idle":"2023-05-22T08:20:00.137946Z","shell.execute_reply.started":"2023-05-22T08:20:00.128378Z","shell.execute_reply":"2023-05-22T08:20:00.136798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:20:15.792327Z","iopub.execute_input":"2023-05-22T08:20:15.792919Z","iopub.status.idle":"2023-05-22T08:20:15.876433Z","shell.execute_reply.started":"2023-05-22T08:20:15.792842Z","shell.execute_reply":"2023-05-22T08:20:15.875345Z"},"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-22T08:20:31.569445Z","iopub.execute_input":"2023-05-22T08:20:31.570017Z","iopub.status.idle":"2023-05-22T08:20:31.612396Z","shell.execute_reply.started":"2023-05-22T08:20:31.569971Z","shell.execute_reply":"2023-05-22T08:20:31.611351Z"},"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-22T08:20:47.185612Z","iopub.execute_input":"2023-05-22T08:20:47.185999Z","iopub.status.idle":"2023-05-22T08:20:47.193018Z","shell.execute_reply.started":"2023-05-22T08:20:47.185964Z","shell.execute_reply":"2023-05-22T08:20:47.191804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:21:01.042727Z","iopub.execute_input":"2023-05-22T08:21:01.043206Z","iopub.status.idle":"2023-05-22T08:21:01.129436Z","shell.execute_reply.started":"2023-05-22T08:21:01.043163Z","shell.execute_reply":"2023-05-22T08:21:01.128343Z"},"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-22T08:21:13.999761Z","iopub.execute_input":"2023-05-22T08:21:14.000230Z","iopub.status.idle":"2023-05-22T08:21:14.034416Z","shell.execute_reply.started":"2023-05-22T08:21:14.000187Z","shell.execute_reply":"2023-05-22T08:21:14.033327Z"},"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-22T08:21:30.615206Z","iopub.execute_input":"2023-05-22T08:21:30.615711Z","iopub.status.idle":"2023-05-22T08:21:30.626545Z","shell.execute_reply.started":"2023-05-22T08:21:30.615670Z","shell.execute_reply":"2023-05-22T08:21:30.625314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:21:43.431892Z","iopub.execute_input":"2023-05-22T08:21:43.432423Z","iopub.status.idle":"2023-05-22T08:21:43.518685Z","shell.execute_reply.started":"2023-05-22T08:21:43.432375Z","shell.execute_reply":"2023-05-22T08:21:43.517563Z"},"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-22T08:21:58.170465Z","iopub.execute_input":"2023-05-22T08:21:58.170864Z","iopub.status.idle":"2023-05-22T08:21:58.208345Z","shell.execute_reply.started":"2023-05-22T08:21:58.170829Z","shell.execute_reply":"2023-05-22T08:21:58.207256Z"},"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-22T08:22:51.112248Z","iopub.execute_input":"2023-05-22T08:22:51.113000Z","iopub.status.idle":"2023-05-22T08:22:51.120945Z","shell.execute_reply.started":"2023-05-22T08:22:51.112961Z","shell.execute_reply":"2023-05-22T08:22:51.119629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:23:04.460302Z","iopub.execute_input":"2023-05-22T08:23:04.460929Z","iopub.status.idle":"2023-05-22T08:23:04.543297Z","shell.execute_reply.started":"2023-05-22T08:23:04.460881Z","shell.execute_reply":"2023-05-22T08:23:04.542196Z"},"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-22T08:23:18.014814Z","iopub.execute_input":"2023-05-22T08:23:18.015312Z","iopub.status.idle":"2023-05-22T08:23:18.047846Z","shell.execute_reply.started":"2023-05-22T08:23:18.015243Z","shell.execute_reply":"2023-05-22T08:23:18.046698Z"},"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-22T08:23:36.614822Z","iopub.execute_input":"2023-05-22T08:23:36.615214Z","iopub.status.idle":"2023-05-22T08:23:36.622543Z","shell.execute_reply.started":"2023-05-22T08:23:36.615178Z","shell.execute_reply":"2023-05-22T08:23:36.621334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:23:50.991607Z","iopub.execute_input":"2023-05-22T08:23:50.992101Z","iopub.status.idle":"2023-05-22T08:23:51.076186Z","shell.execute_reply.started":"2023-05-22T08:23:50.992056Z","shell.execute_reply":"2023-05-22T08:23:51.075113Z"},"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-22T08:24:03.604657Z","iopub.execute_input":"2023-05-22T08:24:03.605060Z","iopub.status.idle":"2023-05-22T08:24:03.633762Z","shell.execute_reply.started":"2023-05-22T08:24:03.605025Z","shell.execute_reply":"2023-05-22T08:24:03.632589Z"},"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-22T08:24:15.227040Z","iopub.execute_input":"2023-05-22T08:24:15.227452Z","iopub.status.idle":"2023-05-22T08:24:15.235255Z","shell.execute_reply.started":"2023-05-22T08:24:15.227416Z","shell.execute_reply":"2023-05-22T08:24:15.233962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:24:28.315426Z","iopub.execute_input":"2023-05-22T08:24:28.315818Z","iopub.status.idle":"2023-05-22T08:24:28.386974Z","shell.execute_reply.started":"2023-05-22T08:24:28.315775Z","shell.execute_reply":"2023-05-22T08:24:28.385840Z"},"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-22T08:24:41.082478Z","iopub.execute_input":"2023-05-22T08:24:41.082938Z","iopub.status.idle":"2023-05-22T08:24:41.117694Z","shell.execute_reply.started":"2023-05-22T08:24:41.082896Z","shell.execute_reply":"2023-05-22T08:24:41.116593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference on 10 Top Loss Images","metadata":{}},{"cell_type":"code","source":"top_loss_images = [\n    '359088265664.jpg', \n    '9092699b6681.jpg', \n    'b840c79e40e0.jpg', \n    '0e46c988beac.jpg', \n    'e832d98c37b2.jpg', \n    '90c504a8b320.jpg', \n    '53360355b73c.jpg', \n    '64374ed8c87a.jpg', \n    '8f678bd731ba.jpg', \n    'ed4a7c1f1267.jpg'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:25:33.439449Z","iopub.execute_input":"2023-05-22T08:25:33.440610Z","iopub.status.idle":"2023-05-22T08:25:33.446232Z","shell.execute_reply.started":"2023-05-22T08:25:33.440561Z","shell.execute_reply":"2023-05-22T08:25:33.444871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[0]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:25:38.225590Z","iopub.execute_input":"2023-05-22T08:25:38.226593Z","iopub.status.idle":"2023-05-22T08:25:38.234418Z","shell.execute_reply.started":"2023-05-22T08:25:38.226534Z","shell.execute_reply":"2023-05-22T08:25:38.233131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:25:56.073209Z","iopub.execute_input":"2023-05-22T08:25:56.073985Z","iopub.status.idle":"2023-05-22T08:25:56.146327Z","shell.execute_reply.started":"2023-05-22T08:25:56.073944Z","shell.execute_reply":"2023-05-22T08:25:56.145109Z"},"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-22T08:26:11.632966Z","iopub.execute_input":"2023-05-22T08:26:11.633722Z","iopub.status.idle":"2023-05-22T08:26:11.665638Z","shell.execute_reply.started":"2023-05-22T08:26:11.633682Z","shell.execute_reply":"2023-05-22T08:26:11.664500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[1]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:26:28.247110Z","iopub.execute_input":"2023-05-22T08:26:28.247869Z","iopub.status.idle":"2023-05-22T08:26:28.255148Z","shell.execute_reply.started":"2023-05-22T08:26:28.247826Z","shell.execute_reply":"2023-05-22T08:26:28.253887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:26:46.633928Z","iopub.execute_input":"2023-05-22T08:26:46.634454Z","iopub.status.idle":"2023-05-22T08:26:46.712238Z","shell.execute_reply.started":"2023-05-22T08:26:46.634406Z","shell.execute_reply":"2023-05-22T08:26:46.711109Z"},"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-22T08:27:00.174599Z","iopub.execute_input":"2023-05-22T08:27:00.175093Z","iopub.status.idle":"2023-05-22T08:27:00.219809Z","shell.execute_reply.started":"2023-05-22T08:27:00.175049Z","shell.execute_reply":"2023-05-22T08:27:00.218637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[2]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:27:17.333316Z","iopub.execute_input":"2023-05-22T08:27:17.333999Z","iopub.status.idle":"2023-05-22T08:27:17.340719Z","shell.execute_reply.started":"2023-05-22T08:27:17.333962Z","shell.execute_reply":"2023-05-22T08:27:17.339594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:27:29.942095Z","iopub.execute_input":"2023-05-22T08:27:29.942601Z","iopub.status.idle":"2023-05-22T08:27:30.029781Z","shell.execute_reply.started":"2023-05-22T08:27:29.942557Z","shell.execute_reply":"2023-05-22T08:27:30.028555Z"},"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-22T08:27:43.622832Z","iopub.execute_input":"2023-05-22T08:27:43.623327Z","iopub.status.idle":"2023-05-22T08:27:43.722441Z","shell.execute_reply.started":"2023-05-22T08:27:43.623282Z","shell.execute_reply":"2023-05-22T08:27:43.721251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[3]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:28:01.487942Z","iopub.execute_input":"2023-05-22T08:28:01.488698Z","iopub.status.idle":"2023-05-22T08:28:01.495778Z","shell.execute_reply.started":"2023-05-22T08:28:01.488655Z","shell.execute_reply":"2023-05-22T08:28:01.494645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:28:16.482948Z","iopub.execute_input":"2023-05-22T08:28:16.483385Z","iopub.status.idle":"2023-05-22T08:28:16.551892Z","shell.execute_reply.started":"2023-05-22T08:28:16.483347Z","shell.execute_reply":"2023-05-22T08:28:16.550763Z"},"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-22T08:28:30.817488Z","iopub.execute_input":"2023-05-22T08:28:30.818391Z","iopub.status.idle":"2023-05-22T08:28:30.846352Z","shell.execute_reply.started":"2023-05-22T08:28:30.818349Z","shell.execute_reply":"2023-05-22T08:28:30.844307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[4]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:28:54.578746Z","iopub.execute_input":"2023-05-22T08:28:54.579526Z","iopub.status.idle":"2023-05-22T08:28:54.586593Z","shell.execute_reply.started":"2023-05-22T08:28:54.579482Z","shell.execute_reply":"2023-05-22T08:28:54.585480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:29:06.535336Z","iopub.execute_input":"2023-05-22T08:29:06.535827Z","iopub.status.idle":"2023-05-22T08:29:06.621967Z","shell.execute_reply.started":"2023-05-22T08:29:06.535783Z","shell.execute_reply":"2023-05-22T08:29:06.620859Z"},"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-22T08:29:18.554403Z","iopub.execute_input":"2023-05-22T08:29:18.555153Z","iopub.status.idle":"2023-05-22T08:29:18.590685Z","shell.execute_reply.started":"2023-05-22T08:29:18.555113Z","shell.execute_reply":"2023-05-22T08:29:18.589679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[5]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:29:31.024347Z","iopub.execute_input":"2023-05-22T08:29:31.025104Z","iopub.status.idle":"2023-05-22T08:29:31.032445Z","shell.execute_reply.started":"2023-05-22T08:29:31.025060Z","shell.execute_reply":"2023-05-22T08:29:31.031221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:29:44.718087Z","iopub.execute_input":"2023-05-22T08:29:44.718504Z","iopub.status.idle":"2023-05-22T08:29:44.789243Z","shell.execute_reply.started":"2023-05-22T08:29:44.718470Z","shell.execute_reply":"2023-05-22T08:29:44.788147Z"},"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-22T08:29:57.550837Z","iopub.execute_input":"2023-05-22T08:29:57.551231Z","iopub.status.idle":"2023-05-22T08:29:57.583202Z","shell.execute_reply.started":"2023-05-22T08:29:57.551197Z","shell.execute_reply":"2023-05-22T08:29:57.582145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[6]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:30:18.715459Z","iopub.execute_input":"2023-05-22T08:30:18.716073Z","iopub.status.idle":"2023-05-22T08:30:18.722812Z","shell.execute_reply.started":"2023-05-22T08:30:18.716032Z","shell.execute_reply":"2023-05-22T08:30:18.721753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:30:33.621839Z","iopub.execute_input":"2023-05-22T08:30:33.622226Z","iopub.status.idle":"2023-05-22T08:30:33.692587Z","shell.execute_reply.started":"2023-05-22T08:30:33.622192Z","shell.execute_reply":"2023-05-22T08:30:33.691475Z"},"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-22T08:30:46.320141Z","iopub.execute_input":"2023-05-22T08:30:46.320889Z","iopub.status.idle":"2023-05-22T08:30:46.366234Z","shell.execute_reply.started":"2023-05-22T08:30:46.320846Z","shell.execute_reply":"2023-05-22T08:30:46.365070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[7]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:31:07.134555Z","iopub.execute_input":"2023-05-22T08:31:07.135341Z","iopub.status.idle":"2023-05-22T08:31:07.142479Z","shell.execute_reply.started":"2023-05-22T08:31:07.135291Z","shell.execute_reply":"2023-05-22T08:31:07.141320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:31:20.172933Z","iopub.execute_input":"2023-05-22T08:31:20.173456Z","iopub.status.idle":"2023-05-22T08:31:20.256315Z","shell.execute_reply.started":"2023-05-22T08:31:20.173408Z","shell.execute_reply":"2023-05-22T08:31:20.255309Z"},"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-22T08:31:32.870292Z","iopub.execute_input":"2023-05-22T08:31:32.870913Z","iopub.status.idle":"2023-05-22T08:31:32.889709Z","shell.execute_reply.started":"2023-05-22T08:31:32.870874Z","shell.execute_reply":"2023-05-22T08:31:32.888568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[8]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:31:43.996670Z","iopub.execute_input":"2023-05-22T08:31:43.997086Z","iopub.status.idle":"2023-05-22T08:31:44.003864Z","shell.execute_reply.started":"2023-05-22T08:31:43.997050Z","shell.execute_reply":"2023-05-22T08:31:44.002671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:31:56.085075Z","iopub.execute_input":"2023-05-22T08:31:56.085596Z","iopub.status.idle":"2023-05-22T08:31:56.183926Z","shell.execute_reply.started":"2023-05-22T08:31:56.085551Z","shell.execute_reply":"2023-05-22T08:31:56.182821Z"},"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-22T08:32:10.544161Z","iopub.execute_input":"2023-05-22T08:32:10.544917Z","iopub.status.idle":"2023-05-22T08:32:10.611195Z","shell.execute_reply.started":"2023-05-22T08:32:10.544877Z","shell.execute_reply":"2023-05-22T08:32:10.610126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"img_file_name = top_loss_images[9]\nimg_file_name","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:32:35.445787Z","iopub.execute_input":"2023-05-22T08:32:35.446191Z","iopub.status.idle":"2023-05-22T08:32:35.454699Z","shell.execute_reply.started":"2023-05-22T08:32:35.446156Z","shell.execute_reply":"2023-05-22T08:32:35.453396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npostprocessed_bboxes = get_tick_mark_bboxes(img_file_name)\npostprocessed_bboxes","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:32:47.875461Z","iopub.execute_input":"2023-05-22T08:32:47.876218Z","iopub.status.idle":"2023-05-22T08:32:47.948932Z","shell.execute_reply.started":"2023-05-22T08:32:47.876178Z","shell.execute_reply":"2023-05-22T08:32:47.947741Z"},"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-22T08:33:01.236450Z","iopub.execute_input":"2023-05-22T08:33:01.236862Z","iopub.status.idle":"2023-05-22T08:33:01.269520Z","shell.execute_reply.started":"2023-05-22T08:33:01.236827Z","shell.execute_reply":"2023-05-22T08:33:01.268342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"print(\"That's all!\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T08:34:41.758600Z","iopub.execute_input":"2023-05-22T08:34:41.759034Z","iopub.status.idle":"2023-05-22T08:34:41.765278Z","shell.execute_reply.started":"2023-05-22T08:34:41.758998Z","shell.execute_reply":"2023-05-22T08:34:41.764038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}