{"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":"# ","metadata":{}},{"cell_type":"markdown","source":"# Importing libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom PIL import Image, ImageDraw\nimport random","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:03.040687Z","iopub.execute_input":"2022-02-22T16:17:03.041696Z","iopub.status.idle":"2022-02-22T16:17:04.264837Z","shell.execute_reply.started":"2022-02-22T16:17:03.041575Z","shell.execute_reply":"2022-02-22T16:17:04.264045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data description","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('../input/tensorflow-great-barrier-reef/train.csv')\ntest = pd.read_csv('../input/tensorflow-great-barrier-reef/test.csv')\nsample_submission = pd.read_csv('../input/tensorflow-great-barrier-reef/example_sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.266274Z","iopub.execute_input":"2022-02-22T16:17:04.267219Z","iopub.status.idle":"2022-02-22T16:17:04.345047Z","shell.execute_reply.started":"2022-02-22T16:17:04.267176Z","shell.execute_reply":"2022-02-22T16:17:04.343978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.346345Z","iopub.execute_input":"2022-02-22T16:17:04.346564Z","iopub.status.idle":"2022-02-22T16:17:04.381026Z","shell.execute_reply.started":"2022-02-22T16:17:04.346537Z","shell.execute_reply":"2022-02-22T16:17:04.380018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.383131Z","iopub.execute_input":"2022-02-22T16:17:04.383374Z","iopub.status.idle":"2022-02-22T16:17:04.400737Z","shell.execute_reply.started":"2022-02-22T16:17:04.383347Z","shell.execute_reply":"2022-02-22T16:17:04.399768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.401737Z","iopub.execute_input":"2022-02-22T16:17:04.402446Z","iopub.status.idle":"2022-02-22T16:17:04.415752Z","shell.execute_reply.started":"2022-02-22T16:17:04.402386Z","shell.execute_reply":"2022-02-22T16:17:04.414669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.419200Z","iopub.execute_input":"2022-02-22T16:17:04.419849Z","iopub.status.idle":"2022-02-22T16:17:04.431700Z","shell.execute_reply.started":"2022-02-22T16:17:04.419816Z","shell.execute_reply":"2022-02-22T16:17:04.430666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data visualization","metadata":{}},{"cell_type":"code","source":"df_train = train.copy()\ntrain_dir = \"../input/tensorflow-great-barrier-reef/train_images\"\ndf_train['image_path'] = train_dir + \"/video_\" + df_train['video_id'].astype(str) + \"/\" + df_train['video_frame'].astype(str) + \".jpg\"\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.433297Z","iopub.execute_input":"2022-02-22T16:17:04.434316Z","iopub.status.idle":"2022-02-22T16:17:04.519007Z","shell.execute_reply.started":"2022-02-22T16:17:04.434258Z","shell.execute_reply":"2022-02-22T16:17:04.518175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['video_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.520589Z","iopub.execute_input":"2022-02-22T16:17:04.521076Z","iopub.status.idle":"2022-02-22T16:17:04.529572Z","shell.execute_reply.started":"2022-02-22T16:17:04.521032Z","shell.execute_reply":"2022-02-22T16:17:04.528662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" plt.bar(x = df_train['video_id'].value_counts().index, height = df_train['video_id'].value_counts())","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.531260Z","iopub.execute_input":"2022-02-22T16:17:04.531994Z","iopub.status.idle":"2022-02-22T16:17:04.811320Z","shell.execute_reply.started":"2022-02-22T16:17:04.531947Z","shell.execute_reply":"2022-02-22T16:17:04.810302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.814518Z","iopub.execute_input":"2022-02-22T16:17:04.814887Z","iopub.status.idle":"2022-02-22T16:17:04.839463Z","shell.execute_reply.started":"2022-02-22T16:17:04.814841Z","shell.execute_reply":"2022-02-22T16:17:04.838547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_training_images = len(df_train)\nnum_training_images","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.841036Z","iopub.execute_input":"2022-02-22T16:17:04.841548Z","iopub.status.idle":"2022-02-22T16:17:04.852501Z","shell.execute_reply.started":"2022-02-22T16:17:04.841502Z","shell.execute_reply":"2022-02-22T16:17:04.850930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20, 20))\nfor i in range(0, 10):\n    plt.subplot(5, 2, i+1)\n    index = random.randint(0, 23501)\n    img_path = df_train['image_path'].iloc[index]\n    img = Image.open(img_path)\n    plt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:04.854496Z","iopub.execute_input":"2022-02-22T16:17:04.854865Z","iopub.status.idle":"2022-02-22T16:17:08.648435Z","shell.execute_reply.started":"2022-02-22T16:17:04.854820Z","shell.execute_reply":"2022-02-22T16:17:08.645432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_video_2_10 = plt.imread('../input/tensorflow-great-barrier-reef/train_images/video_2/10.jpg')\nimg_video_2_10.shape","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:08.650651Z","iopub.execute_input":"2022-02-22T16:17:08.650937Z","iopub.status.idle":"2022-02-22T16:17:08.715298Z","shell.execute_reply.started":"2022-02-22T16:17:08.650904Z","shell.execute_reply":"2022-02-22T16:17:08.714032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_annotated = df_train[df_train['annotations'] != '[]']\ndf_train_annotated","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:08.717125Z","iopub.execute_input":"2022-02-22T16:17:08.717644Z","iopub.status.idle":"2022-02-22T16:17:08.742983Z","shell.execute_reply.started":"2022-02-22T16:17:08.717601Z","shell.execute_reply":"2022-02-22T16:17:08.742133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(len(df_train_annotated)/ num_training_images) * 100","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:08.744591Z","iopub.execute_input":"2022-02-22T16:17:08.745070Z","iopub.status.idle":"2022-02-22T16:17:08.750981Z","shell.execute_reply.started":"2022-02-22T16:17:08.745025Z","shell.execute_reply":"2022-02-22T16:17:08.750226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['No_bbox'] = df_train['annotations'].apply(lambda x:x.count('{'))\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:08.752356Z","iopub.execute_input":"2022-02-22T16:17:08.752583Z","iopub.status.idle":"2022-02-22T16:17:08.791819Z","shell.execute_reply.started":"2022-02-22T16:17:08.752556Z","shell.execute_reply":"2022-02-22T16:17:08.791281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['No_bbox'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:08.792709Z","iopub.execute_input":"2022-02-22T16:17:08.793427Z","iopub.status.idle":"2022-02-22T16:17:08.800644Z","shell.execute_reply.started":"2022-02-22T16:17:08.793396Z","shell.execute_reply":"2022-02-22T16:17:08.799763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (10,5))\nsns.countplot(x = df_train['No_bbox'])","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:08.801727Z","iopub.execute_input":"2022-02-22T16:17:08.802008Z","iopub.status.idle":"2022-02-22T16:17:09.133798Z","shell.execute_reply.started":"2022-02-22T16:17:08.801981Z","shell.execute_reply":"2022-02-22T16:17:09.133085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_annotated['No_bbox'] = df_train_annotated['annotations'].apply(lambda x:x.count('{'))\ndf_train_annotated.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:09.135012Z","iopub.execute_input":"2022-02-22T16:17:09.135610Z","iopub.status.idle":"2022-02-22T16:17:09.157122Z","shell.execute_reply.started":"2022-02-22T16:17:09.135522Z","shell.execute_reply":"2022-02-22T16:17:09.156029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_annotated[df_train_annotated['No_bbox'] >= 5]","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:09.158767Z","iopub.execute_input":"2022-02-22T16:17:09.159422Z","iopub.status.idle":"2022-02-22T16:17:09.185648Z","shell.execute_reply.started":"2022-02-22T16:17:09.159373Z","shell.execute_reply":"2022-02-22T16:17:09.184766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_annotated[df_train_annotated['No_bbox'] >= 8]","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:09.186954Z","iopub.execute_input":"2022-02-22T16:17:09.187552Z","iopub.status.idle":"2022-02-22T16:17:09.213706Z","shell.execute_reply.started":"2022-02-22T16:17:09.187517Z","shell.execute_reply":"2022-02-22T16:17:09.213044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import ast\n\nast.literal_eval(df_train_annotated.iloc[2345].annotations)","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:09.214601Z","iopub.execute_input":"2022-02-22T16:17:09.215200Z","iopub.status.idle":"2022-02-22T16:17:09.223182Z","shell.execute_reply.started":"2022-02-22T16:17:09.215153Z","shell.execute_reply":"2022-02-22T16:17:09.221727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def visualize_img_annots(df, id):\n    img_path = df['image_path'][id]\n    img = Image.open(img_path)\n    bounding_boxes = ast.literal_eval(df['annotations'].loc[id])\n    for box in bounding_boxes:\n            shape = (box['x'], box['y'], box['x']+box['width'], box['y']+box['height'])\n            ImageDraw.Draw(img).rectangle(shape, outline=180, width=3)\n    display(img)","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:09.224528Z","iopub.execute_input":"2022-02-22T16:17:09.224979Z","iopub.status.idle":"2022-02-22T16:17:09.239952Z","shell.execute_reply.started":"2022-02-22T16:17:09.224945Z","shell.execute_reply":"2022-02-22T16:17:09.239252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"visualize_img_annots(df_train_annotated, id = 9292)","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:09.241246Z","iopub.execute_input":"2022-02-22T16:17:09.241521Z","iopub.status.idle":"2022-02-22T16:17:09.791427Z","shell.execute_reply.started":"2022-02-22T16:17:09.241490Z","shell.execute_reply":"2022-02-22T16:17:09.790253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport plotly.graph_objects as go\nimport seaborn as sns\nsns.set_style('darkgrid')\n\nfrom PIL import Image, ImageDraw\nimport tensorflow as tf\n\nimport os\nimport ast  ## Change str -> list.\nimport sys\nimport time\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\nimport greatbarrierreef","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:09.792779Z","iopub.execute_input":"2022-02-22T16:17:09.793628Z","iopub.status.idle":"2022-02-22T16:17:16.712587Z","shell.execute_reply.started":"2022-02-22T16:17:09.793584Z","shell.execute_reply":"2022-02-22T16:17:16.711596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('../input/tensorflow-great-barrier-reef/train.csv')\ndf_train['img_path'] = os.path.join('../input/tensorflow-great-barrier-reef/train_images')+\"/video_\"+df_train.video_id.astype(str)+\"/\"+df_train.video_frame.astype(str)+\".jpg\"\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:16.715347Z","iopub.execute_input":"2022-02-22T16:17:16.715603Z","iopub.status.idle":"2022-02-22T16:17:16.834002Z","shell.execute_reply.started":"2022-02-22T16:17:16.715573Z","shell.execute_reply":"2022-02-22T16:17:16.833210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,5))\nsns.countplot(df_train['video_id'], color='#2196F3')","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:16.835461Z","iopub.execute_input":"2022-02-22T16:17:16.835679Z","iopub.status.idle":"2022-02-22T16:17:17.042629Z","shell.execute_reply.started":"2022-02-22T16:17:16.835653Z","shell.execute_reply":"2022-02-22T16:17:17.041575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with_annotation = len(df_train[df_train['annotations'] != '[]'])\nwithout_annotation = len(df_train[df_train['annotations'] == '[]'])\n\nlabels = ['Without Bounding Box', 'With Bounding Box']\n\nfig = go.Figure([go.Bar(x=labels, \n                        y=[without_annotation, with_annotation], width=0.6)])\n\nfig.update_layout(autosize=False, width=700, height=400, margin=dict(l=60, r=60, b=50, t=50, pad=4))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:17.047245Z","iopub.execute_input":"2022-02-22T16:17:17.047526Z","iopub.status.idle":"2022-02-22T16:17:17.180226Z","shell.execute_reply.started":"2022-02-22T16:17:17.047495Z","shell.execute_reply":"2022-02-22T16:17:17.179390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# creating new column which contains the total number of bounding boxes\ndf_train['No_bbox'] = df_train['annotations'].apply(lambda x:x.count('{')) \n\n# Example\n\nn = df_train['No_bbox'][12843]\nprint(df_train['annotations'][12843])\nprint(f'Number of bounding boxes are : {n}.')","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:17.181826Z","iopub.execute_input":"2022-02-22T16:17:17.182345Z","iopub.status.idle":"2022-02-22T16:17:17.210674Z","shell.execute_reply.started":"2022-02-22T16:17:17.182299Z","shell.execute_reply":"2022-02-22T16:17:17.209778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.bar(df_train['No_bbox'].value_counts().drop(0), title='Count of Bounding Boxes')\nfig.update_layout(autosize=False, width=700, height=400, margin=dict(l=60, r=60, b=50, t=50, pad=4))\nfig.show()\n","metadata":{"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2022-02-22T16:17:17.212327Z","iopub.execute_input":"2022-02-22T16:17:17.212831Z","iopub.status.idle":"2022-02-22T16:17:18.323317Z","shell.execute_reply.started":"2022-02-22T16:17:17.212787Z","shell.execute_reply":"2022-02-22T16:17:18.322369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['annotations'] = df_train['annotations'].apply(ast.literal_eval)\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:18.324541Z","iopub.execute_input":"2022-02-22T16:17:18.324791Z","iopub.status.idle":"2022-02-22T16:17:18.703787Z","shell.execute_reply.started":"2022-02-22T16:17:18.324761Z","shell.execute_reply":"2022-02-22T16:17:18.702930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2 = df_train[df_train['annotations'].astype(str) != \"[]\"]\ndf2 = df2[df2['No_bbox'] == 5]\ndf2.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:18.705147Z","iopub.execute_input":"2022-02-22T16:17:18.705508Z","iopub.status.idle":"2022-02-22T16:17:18.764757Z","shell.execute_reply.started":"2022-02-22T16:17:18.705463Z","shell.execute_reply":"2022-02-22T16:17:18.763753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def img_viz(df, id):\n    image = df_train['img_path'][id]\n    img = Image.open(image)\n    \n    for box in df_train['annotations'][id]:\n        shape = [box['x'], box['y'], box['x']+box['width'], box['y']+box['height']]\n        ImageDraw.Draw(img).rectangle(shape, outline =\"red\", width=3)\n    display(img)","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:18.766121Z","iopub.execute_input":"2022-02-22T16:17:18.766422Z","iopub.status.idle":"2022-02-22T16:17:18.772878Z","shell.execute_reply.started":"2022-02-22T16:17:18.766391Z","shell.execute_reply":"2022-02-22T16:17:18.772073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_viz(df_train, id=5474)","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:18.774328Z","iopub.execute_input":"2022-02-22T16:17:18.775058Z","iopub.status.idle":"2022-02-22T16:17:19.247756Z","shell.execute_reply.started":"2022-02-22T16:17:18.775009Z","shell.execute_reply":"2022-02-22T16:17:19.246329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport ast\nimport json\nimport subprocess\nfrom glob import glob\nfrom tqdm.notebook import tqdm\nfrom pprint import pprint\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom IPython.display import Video","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:30.648792Z","iopub.execute_input":"2022-02-22T16:17:30.649396Z","iopub.status.idle":"2022-02-22T16:17:31.058639Z","shell.execute_reply.started":"2022-02-22T16:17:30.649359Z","shell.execute_reply":"2022-02-22T16:17:31.057647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"INPUT_PATH = '../input/tensorflow-great-barrier-reef'\nHEIGHT = 720 # image height\nWIDTH  = 1280 # image width","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:45.510122Z","iopub.execute_input":"2022-02-22T16:17:45.510449Z","iopub.status.idle":"2022-02-22T16:17:45.514992Z","shell.execute_reply.started":"2022-02-22T16:17:45.510411Z","shell.execute_reply":"2022-02-22T16:17:45.514212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(INPUT_PATH + '/train.csv')\ndisplay(df_train)\nprint(df_train.info())","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:17:57.621270Z","iopub.execute_input":"2022-02-22T16:17:57.621691Z","iopub.status.idle":"2022-02-22T16:17:57.679429Z","shell.execute_reply.started":"2022-02-22T16:17:57.621661Z","shell.execute_reply":"2022-02-22T16:17:57.678661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for video_id in df_train['video_id'].unique():\n    print(f'video_id: {video_id}')\n    print(f'w   annotations:  {sum(df_train[df_train[\"video_id\"]==video_id][\"annotations\"] == \"[]\")}')\n    print(f'w/o annotations:  {sum(df_train[df_train[\"video_id\"]==video_id][\"annotations\"] != \"[]\")}\\n')","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:18:09.615261Z","iopub.execute_input":"2022-02-22T16:18:09.615562Z","iopub.status.idle":"2022-02-22T16:18:09.648602Z","shell.execute_reply.started":"2022-02-22T16:18:09.615529Z","shell.execute_reply":"2022-02-22T16:18:09.647688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Change the type of 'annotations' from str to list\ndf_train['annotations'] = df_train['annotations'].apply(ast.literal_eval) # str -> list\n# Add columns of image path and number of bboxes, and the difference.\ndf_train['image_path'] = INPUT_PATH + '/train_images/video_' + df_train['video_id'].astype(str) + '/' + df_train['video_frame'].astype(str) + \".jpg\"\ndf_train['num_bboxes'] = df_train['annotations'].apply(lambda x: len(x))\ndf_train['diff_num_bboxes'] = df_train['num_bboxes'].diff().fillna(0).astype(int)\ndisplay(df_train)","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:18:21.295079Z","iopub.execute_input":"2022-02-22T16:18:21.295438Z","iopub.status.idle":"2022-02-22T16:18:21.775757Z","shell.execute_reply.started":"2022-02-22T16:18:21.295400Z","shell.execute_reply":"2022-02-22T16:18:21.775115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Get indexes with 3 or more diff_num_bboxes\nindexes = df_train[abs(df_train['diff_num_bboxes'])>=3].index.values\ndisplay(df_train.iloc[indexes])","metadata":{"execution":{"iopub.status.busy":"2022-02-22T16:18:35.205597Z","iopub.execute_input":"2022-02-22T16:18:35.206286Z","iopub.status.idle":"2022-02-22T16:18:35.237352Z","shell.execute_reply.started":"2022-02-22T16:18:35.206247Z","shell.execute_reply":"2022-02-22T16:18:35.236283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}