{"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":"# Imports\n\nIn this competition, our goal is to detect crown-of-thorns starfish which has become a great threat to the Great Barrier Reef. We have to make a model that is able to detect those starfish in real time. Predictions are done in the form of bounding boxes. An image can have one or more bounding boxes that represent the object, starfish. Our goal is to evaluate the images in the same order as they were recorded in the video.   \n##### **Reference kernel**\n\nThank you for sharing your work. \n\n- [Kernel 1](https://www.kaggle.com/werooring/basic-eda-starter-for-everyone/notebook)\n- [Kernel 2](https://www.kaggle.com/matthieubritoantunes/great-barrier-reef-exploratory-data-analysis)\n- [Kernel 3](https://www.kaggle.com/kartik2khandelwal/data-analysis-and-prediction)\n- [Kernel 4](https://www.kaggle.com/sarabhian/gbr-extremely-beginner-level-guide-1#%F0%9F%90%A0%F0%9F%90%9F%F0%9F%90%A1%F0%9F%A6%91%F0%9F%90%99%F0%9F%A6%88%F0%9F%90%AC%F0%9F%90%B3%F0%9F%90%8B%F0%9F%A6%80%F0%9F%90%9A%F0%9F%8F%8A%E2%80%8D%E2%99%80%EF%B8%8F%F0%9F%8D%80%E2%98%98%F0%9F%92%BA%F0%9F%9A%A4%E2%9A%93%F0%9F%8F%9D%F0%9F%8C%8A%F0%9F%8C%8A-%F0%9F%90%A0%F0%9F%90%9F%F0%9F%90%A1)\n- [Kernel 5](https://www.kaggle.com/sjyangkevin/eda-bouding-box-analysis-annotated-videos)","metadata":{}},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')\n\nimport random\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib\nimport ast\nimport matplotlib.image as mpimg\nimport matplotlib.pyplot as plt\n\npd.set_option('display.max_colwidth',None)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:29.055897Z","iopub.execute_input":"2022-02-15T23:16:29.056239Z","iopub.status.idle":"2022-02-15T23:16:30.264920Z","shell.execute_reply.started":"2022-02-15T23:16:29.056158Z","shell.execute_reply":"2022-02-15T23:16:30.263626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 📊 Exploratory Data Analysis | EDA 👩‍💻 ","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-15T23:16:30.266254Z","iopub.execute_input":"2022-02-15T23:16:30.266416Z","iopub.status.idle":"2022-02-15T23:16:30.327907Z","shell.execute_reply.started":"2022-02-15T23:16:30.266396Z","shell.execute_reply":"2022-02-15T23:16:30.327184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:30.328750Z","iopub.execute_input":"2022-02-15T23:16:30.328929Z","iopub.status.idle":"2022-02-15T23:16:30.350569Z","shell.execute_reply.started":"2022-02-15T23:16:30.328907Z","shell.execute_reply":"2022-02-15T23:16:30.349694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:30.352832Z","iopub.execute_input":"2022-02-15T23:16:30.353248Z","iopub.status.idle":"2022-02-15T23:16:30.365565Z","shell.execute_reply.started":"2022-02-15T23:16:30.353210Z","shell.execute_reply":"2022-02-15T23:16:30.363811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('train dataset shape: ', train.shape)\nprint('test dataset shape: ', test.shape)\nprint('\\n')\nprint('submission dataset shape: ', sample_submission.shape)\nprint('\\n')\nprint('train dataset Info: ', train.info())\nprint('test dataset Info: ', test.info())","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:30.367377Z","iopub.execute_input":"2022-02-15T23:16:30.367745Z","iopub.status.idle":"2022-02-15T23:16:30.410188Z","shell.execute_reply.started":"2022-02-15T23:16:30.367709Z","shell.execute_reply":"2022-02-15T23:16:30.409334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nsns.heatmap(train.isna(), cbar=False)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:30.411263Z","iopub.execute_input":"2022-02-15T23:16:30.411448Z","iopub.status.idle":"2022-02-15T23:16:30.832220Z","shell.execute_reply.started":"2022-02-15T23:16:30.411427Z","shell.execute_reply":"2022-02-15T23:16:30.831367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"there are no nulls detected!","metadata":{}},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:30.833353Z","iopub.execute_input":"2022-02-15T23:16:30.834214Z","iopub.status.idle":"2022-02-15T23:16:30.841488Z","shell.execute_reply.started":"2022-02-15T23:16:30.834161Z","shell.execute_reply":"2022-02-15T23:16:30.840772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The number of `video_frame` per video","metadata":{}},{"cell_type":"code","source":"train.groupby('video_id')['video_frame'].count()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:30.842643Z","iopub.execute_input":"2022-02-15T23:16:30.843067Z","iopub.status.idle":"2022-02-15T23:16:30.859089Z","shell.execute_reply.started":"2022-02-15T23:16:30.843028Z","shell.execute_reply":"2022-02-15T23:16:30.858660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Checking out the `video_id` distribution / number of unique videos","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nsns.set_palette(\"pastel\")\nsns.histplot(data=train, x='video_id', kde = True)\nplt.axvline(train['video_id'].mean(),c = 'red', ls = '--', lw = 3)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:30.859947Z","iopub.execute_input":"2022-02-15T23:16:30.860489Z","iopub.status.idle":"2022-02-15T23:16:31.277465Z","shell.execute_reply.started":"2022-02-15T23:16:30.860461Z","shell.execute_reply":"2022-02-15T23:16:31.276830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"it can be seen that we are spanning over 3 different videos","metadata":{}},{"cell_type":"markdown","source":"### Adding image path from the `greatbarrierreef` folder to the dataset\n\nI would also like to see how those images look like so I will choose a random `video_id` and a random `image_id` from the `train` dataset","metadata":{}},{"cell_type":"code","source":"train['image_path'] = '../input/tensorflow-great-barrier-reef/train_images/video_'+train['video_id'].astype(str)+'/'+train['image_id'].apply(lambda x: x.split('-')[1])+'.jpg'","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:31.279888Z","iopub.execute_input":"2022-02-15T23:16:31.280071Z","iopub.status.idle":"2022-02-15T23:16:31.315009Z","shell.execute_reply.started":"2022-02-15T23:16:31.280049Z","shell.execute_reply":"2022-02-15T23:16:31.313292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.tail()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:31.316003Z","iopub.execute_input":"2022-02-15T23:16:31.316292Z","iopub.status.idle":"2022-02-15T23:16:31.328750Z","shell.execute_reply.started":"2022-02-15T23:16:31.316261Z","shell.execute_reply":"2022-02-15T23:16:31.328124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Plotting random image 🐠","metadata":{}},{"cell_type":"code","source":"rows, cols = 2, 2\nfig, axs = plt.subplots(rows, cols, figsize=(12,10))\nfig.subplots_adjust(top = 0.99, bottom=0.01, hspace=-0.6, wspace=0.4)\nfor i,ax in zip(train, axs.ravel()):\n  random_image = random.randint(0,len(train)-1)\n  img = mpimg.imread(train['image_path'][random_image])\n  ax.imshow(img)\n  ax.axis('off')\n  ax.set_title(f'Image ID: {train[\"image_id\"][random_image]}',{'fontsize': 20})","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:31.329700Z","iopub.execute_input":"2022-02-15T23:16:31.329859Z","iopub.status.idle":"2022-02-15T23:16:32.324215Z","shell.execute_reply.started":"2022-02-15T23:16:31.329838Z","shell.execute_reply":"2022-02-15T23:16:32.323250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### All About Decoding `Annotations`\nExploring `annotations`\n\nAnnotations have the following format: (there can be multiple records in one list)\n> [{'x': 645, 'y': 182, 'width': 41, 'height': 45}]\n\nwhere,\n\n- '645' -- x coordinate\n- '182' -- x coordinate\n- '41'  -- width of the box\n- '45'  -- height of the box","metadata":{}},{"cell_type":"code","source":"len(train['annotations'])  ","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.325294Z","iopub.execute_input":"2022-02-15T23:16:32.325503Z","iopub.status.idle":"2022-02-15T23:16:32.331585Z","shell.execute_reply.started":"2022-02-15T23:16:32.325476Z","shell.execute_reply":"2022-02-15T23:16:32.330865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['annotations'].dtype","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.332459Z","iopub.execute_input":"2022-02-15T23:16:32.332675Z","iopub.status.idle":"2022-02-15T23:16:32.349966Z","shell.execute_reply.started":"2022-02-15T23:16:32.332646Z","shell.execute_reply":"2022-02-15T23:16:32.349388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.annotations.describe()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.350794Z","iopub.execute_input":"2022-02-15T23:16:32.350999Z","iopub.status.idle":"2022-02-15T23:16:32.373576Z","shell.execute_reply.started":"2022-02-15T23:16:32.350973Z","shell.execute_reply":"2022-02-15T23:16:32.372608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Unique `annotations`","metadata":{}},{"cell_type":"code","source":"train.annotations.unique()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.374710Z","iopub.execute_input":"2022-02-15T23:16:32.375470Z","iopub.status.idle":"2022-02-15T23:16:32.387613Z","shell.execute_reply.started":"2022-02-15T23:16:32.375394Z","shell.execute_reply":"2022-02-15T23:16:32.387157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"record_with_annotations = train[train['annotations'] != '[]']['annotations'].count()\nrecord_without_annotations = train[train['annotations'] == '[]']['annotations'].count()\nplt.rcParams['figure.figsize'] = (11, 5)\nsns.barplot(x = ['record with annotations', 'record without annotations'], y = [record_with_annotations, record_without_annotations], palette = 'colorblind')\nplt.title('with/without Annotation Distribution', fontsize = 30)\nplt.xlabel('Annotation', fontsize = 15)\nplt.ylabel('Count', fontsize = 15)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.388409Z","iopub.execute_input":"2022-02-15T23:16:32.389128Z","iopub.status.idle":"2022-02-15T23:16:32.535553Z","shell.execute_reply.started":"2022-02-15T23:16:32.389085Z","shell.execute_reply":"2022-02-15T23:16:32.534746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"annotation_len = train[train['annotations'] != '[]']\nannotation_len","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.536661Z","iopub.execute_input":"2022-02-15T23:16:32.536847Z","iopub.status.idle":"2022-02-15T23:16:32.560642Z","shell.execute_reply.started":"2022-02-15T23:16:32.536821Z","shell.execute_reply":"2022-02-15T23:16:32.560138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"number of no records for `annotations`","metadata":{}},{"cell_type":"code","source":"len(train['annotations'])  - len(annotation_len['annotations'])","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.561918Z","iopub.execute_input":"2022-02-15T23:16:32.562361Z","iopub.status.idle":"2022-02-15T23:16:32.568246Z","shell.execute_reply.started":"2022-02-15T23:16:32.562332Z","shell.execute_reply":"2022-02-15T23:16:32.567479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"looks like we are missiong a lot of records for annotations, which can be difficult for us to make a good model. ","metadata":{}},{"cell_type":"markdown","source":"checking annotation length distribution for records that have `annotations not null` detected\n\nif the length of `annotation` detects the presence of starfish, lets check the distribution:","metadata":{}},{"cell_type":"code","source":"plt.rcParams['figure.figsize'] = (15, 9)\nsns.countplot(annotation_len['annotations'].apply(lambda x: len(x)).value_counts(), palette = 'colorblind')\nplt.title('Annotation Length Distribution', fontsize = 30)\nplt.xlabel('Annotation', fontsize = 15)\nplt.ylabel('Count', fontsize = 15)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.569282Z","iopub.execute_input":"2022-02-15T23:16:32.569522Z","iopub.status.idle":"2022-02-15T23:16:32.951272Z","shell.execute_reply.started":"2022-02-15T23:16:32.569502Z","shell.execute_reply":"2022-02-15T23:16:32.949307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### `Annotation` distribution per `video_id`\n\n**Reference Kernel** is [here](https://www.kaggle.com/icaram/eda-non-annotated-starfish)","metadata":{}},{"cell_type":"code","source":"# for video_id in train['video_id'].unique():\nvideo_1 = (annotation_len[annotation_len['video_id'] == 0]['annotations']).count()\nvideo_2 = (annotation_len[annotation_len['video_id'] == 1]['annotations']).count()\nvideo_3 = (annotation_len[annotation_len['video_id'] == 2]['annotations']).count()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.952782Z","iopub.execute_input":"2022-02-15T23:16:32.952997Z","iopub.status.idle":"2022-02-15T23:16:32.960979Z","shell.execute_reply.started":"2022-02-15T23:16:32.952974Z","shell.execute_reply":"2022-02-15T23:16:32.960130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.barplot(x=['Video id: 0', 'Video id: 1', 'Video id: 2'], y=[video_1, video_2, video_3])\nax.set_ylabel('Count')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:32.962137Z","iopub.execute_input":"2022-02-15T23:16:32.963185Z","iopub.status.idle":"2022-02-15T23:16:33.143507Z","shell.execute_reply.started":"2022-02-15T23:16:32.963145Z","shell.execute_reply":"2022-02-15T23:16:33.142332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"seems like video with `ID` 2 has the least amount of `annotations` record.","metadata":{}},{"cell_type":"markdown","source":"### Checking for corelation\n\nno noticeable positive or negative correlation detected. ","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(12,8))\nsns.heatmap(train.corr(), linewidths = 0.5, linecolor = 'white', annot = True,\n           cmap = 'RdYlGn', cbar_kws = {'shrink' : 0.5})","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.144663Z","iopub.execute_input":"2022-02-15T23:16:33.144849Z","iopub.status.idle":"2022-02-15T23:16:33.375442Z","shell.execute_reply.started":"2022-02-15T23:16:33.144826Z","shell.execute_reply":"2022-02-15T23:16:33.374884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"adding `image_path` to my `annotation_len` dataframe","metadata":{}},{"cell_type":"code","source":"annotation_len['image_path'] = '../input/tensorflow-great-barrier-reef/train_images/video_'+annotation_len['video_id'].astype(str)+'/'+annotation_len['image_id'].apply(lambda x: x.split('-')[1])+'.jpg'","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.376580Z","iopub.execute_input":"2022-02-15T23:16:33.376773Z","iopub.status.idle":"2022-02-15T23:16:33.389087Z","shell.execute_reply.started":"2022-02-15T23:16:33.376752Z","shell.execute_reply":"2022-02-15T23:16:33.388172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"annotation_len.tail(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.390335Z","iopub.execute_input":"2022-02-15T23:16:33.390995Z","iopub.status.idle":"2022-02-15T23:16:33.409868Z","shell.execute_reply.started":"2022-02-15T23:16:33.390910Z","shell.execute_reply":"2022-02-15T23:16:33.409333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Detecting object with the help of a **`bounding box`** from a random image file","metadata":{}},{"cell_type":"markdown","source":"Each record in the `annotation` represents a bounding box. We can see from above exploration that one `annotation` list can have multiple records. This correspond to multiple bounding boxes or our goal of detected object, starfish 🐟.\n\nIn order to draw bounding box we must transform the `annotations` to list. `annotations` is in a string format. For bounding box the indices must be integers.  ","metadata":{}},{"cell_type":"code","source":"annotation_len['annotations'] = annotation_len['annotations'].apply(ast.literal_eval)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.410925Z","iopub.execute_input":"2022-02-15T23:16:33.411304Z","iopub.status.idle":"2022-02-15T23:16:33.729939Z","shell.execute_reply.started":"2022-02-15T23:16:33.411274Z","shell.execute_reply":"2022-02-15T23:16:33.729049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"annotation_len.tail(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.731617Z","iopub.execute_input":"2022-02-15T23:16:33.732004Z","iopub.status.idle":"2022-02-15T23:16:33.744242Z","shell.execute_reply.started":"2022-02-15T23:16:33.731980Z","shell.execute_reply":"2022-02-15T23:16:33.743215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"adding number of bounding box from the list of `annotations`.","metadata":{}},{"cell_type":"code","source":"annotation_len['number_of_bounding_box'] = annotation_len['annotations'].apply(lambda x: len(x))\nannotation_len.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.748676Z","iopub.execute_input":"2022-02-15T23:16:33.749401Z","iopub.status.idle":"2022-02-15T23:16:33.770322Z","shell.execute_reply.started":"2022-02-15T23:16:33.749358Z","shell.execute_reply":"2022-02-15T23:16:33.769337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Max number of starfish 🐟 that can be present in the dataframe","metadata":{}},{"cell_type":"code","source":"annotation_len['number_of_bounding_box'].max()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.771319Z","iopub.execute_input":"2022-02-15T23:16:33.772321Z","iopub.status.idle":"2022-02-15T23:16:33.778969Z","shell.execute_reply.started":"2022-02-15T23:16:33.772260Z","shell.execute_reply":"2022-02-15T23:16:33.778568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"looks like 18 is the maximum number of startfish 🐟 that can be in an image from analyzing the DF","metadata":{}},{"cell_type":"code","source":"max_bbox = annotation_len[annotation_len['number_of_bounding_box'] == 18]['annotations']","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.779808Z","iopub.execute_input":"2022-02-15T23:16:33.780203Z","iopub.status.idle":"2022-02-15T23:16:33.801297Z","shell.execute_reply.started":"2022-02-15T23:16:33.780179Z","shell.execute_reply":"2022-02-15T23:16:33.800655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"max_bbox","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.802272Z","iopub.execute_input":"2022-02-15T23:16:33.803028Z","iopub.status.idle":"2022-02-15T23:16:33.827607Z","shell.execute_reply.started":"2022-02-15T23:16:33.803003Z","shell.execute_reply":"2022-02-15T23:16:33.826712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(max_bbox)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.828647Z","iopub.execute_input":"2022-02-15T23:16:33.829143Z","iopub.status.idle":"2022-02-15T23:16:33.843576Z","shell.execute_reply.started":"2022-02-15T23:16:33.828907Z","shell.execute_reply":"2022-02-15T23:16:33.842627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Bounding Box distribution","metadata":{}},{"cell_type":"code","source":"plt.rcParams['figure.figsize'] = (15, 9)\nsns.countplot(annotation_len['number_of_bounding_box'], palette = 'colorblind')\nplt.title('Bounding Boxh Distribution', fontsize = 30)\nplt.xlabel('Bounding Box', fontsize = 15)\nplt.ylabel('Count', fontsize = 15)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:33.844555Z","iopub.execute_input":"2022-02-15T23:16:33.845183Z","iopub.status.idle":"2022-02-15T23:16:34.113945Z","shell.execute_reply.started":"2022-02-15T23:16:33.845149Z","shell.execute_reply":"2022-02-15T23:16:34.113023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rows, cols = 1, 2\nfig, axs = plt.subplots(rows, cols, figsize=(24,10))\nfig.subplots_adjust(top = 0.99, bottom=0.01, hspace=-0.6, wspace=0.4)\nfor i,ax in zip(annotation_len, axs.ravel()):\n  random_image = random.choice(annotation_len.index)\n  img = mpimg.imread(annotation_len['image_path'][random_image])\n    \n  # creating bounding boc from annotation data\n  annotations = annotation_len['annotations'][random_image]\n  total = len(annotations)\n  for bbox in annotations:\n    x, y, w, h = bbox['x'], bbox['y'], bbox['width'], bbox['height']\n    rect = matplotlib.patches.Rectangle((x, y), w, h, linewidth=1, edgecolor='darkorange', facecolor='orange', alpha=.5)\n    ax.add_patch(rect)\n  ax.imshow(img)\n  ax.axis('off')\n  ax.set_title(f'Image ID: {annotation_len[\"image_id\"][random_image]} with {total} starfish(s)',{'fontsize': 15})","metadata":{"execution":{"iopub.status.busy":"2022-02-15T23:16:34.115384Z","iopub.execute_input":"2022-02-15T23:16:34.115872Z","iopub.status.idle":"2022-02-15T23:16:34.995655Z","shell.execute_reply.started":"2022-02-15T23:16:34.115843Z","shell.execute_reply":"2022-02-15T23:16:34.991510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**WOW!! Looks great**","metadata":{}}]}