{"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":"# Installing IceVision","metadata":{}},{"cell_type":"code","source":"!python --version","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:48:40.690003Z","iopub.execute_input":"2023-06-09T05:48:40.690517Z","iopub.status.idle":"2023-06-09T05:48:41.659841Z","shell.execute_reply.started":"2023-06-09T05:48:40.690477Z","shell.execute_reply":"2023-06-09T05:48:41.658614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Note:** You can ignore the 'errors' and warnings that are output by pip in the next code cell.","metadata":{}},{"cell_type":"code","source":"# Download IceVision installation script:\n!wget https://raw.githubusercontent.com/airctic/icevision/master/icevision_install.sh\n\n# Choose installation target: cuda11 or cuda10 or cpu\n!bash icevision_install.sh cuda11 master","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:48:51.180584Z","iopub.execute_input":"2023-06-09T05:48:51.181363Z","iopub.status.idle":"2023-06-09T05:53:59.338309Z","shell.execute_reply.started":"2023-06-09T05:48:51.181316Z","shell.execute_reply":"2023-06-09T05:53:59.337047Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Restart kernel after installation:\nimport IPython\n\nIPython.Application.instance().kernel.do_shutdown(True)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:54:14.218227Z","iopub.execute_input":"2023-06-09T05:54:14.219031Z","iopub.status.idle":"2023-06-09T05:54:14.232241Z","shell.execute_reply.started":"2023-06-09T05:54:14.218986Z","shell.execute_reply":"2023-06-09T05:54:14.231141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from icevision.all import *","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:54:28.969357Z","iopub.execute_input":"2023-06-09T05:54:28.969818Z","iopub.status.idle":"2023-06-09T05:55:47.846407Z","shell.execute_reply.started":"2023-06-09T05:54:28.969777Z","shell.execute_reply":"2023-06-09T05:55:47.845311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Let's begin!\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:55:53.546527Z","iopub.execute_input":"2023-06-09T05:55:53.546958Z","iopub.status.idle":"2023-06-09T05:55:53.553145Z","shell.execute_reply.started":"2023-06-09T05:55:53.546918Z","shell.execute_reply":"2023-06-09T05:55:53.551927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Preparation","metadata":{}},{"cell_type":"code","source":"from pathlib import Path\n\nextra_data_path = Path('/kaggle/input/b-m-g-a-extra-data')\n!ls {extra_data_path}","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:56:07.558617Z","iopub.execute_input":"2023-06-09T05:56:07.559182Z","iopub.status.idle":"2023-06-09T05:56:08.842631Z","shell.execute_reply.started":"2023-06-09T05:56:07.559128Z","shell.execute_reply":"2023-06-09T05:56:08.840753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's create a single folder in our working directory, and copy all the relevant images into it.","metadata":{}},{"cell_type":"code","source":"working_dir = Path('/kaggle/working/')\nall_images_path = working_dir/'all_dot_scatter_images'\nall_images_path.mkdir()","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:56:20.845711Z","iopub.execute_input":"2023-06-09T05:56:20.846634Z","iopub.status.idle":"2023-06-09T05:56:20.853122Z","shell.execute_reply.started":"2023-06-09T05:56:20.846581Z","shell.execute_reply":"2023-06-09T05:56:20.851965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"First, we'll copy the competition dot plot images.","metadata":{}},{"cell_type":"code","source":"competition_dot_images_path = extra_data_path/'dot_600'/'dot_600'\ni = 0\nfor file_path in competition_dot_images_path.glob(\"*.jpg\"):\n    i += 1\nprint(f\"{i} competition dot plot images found.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:56:36.426542Z","iopub.execute_input":"2023-06-09T05:56:36.427050Z","iopub.status.idle":"2023-06-09T05:56:36.668155Z","shell.execute_reply.started":"2023-06-09T05:56:36.427005Z","shell.execute_reply":"2023-06-09T05:56:36.667008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.notebook import tqdm\nimport shutil\n\norigin = str(competition_dot_images_path) + '/'\ntarget = str(all_images_path) + '/'\ni = 0\nfor file_path in tqdm(sorted(competition_dot_images_path.glob(\"*.jpg\"))):\n    file_name = str(file_path).split(\"/\")[-1]\n    shutil.copy(origin + file_name, target + file_name)\n    i += 1\nprint(f\"{i} files copied.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:56:45.810725Z","iopub.execute_input":"2023-06-09T05:56:45.811252Z","iopub.status.idle":"2023-06-09T05:56:50.963604Z","shell.execute_reply.started":"2023-06-09T05:56:45.811204Z","shell.execute_reply":"2023-06-09T05:56:50.962371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Next, we'll copy the competition scatter plot images. To do this, we'll create a data frame (containing the scatter plot information) first.","metadata":{}},{"cell_type":"code","source":"competition_data_path = Path('/kaggle/input/benetech-making-graphs-accessible')\n!ls {competition_data_path}","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:57:01.655129Z","iopub.execute_input":"2023-06-09T05:57:01.655562Z","iopub.status.idle":"2023-06-09T05:57:02.675476Z","shell.execute_reply.started":"2023-06-09T05:57:01.655522Z","shell.execute_reply":"2023-06-09T05:57:02.674072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = competition_data_path/'train'\n!ls {train_path}","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:57:05.463882Z","iopub.execute_input":"2023-06-09T05:57:05.464388Z","iopub.status.idle":"2023-06-09T05:57:06.570470Z","shell.execute_reply.started":"2023-06-09T05:57:05.464343Z","shell.execute_reply":"2023-06-09T05:57:06.568826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"competition_images_path = train_path/'images'\ncompetition_annotations_path = train_path/'annotations'","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:57:09.468147Z","iopub.execute_input":"2023-06-09T05:57:09.468627Z","iopub.status.idle":"2023-06-09T05:57:09.474131Z","shell.execute_reply.started":"2023-06-09T05:57:09.468587Z","shell.execute_reply":"2023-06-09T05:57:09.472794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\n\nimg_file_names = []\nsources = []\nchart_types = []\n\nfor file_path in tqdm(sorted(competition_annotations_path.glob(\"*.json\"))):\n    with open(file_path, \"r\") as json_file:\n        json_file_name = str(file_path).split(\"/\")[-1]\n        without_ext = json_file_name.split(\".\")[0]\n        img_file_name = without_ext + \".jpg\"\n        img_file_names.append(img_file_name)\n        data = json.load(json_file)\n        sources.append(data['source'])\n        chart_types.append(data['chart-type'])\n\nlen(img_file_names), len(sources), len(chart_types)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T05:57:17.335253Z","iopub.execute_input":"2023-06-09T05:57:17.335676Z","iopub.status.idle":"2023-06-09T06:03:09.566541Z","shell.execute_reply.started":"2023-06-09T05:57:17.335640Z","shell.execute_reply":"2023-06-09T06:03:09.565212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\ndf = pd.DataFrame({'img_file_name': img_file_names, 'source': sources, 'chart_type': chart_types})\ndf","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:03:47.789076Z","iopub.execute_input":"2023-06-09T06:03:47.789507Z","iopub.status.idle":"2023-06-09T06:03:47.844627Z","shell.execute_reply.started":"2023-06-09T06:03:47.789465Z","shell.execute_reply":"2023-06-09T06:03:47.843245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scatter_df = df.loc[df['chart_type'] == 'scatter'].reset_index(drop=True)\nscatter_df","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:04:01.220734Z","iopub.execute_input":"2023-06-09T06:04:01.221248Z","iopub.status.idle":"2023-06-09T06:04:01.269756Z","shell.execute_reply.started":"2023-06-09T06:04:01.221202Z","shell.execute_reply":"2023-06-09T06:04:01.268628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We need to filter out the 'corrupt' images, i.e., the images where one or more bounding box lies outside the image.","metadata":{}},{"cell_type":"code","source":"corrupt_files_df = pd.read_csv(extra_data_path/'corrupt_files_scatter_16px.csv')\ncorrupt_files_df","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:04:11.964019Z","iopub.execute_input":"2023-06-09T06:04:11.964564Z","iopub.status.idle":"2023-06-09T06:04:11.993390Z","shell.execute_reply.started":"2023-06-09T06:04:11.964513Z","shell.execute_reply":"2023-06-09T06:04:11.992275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corrupt = corrupt_files_df['corrupt_file'].tolist()\ncorrupt = [c[:-5] + \".jpg\" for c in corrupt]\ncorrupt[:5]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:05:19.158832Z","iopub.execute_input":"2023-06-09T06:05:19.159412Z","iopub.status.idle":"2023-06-09T06:05:19.171870Z","shell.execute_reply.started":"2023-06-09T06:05:19.159361Z","shell.execute_reply":"2023-06-09T06:05:19.170790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scatter_df = scatter_df.loc[~ scatter_df['img_file_name'].isin(corrupt)].reset_index(drop=True)\nlen(scatter_df)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:05:32.992777Z","iopub.execute_input":"2023-06-09T06:05:32.993215Z","iopub.status.idle":"2023-06-09T06:05:33.011015Z","shell.execute_reply.started":"2023-06-09T06:05:32.993174Z","shell.execute_reply":"2023-06-09T06:05:33.009656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"origin = str(competition_images_path) + '/'\ntarget = str(all_images_path) + '/'\ni = 0\nfor i in tqdm(range(len(scatter_df))):\n    file_name = scatter_df['img_file_name'][i]\n    shutil.copy(origin + file_name, target + file_name)\n    i += 1\nprint(f\"{i} files copied.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:05:43.997683Z","iopub.execute_input":"2023-06-09T06:05:43.998095Z","iopub.status.idle":"2023-06-09T06:07:00.496622Z","shell.execute_reply.started":"2023-06-09T06:05:43.998053Z","shell.execute_reply":"2023-06-09T06:07:00.495382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Finally, we'll copy the extra scatter plot images.","metadata":{}},{"cell_type":"code","source":"extra_images_path = extra_data_path/'scatter_extra_176'/'scatter_extra_176'\ni = 0\nfor file_path in extra_images_path.glob(\"*.jpg\"):\n    i += 1\nprint(f\"{i} extra scatter plot images found.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:07:45.471834Z","iopub.execute_input":"2023-06-09T06:07:45.472251Z","iopub.status.idle":"2023-06-09T06:07:45.559756Z","shell.execute_reply.started":"2023-06-09T06:07:45.472213Z","shell.execute_reply":"2023-06-09T06:07:45.558508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"origin = str(extra_images_path) + '/'\ntarget = str(all_images_path) + '/'\ni = 0\nfor file_path in extra_images_path.glob(\"*.jpg\"):\n    file_name = str(file_path).split(\"/\")[-1]\n    shutil.copy(origin + file_name, target + file_name)\n    i += 1\nprint(f\"{i} files copied.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:07:54.487484Z","iopub.execute_input":"2023-06-09T06:07:54.487990Z","iopub.status.idle":"2023-06-09T06:07:55.880166Z","shell.execute_reply.started":"2023-06-09T06:07:54.487944Z","shell.execute_reply":"2023-06-09T06:07:55.878986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's see how many images we have in total.","metadata":{}},{"cell_type":"code","source":"i = 0\nfor file_path in all_images_path.glob(\"*.jpg\"):\n    i += 1\nprint(f\"{i} dot plot & scatter plot images found.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:08:05.360356Z","iopub.execute_input":"2023-06-09T06:08:05.360800Z","iopub.status.idle":"2023-06-09T06:08:05.423938Z","shell.execute_reply.started":"2023-06-09T06:08:05.360764Z","shell.execute_reply":"2023-06-09T06:08:05.422652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"600 + 11223 + 176","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:08:10.082147Z","iopub.execute_input":"2023-06-09T06:08:10.082623Z","iopub.status.idle":"2023-06-09T06:08:10.090673Z","shell.execute_reply.started":"2023-06-09T06:08:10.082581Z","shell.execute_reply":"2023-06-09T06:08:10.089396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Similarly, let's create a single folder in our working directory, and copy all the relevant VOC XML files into it.","metadata":{}},{"cell_type":"code","source":"all_VOC_XML_path = working_dir/'all_dot_scatter_VOC_XML_files'\nall_VOC_XML_path.mkdir()","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:08:17.925326Z","iopub.execute_input":"2023-06-09T06:08:17.925748Z","iopub.status.idle":"2023-06-09T06:08:17.931284Z","shell.execute_reply.started":"2023-06-09T06:08:17.925712Z","shell.execute_reply":"2023-06-09T06:08:17.930003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"First, we'll copy the competition dot plot VOC XML files.","metadata":{}},{"cell_type":"code","source":"competition_dot_VOC_XML_path = extra_data_path/'labels_dot_600_VOC_XML'/'labels_dot_600_VOC_XML'\ni = 0\nfor file_path in competition_dot_VOC_XML_path.glob(\"*.xml\"):\n    i += 1\nprint(f\"{i} dot plot VOC XML files found.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:08:39.727354Z","iopub.execute_input":"2023-06-09T06:08:39.727827Z","iopub.status.idle":"2023-06-09T06:08:40.080995Z","shell.execute_reply.started":"2023-06-09T06:08:39.727789Z","shell.execute_reply":"2023-06-09T06:08:40.079695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"origin = str(competition_dot_VOC_XML_path) + '/'\ntarget = str(all_VOC_XML_path) + '/'\ni = 0\nfor file_path in tqdm(sorted(competition_dot_VOC_XML_path.glob(\"*.xml\"))):\n    file_name = str(file_path).split(\"/\")[-1]\n    shutil.copy(origin + file_name, target + file_name)\n    i += 1\nprint(f\"{i} files copied.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:09:02.308743Z","iopub.execute_input":"2023-06-09T06:09:02.309302Z","iopub.status.idle":"2023-06-09T06:09:08.450874Z","shell.execute_reply.started":"2023-06-09T06:09:02.309234Z","shell.execute_reply":"2023-06-09T06:09:08.449482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Next, we'll copy the competition scatter plot VOC XML files.","metadata":{}},{"cell_type":"code","source":"competition_scatter_VOC_XML_path = extra_data_path/'labels_scatter_11223_VOC_XML'\ni = 0\nfor file_path in competition_scatter_VOC_XML_path.glob(\"*.xml\"):\n    i += 1\nprint(f\"{i} competition scatter plot VOC XML files found.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:09:19.279700Z","iopub.execute_input":"2023-06-09T06:09:19.280107Z","iopub.status.idle":"2023-06-09T06:09:20.164520Z","shell.execute_reply.started":"2023-06-09T06:09:19.280066Z","shell.execute_reply":"2023-06-09T06:09:20.162986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"origin = str(competition_scatter_VOC_XML_path) + '/'\ntarget = str(all_VOC_XML_path) + '/'\ni = 0\nfor i in tqdm(range(len(scatter_df))):\n    file_name = scatter_df['img_file_name'][i]\n    file_name = file_name[:-4] + \".xml\"\n    shutil.copy(origin + file_name, target + file_name)\n    i += 1\nprint(f\"{i} files copied.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:09:33.599639Z","iopub.execute_input":"2023-06-09T06:09:33.600057Z","iopub.status.idle":"2023-06-09T06:11:20.974618Z","shell.execute_reply.started":"2023-06-09T06:09:33.600018Z","shell.execute_reply":"2023-06-09T06:11:20.973376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Finally, we'll copy the extra scatter plot VOC XML files.","metadata":{}},{"cell_type":"code","source":"extra_VOC_XML_path = extra_data_path/'labels_scatter_extra_176_VOC_XML'/'labels_scatter_extra_176_VOC_XML'\ni = 0\nfor file_path in extra_VOC_XML_path.glob(\"*.xml\"):\n    i += 1\nprint(f\"{i} extra scatter plot VOC XML files found.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:11:49.298790Z","iopub.execute_input":"2023-06-09T06:11:49.299200Z","iopub.status.idle":"2023-06-09T06:11:49.392248Z","shell.execute_reply.started":"2023-06-09T06:11:49.299161Z","shell.execute_reply":"2023-06-09T06:11:49.391005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"origin = str(extra_VOC_XML_path) + '/'\ntarget = str(all_VOC_XML_path) + '/'\ni = 0\nfor file_path in extra_VOC_XML_path.glob(\"*.xml\"):\n    file_name = str(file_path).split(\"/\")[-1]\n    shutil.copy(origin + file_name, target + file_name)\n    i += 1\nprint(f\"{i} files copied.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:02.217474Z","iopub.execute_input":"2023-06-09T06:12:02.218021Z","iopub.status.idle":"2023-06-09T06:12:03.605569Z","shell.execute_reply.started":"2023-06-09T06:12:02.217972Z","shell.execute_reply":"2023-06-09T06:12:03.604279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's see how many VOC XML files we have in total.","metadata":{}},{"cell_type":"code","source":"i = 0\nfor file_path in sorted(all_VOC_XML_path.glob(\"*.xml\")):\n    i += 1\nprint(f\"{i} VOC XML files found.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:09.557266Z","iopub.execute_input":"2023-06-09T06:12:09.557802Z","iopub.status.idle":"2023-06-09T06:12:09.763287Z","shell.execute_reply.started":"2023-06-09T06:12:09.557759Z","shell.execute_reply":"2023-06-09T06:12:09.761857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"600 + 11223 + 176","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:13.226931Z","iopub.execute_input":"2023-06-09T06:12:13.227349Z","iopub.status.idle":"2023-06-09T06:12:13.234728Z","shell.execute_reply.started":"2023-06-09T06:12:13.227308Z","shell.execute_reply":"2023-06-09T06:12:13.233496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Validation Scheme","metadata":{}},{"cell_type":"code","source":"from PIL import Image\n\nval_scheme = Image.open(extra_data_path/'Validation_Scheme_Dot_Scatter.png')\nval_scheme","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:19.108468Z","iopub.execute_input":"2023-06-09T06:12:19.108899Z","iopub.status.idle":"2023-06-09T06:12:19.189445Z","shell.execute_reply.started":"2023-06-09T06:12:19.108862Z","shell.execute_reply":"2023-06-09T06:12:19.188301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names = []\ntrain_file_names = []","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:24.945487Z","iopub.execute_input":"2023-06-09T06:12:24.945908Z","iopub.status.idle":"2023-06-09T06:12:24.951392Z","shell.execute_reply.started":"2023-06-09T06:12:24.945860Z","shell.execute_reply":"2023-06-09T06:12:24.949673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dot_file_names = []\nfor file_path in sorted(competition_dot_images_path.glob(\"*.jpg\")):\n    file_name = str(file_path).split(\"/\")[-1]\n    dot_file_names.append(file_name)\nlen(dot_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:34.197553Z","iopub.execute_input":"2023-06-09T06:12:34.197963Z","iopub.status.idle":"2023-06-09T06:12:34.218974Z","shell.execute_reply.started":"2023-06-09T06:12:34.197925Z","shell.execute_reply":"2023-06-09T06:12:34.217601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n\nrandom.seed(42)\nrandom.shuffle(dot_file_names)\ndot_file_names[:5]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:40.588614Z","iopub.execute_input":"2023-06-09T06:12:40.589028Z","iopub.status.idle":"2023-06-09T06:12:40.597505Z","shell.execute_reply.started":"2023-06-09T06:12:40.588989Z","shell.execute_reply":"2023-06-09T06:12:40.596383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names.extend(dot_file_names[:80])\nlen(val_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:54.170548Z","iopub.execute_input":"2023-06-09T06:12:54.171967Z","iopub.status.idle":"2023-06-09T06:12:54.190797Z","shell.execute_reply.started":"2023-06-09T06:12:54.171913Z","shell.execute_reply":"2023-06-09T06:12:54.189737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_file_names.extend(dot_file_names[80:180])\nlen(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:12:57.788405Z","iopub.execute_input":"2023-06-09T06:12:57.788904Z","iopub.status.idle":"2023-06-09T06:12:57.797644Z","shell.execute_reply.started":"2023-06-09T06:12:57.788849Z","shell.execute_reply":"2023-06-09T06:12:57.796364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scatter_extracted = scatter_df.loc[scatter_df['source'] == 'extracted']\nlen(scatter_extracted)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:13:02.506757Z","iopub.execute_input":"2023-06-09T06:13:02.507179Z","iopub.status.idle":"2023-06-09T06:13:02.519226Z","shell.execute_reply.started":"2023-06-09T06:13:02.507142Z","shell.execute_reply":"2023-06-09T06:13:02.517813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shuffle the rows:","metadata":{}},{"cell_type":"code","source":"scatter_extracted = scatter_extracted.sample(frac=1, random_state=42, ignore_index=True)\nscatter_extracted","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:13:10.370148Z","iopub.execute_input":"2023-06-09T06:13:10.370575Z","iopub.status.idle":"2023-06-09T06:13:10.389932Z","shell.execute_reply.started":"2023-06-09T06:13:10.370536Z","shell.execute_reply":"2023-06-09T06:13:10.388872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extracted_in_val = scatter_extracted.iloc[:80]\nval_file_names.extend(extracted_in_val['img_file_name'].tolist())\nlen(val_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:13:20.423811Z","iopub.execute_input":"2023-06-09T06:13:20.424228Z","iopub.status.idle":"2023-06-09T06:13:20.432040Z","shell.execute_reply.started":"2023-06-09T06:13:20.424190Z","shell.execute_reply":"2023-06-09T06:13:20.430844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extracted_in_train = scatter_extracted.iloc[80:]\ntrain_file_names.extend(extracted_in_train['img_file_name'].tolist())\nlen(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:13:26.733500Z","iopub.execute_input":"2023-06-09T06:13:26.733928Z","iopub.status.idle":"2023-06-09T06:13:26.741878Z","shell.execute_reply.started":"2023-06-09T06:13:26.733890Z","shell.execute_reply":"2023-06-09T06:13:26.740515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scatter_generated = scatter_df.loc[scatter_df['source'] == 'generated']\nlen(scatter_generated)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:13:31.342090Z","iopub.execute_input":"2023-06-09T06:13:31.342524Z","iopub.status.idle":"2023-06-09T06:13:31.357498Z","shell.execute_reply.started":"2023-06-09T06:13:31.342484Z","shell.execute_reply":"2023-06-09T06:13:31.353227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shuffle the rows:","metadata":{}},{"cell_type":"code","source":"scatter_generated = scatter_generated.sample(frac=1, random_state=42, ignore_index=True)\nscatter_generated","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:13:37.108054Z","iopub.execute_input":"2023-06-09T06:13:37.108473Z","iopub.status.idle":"2023-06-09T06:13:37.128310Z","shell.execute_reply.started":"2023-06-09T06:13:37.108433Z","shell.execute_reply":"2023-06-09T06:13:37.127029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"generated_in_train = scatter_generated.iloc[:239]\ntrain_file_names.extend(generated_in_train['img_file_name'].tolist())\nlen(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:13:40.777938Z","iopub.execute_input":"2023-06-09T06:13:40.778365Z","iopub.status.idle":"2023-06-09T06:13:40.785948Z","shell.execute_reply.started":"2023-06-09T06:13:40.778325Z","shell.execute_reply":"2023-06-09T06:13:40.784604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for file_path in extra_images_path.glob(\"*.jpg\"):\n    file_name = str(file_path).split(\"/\")[-1]\n    train_file_names.append(file_name)\nlen(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:10.854100Z","iopub.execute_input":"2023-06-09T06:14:10.854558Z","iopub.status.idle":"2023-06-09T06:14:10.866814Z","shell.execute_reply.started":"2023-06-09T06:14:10.854515Z","shell.execute_reply":"2023-06-09T06:14:10.865510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"val_file_names = [f_n[:-4] for f_n in val_file_names]\nrandom.seed(42)\nrandom.shuffle(val_file_names)\nval_file_names[:5]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:19.610305Z","iopub.execute_input":"2023-06-09T06:14:19.610715Z","iopub.status.idle":"2023-06-09T06:14:19.618961Z","shell.execute_reply.started":"2023-06-09T06:14:19.610681Z","shell.execute_reply":"2023-06-09T06:14:19.617801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_file_names = [f_n[:-4] for f_n in train_file_names]\nrandom.seed(42)\nrandom.shuffle(train_file_names)\ntrain_file_names[:5]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:25.345030Z","iopub.execute_input":"2023-06-09T06:14:25.345453Z","iopub.status.idle":"2023-06-09T06:14:25.354518Z","shell.execute_reply.started":"2023-06-09T06:14:25.345414Z","shell.execute_reply":"2023-06-09T06:14:25.353077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_splitter = FixedSplitter([train_file_names, val_file_names])","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:29.709900Z","iopub.execute_input":"2023-06-09T06:14:29.710327Z","iopub.status.idle":"2023-06-09T06:14:29.715625Z","shell.execute_reply.started":"2023-06-09T06:14:29.710285Z","shell.execute_reply":"2023-06-09T06:14:29.714223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create the parser:\nparser = parsers.VOCBBoxParser(images_dir=all_images_path, annotations_dir=all_VOC_XML_path)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:32.395858Z","iopub.execute_input":"2023-06-09T06:14:32.396283Z","iopub.status.idle":"2023-06-09T06:14:32.623966Z","shell.execute_reply.started":"2023-06-09T06:14:32.396229Z","shell.execute_reply":"2023-06-09T06:14:32.622846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Parse annotations to create records:\ntrain_records, val_records = parser.parse(data_splitter, autofix=True)\ntype(train_records), type(val_records)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:35.302852Z","iopub.execute_input":"2023-06-09T06:14:35.303255Z","iopub.status.idle":"2023-06-09T06:14:52.857879Z","shell.execute_reply.started":"2023-06-09T06:14:35.303215Z","shell.execute_reply":"2023-06-09T06:14:52.856973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"parser.class_map","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:55.299692Z","iopub.execute_input":"2023-06-09T06:14:55.300179Z","iopub.status.idle":"2023-06-09T06:14:55.307151Z","shell.execute_reply.started":"2023-06-09T06:14:55.300107Z","shell.execute_reply":"2023-06-09T06:14:55.306029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_records), len(val_records)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:14:56.903426Z","iopub.execute_input":"2023-06-09T06:14:56.903840Z","iopub.status.idle":"2023-06-09T06:14:56.911070Z","shell.execute_reply.started":"2023-06-09T06:14:56.903803Z","shell.execute_reply":"2023-06-09T06:14:56.909644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_records[0]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:00.473476Z","iopub.execute_input":"2023-06-09T06:15:00.473888Z","iopub.status.idle":"2023-06-09T06:15:00.481715Z","shell.execute_reply.started":"2023-06-09T06:15:00.473846Z","shell.execute_reply":"2023-06-09T06:15:00.480367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_records[0]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:02.576633Z","iopub.execute_input":"2023-06-09T06:15:02.577046Z","iopub.status.idle":"2023-06-09T06:15:02.584815Z","shell.execute_reply.started":"2023-06-09T06:15:02.577009Z","shell.execute_reply":"2023-06-09T06:15:02.583319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model Training","metadata":{}},{"cell_type":"code","source":"import os\nimport random\nimport numpy as np\nimport torch\n\ndef seed_everything(seed):\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.cuda.manual_seed_all(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n\nseed_everything(42)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:12.017599Z","iopub.execute_input":"2023-06-09T06:15:12.018006Z","iopub.status.idle":"2023-06-09T06:15:12.028322Z","shell.execute_reply.started":"2023-06-09T06:15:12.017967Z","shell.execute_reply":"2023-06-09T06:15:12.027140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"128 * 5","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:13.617361Z","iopub.execute_input":"2023-06-09T06:15:13.617754Z","iopub.status.idle":"2023-06-09T06:15:13.626592Z","shell.execute_reply.started":"2023-06-09T06:15:13.617717Z","shell.execute_reply":"2023-06-09T06:15:13.625180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Transforms:\nimage_size = 640\ntrain_tfms = tfms.A.Adapter([tfms.A.ColorJitter(p=0.5), *tfms.A.resize_and_pad(image_size), tfms.A.Normalize()])\nval_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(image_size), tfms.A.Normalize()])\ntype(train_tfms), type(val_tfms)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:32.502887Z","iopub.execute_input":"2023-06-09T06:15:32.503339Z","iopub.status.idle":"2023-06-09T06:15:32.513833Z","shell.execute_reply.started":"2023-06-09T06:15:32.503302Z","shell.execute_reply":"2023-06-09T06:15:32.512285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_tfms.tfms_list","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:37.710096Z","iopub.execute_input":"2023-06-09T06:15:37.710627Z","iopub.status.idle":"2023-06-09T06:15:37.723563Z","shell.execute_reply.started":"2023-06-09T06:15:37.710576Z","shell.execute_reply":"2023-06-09T06:15:37.722126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_tfms.tfms_list","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:39.810874Z","iopub.execute_input":"2023-06-09T06:15:39.811346Z","iopub.status.idle":"2023-06-09T06:15:39.821669Z","shell.execute_reply.started":"2023-06-09T06:15:39.811300Z","shell.execute_reply":"2023-06-09T06:15:39.820028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# `Dataset` objects:\ntrain_ds = Dataset(train_records, train_tfms)\nval_ds = Dataset(val_records, val_tfms)\ntype(train_ds), type(val_ds)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:44.595523Z","iopub.execute_input":"2023-06-09T06:15:44.595932Z","iopub.status.idle":"2023-06-09T06:15:44.604210Z","shell.execute_reply.started":"2023-06-09T06:15:44.595891Z","shell.execute_reply":"2023-06-09T06:15:44.602824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Show a few elements of `train_ds` with transformations applied:\nsamples = [train_ds[i] for i in range(4)]\nshow_samples(samples, display_label=False, ncols=2)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:15:49.499449Z","iopub.execute_input":"2023-06-09T06:15:49.499867Z","iopub.status.idle":"2023-06-09T06:15:52.856724Z","shell.execute_reply.started":"2023-06-09T06:15:49.499831Z","shell.execute_reply":"2023-06-09T06:15:52.855478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Show a few elements of `val_ds` with transformations applied:\nsamples = [val_ds[i] for i in range(4)]\nshow_samples(samples, display_label=False, ncols=2)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:16:02.665246Z","iopub.execute_input":"2023-06-09T06:16:02.665702Z","iopub.status.idle":"2023-06-09T06:16:06.836101Z","shell.execute_reply.started":"2023-06-09T06:16:02.665664Z","shell.execute_reply":"2023-06-09T06:16:06.834573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extra_args = {}\n\nmodel_type = models.torchvision.faster_rcnn\nbackbone = model_type.backbones.resnet50_fpn\n\nmodel_type, backbone, extra_args","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:16:16.118762Z","iopub.execute_input":"2023-06-09T06:16:16.119201Z","iopub.status.idle":"2023-06-09T06:16:16.126772Z","shell.execute_reply.started":"2023-06-09T06:16:16.119155Z","shell.execute_reply":"2023-06-09T06:16:16.125455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Instantiate the model:\nmodel = model_type.model(backbone=backbone(pretrained=True), num_classes=len(parser.class_map), **extra_args)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:16:21.304412Z","iopub.execute_input":"2023-06-09T06:16:21.304817Z","iopub.status.idle":"2023-06-09T06:16:22.700867Z","shell.execute_reply.started":"2023-06-09T06:16:21.304782Z","shell.execute_reply":"2023-06-09T06:16:22.699645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dl = model_type.train_dl(train_ds, batch_size=8, num_workers=2, shuffle=True)\nval_dl = model_type.valid_dl(val_ds, batch_size=8, num_workers=2, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:16:27.640019Z","iopub.execute_input":"2023-06-09T06:16:27.640455Z","iopub.status.idle":"2023-06-09T06:16:27.646941Z","shell.execute_reply.started":"2023-06-09T06:16:27.640414Z","shell.execute_reply":"2023-06-09T06:16:27.645613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_dl), len(val_dl)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:16:31.843769Z","iopub.execute_input":"2023-06-09T06:16:31.844399Z","iopub.status.idle":"2023-06-09T06:16:31.858283Z","shell.execute_reply.started":"2023-06-09T06:16:31.844341Z","shell.execute_reply":"2023-06-09T06:16:31.856911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_type.show_batch(first(train_dl), display_label=False, ncols=2)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:16:35.458091Z","iopub.execute_input":"2023-06-09T06:16:35.458517Z","iopub.status.idle":"2023-06-09T06:16:42.838625Z","shell.execute_reply.started":"2023-06-09T06:16:35.458477Z","shell.execute_reply":"2023-06-09T06:16:42.837411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_type.show_batch(first(val_dl), display_label=False, ncols=2)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:16:58.529040Z","iopub.execute_input":"2023-06-09T06:16:58.529515Z","iopub.status.idle":"2023-06-09T06:17:06.221067Z","shell.execute_reply.started":"2023-06-09T06:16:58.529471Z","shell.execute_reply":"2023-06-09T06:17:06.218492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Accuracy(SimpleConfusionMatrix):\n    def __init__(self):\n        super().__init__()\n    \n    def finalize(self):\n        assert len(self.target_labels) == len(self.predicted_labels)\n        label_ids = list(self.class_map._class2id.values())\n        self.confusion_matrix = sklearn.metrics.confusion_matrix(\n            y_true=self.target_labels,\n            y_pred=self.predicted_labels,\n            labels=label_ids,\n        )\n        accuracy = (self.confusion_matrix[0, 0] + self.confusion_matrix[1, 1]) / self.confusion_matrix.sum()\n        if self.print_summary:\n            print(self.confusion_matrix)\n        self._reset()\n        return {\"accuracy\": accuracy}","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:17:24.772423Z","iopub.execute_input":"2023-06-09T06:17:24.772850Z","iopub.status.idle":"2023-06-09T06:17:24.783685Z","shell.execute_reply.started":"2023-06-09T06:17:24.772811Z","shell.execute_reply":"2023-06-09T06:17:24.782388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class NumErrors(SimpleConfusionMatrix):\n    def __init__(self):\n        super().__init__()\n    \n    def finalize(self):\n        assert len(self.target_labels) == len(self.predicted_labels)\n        label_ids = list(self.class_map._class2id.values())\n        self.confusion_matrix = sklearn.metrics.confusion_matrix(\n            y_true=self.target_labels,\n            y_pred=self.predicted_labels,\n            labels=label_ids,\n        )\n        num_errors = self.confusion_matrix[0, 1] + self.confusion_matrix[1, 0]\n        if self.print_summary:\n            print(self.confusion_matrix)\n        self._reset()\n        return {\"num_errors\": num_errors}","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:17:30.038339Z","iopub.execute_input":"2023-06-09T06:17:30.038886Z","iopub.status.idle":"2023-06-09T06:17:30.046837Z","shell.execute_reply.started":"2023-06-09T06:17:30.038834Z","shell.execute_reply":"2023-06-09T06:17:30.045496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics = [COCOMetric(metric_type=COCOMetricType.bbox), SimpleConfusionMatrix(), Accuracy(), NumErrors()]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:17:34.706019Z","iopub.execute_input":"2023-06-09T06:17:34.706441Z","iopub.status.idle":"2023-06-09T06:17:34.712357Z","shell.execute_reply.started":"2023-06-09T06:17:34.706401Z","shell.execute_reply":"2023-06-09T06:17:34.711057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.callback.tracker import SaveModelCallback\n\ncb = SaveModelCallback(monitor='Accuracy', fname='dot_scatter_', every_epoch=True)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:17:39.586225Z","iopub.execute_input":"2023-06-09T06:17:39.586665Z","iopub.status.idle":"2023-06-09T06:17:39.592908Z","shell.execute_reply.started":"2023-06-09T06:17:39.586611Z","shell.execute_reply":"2023-06-09T06:17:39.591398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = model_type.fastai.learner(dls=[train_dl, val_dl], model=model, metrics=metrics, cbs=[cb])","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:17:47.986592Z","iopub.execute_input":"2023-06-09T06:17:47.987121Z","iopub.status.idle":"2023-06-09T06:17:48.026859Z","shell.execute_reply.started":"2023-06-09T06:17:47.987072Z","shell.execute_reply":"2023-06-09T06:17:48.025590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.lr_find()","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:17:52.534251Z","iopub.execute_input":"2023-06-09T06:17:52.534705Z","iopub.status.idle":"2023-06-09T06:18:35.891298Z","shell.execute_reply.started":"2023-06-09T06:17:52.534667Z","shell.execute_reply":"2023-06-09T06:18:35.889892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fine_tune(10, 2e-3, freeze_epochs=1)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:18:46.017704Z","iopub.execute_input":"2023-06-09T06:18:46.018135Z","iopub.status.idle":"2023-06-09T06:37:15.669876Z","shell.execute_reply.started":"2023-06-09T06:18:46.018095Z","shell.execute_reply":"2023-06-09T06:37:15.668408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.load('dot_scatter__8')","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:53:14.620209Z","iopub.execute_input":"2023-06-09T06:53:14.620704Z","iopub.status.idle":"2023-06-09T06:53:14.811419Z","shell.execute_reply.started":"2023-06-09T06:53:14.620664Z","shell.execute_reply":"2023-06-09T06:53:14.810128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import icevision\n\nicevision.__version__","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:53:19.746697Z","iopub.execute_input":"2023-06-09T06:53:19.747144Z","iopub.status.idle":"2023-06-09T06:53:19.755633Z","shell.execute_reply.started":"2023-06-09T06:53:19.747102Z","shell.execute_reply":"2023-06-09T06:53:19.754222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from icevision.models import *\n\nsave_icevision_checkpoint(\n    model, \n    model_name='torchvision.faster_rcnn', \n    backbone_name='resnet50_fpn',\n    classes=parser.class_map.get_classes(), \n    img_size=image_size, \n    filename=\"faster_rcnn-dot_scatter.pth\", \n    meta={'icevision_version': '0.12.0'}\n)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:53:25.493167Z","iopub.execute_input":"2023-06-09T06:53:25.493699Z","iopub.status.idle":"2023-06-09T06:53:26.445673Z","shell.execute_reply.started":"2023-06-09T06:53:25.493648Z","shell.execute_reply":"2023-06-09T06:53:26.444356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint_and_model = model_from_checkpoint('/kaggle/working/faster_rcnn-dot_scatter.pth')\ntype(checkpoint_and_model)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:53:31.386900Z","iopub.execute_input":"2023-06-09T06:53:31.387430Z","iopub.status.idle":"2023-06-09T06:53:32.437678Z","shell.execute_reply.started":"2023-06-09T06:53:31.387369Z","shell.execute_reply":"2023-06-09T06:53:32.436337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_map = checkpoint_and_model[\"class_map\"]\nimg_size = checkpoint_and_model[\"img_size\"]\nmodel_type = checkpoint_and_model[\"model_type\"]\nbackbone = checkpoint_and_model[\"backbone\"]\nloaded_model = checkpoint_and_model[\"model\"]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:53:36.598744Z","iopub.execute_input":"2023-06-09T06:53:36.599230Z","iopub.status.idle":"2023-06-09T06:53:36.608723Z","shell.execute_reply.started":"2023-06-09T06:53:36.599185Z","shell.execute_reply":"2023-06-09T06:53:36.606924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model Evaluation","metadata":{}},{"cell_type":"code","source":"learn.validate(dl=val_dl)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:53:48.568193Z","iopub.execute_input":"2023-06-09T06:53:48.568722Z","iopub.status.idle":"2023-06-09T06:54:17.880903Z","shell.execute_reply.started":"2023-06-09T06:53:48.568675Z","shell.execute_reply":"2023-06-09T06:54:17.879393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The above list contains `valid_loss`, `COCOMetric`, `SimpleConfusionMatrix`, `Accuracy` and `NumErrors` corresponding to the best epoch.","metadata":{}},{"cell_type":"code","source":"metrics[1].confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:55:17.699131Z","iopub.execute_input":"2023-06-09T06:55:17.699616Z","iopub.status.idle":"2023-06-09T06:55:17.707922Z","shell.execute_reply.started":"2023-06-09T06:55:17.699573Z","shell.execute_reply":"2023-06-09T06:55:17.706561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics[1].plot()","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:55:21.922627Z","iopub.execute_input":"2023-06-09T06:55:21.923120Z","iopub.status.idle":"2023-06-09T06:55:22.343645Z","shell.execute_reply.started":"2023-06-09T06:55:21.923075Z","shell.execute_reply":"2023-06-09T06:55:22.342328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's examine the model's predictions on 25 randomly chosen images from the validation set.","metadata":{}},{"cell_type":"code","source":"val_file_names = [f_n + '.jpg' for f_n in val_file_names]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:55:36.053626Z","iopub.execute_input":"2023-06-09T06:55:36.054155Z","iopub.status.idle":"2023-06-09T06:55:36.064996Z","shell.execute_reply.started":"2023-06-09T06:55:36.054105Z","shell.execute_reply":"2023-06-09T06:55:36.063378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random.seed(42)\nrandom.shuffle(val_file_names)\nprint(val_file_names[:25])","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:55:49.751341Z","iopub.execute_input":"2023-06-09T06:55:49.751844Z","iopub.status.idle":"2023-06-09T06:55:49.762702Z","shell.execute_reply.started":"2023-06-09T06:55:49.751797Z","shell.execute_reply":"2023-06-09T06:55:49.761486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[0])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:56:00.461698Z","iopub.execute_input":"2023-06-09T06:56:00.462190Z","iopub.status.idle":"2023-06-09T06:56:04.767864Z","shell.execute_reply.started":"2023-06-09T06:56:00.462143Z","shell.execute_reply":"2023-06-09T06:56:04.766095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[1])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:56:22.259430Z","iopub.execute_input":"2023-06-09T06:56:22.259865Z","iopub.status.idle":"2023-06-09T06:56:24.325245Z","shell.execute_reply.started":"2023-06-09T06:56:22.259829Z","shell.execute_reply":"2023-06-09T06:56:24.323820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[2])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:56:31.709335Z","iopub.execute_input":"2023-06-09T06:56:31.709859Z","iopub.status.idle":"2023-06-09T06:56:35.217638Z","shell.execute_reply.started":"2023-06-09T06:56:31.709810Z","shell.execute_reply":"2023-06-09T06:56:35.216397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[3])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:56:43.759631Z","iopub.execute_input":"2023-06-09T06:56:43.760034Z","iopub.status.idle":"2023-06-09T06:56:45.846816Z","shell.execute_reply.started":"2023-06-09T06:56:43.759999Z","shell.execute_reply":"2023-06-09T06:56:45.845539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[4])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:56:53.924575Z","iopub.execute_input":"2023-06-09T06:56:53.925080Z","iopub.status.idle":"2023-06-09T06:56:57.391630Z","shell.execute_reply.started":"2023-06-09T06:56:53.925034Z","shell.execute_reply":"2023-06-09T06:56:57.390467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[5])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:57:09.450764Z","iopub.execute_input":"2023-06-09T06:57:09.451367Z","iopub.status.idle":"2023-06-09T06:57:12.778845Z","shell.execute_reply.started":"2023-06-09T06:57:09.451294Z","shell.execute_reply":"2023-06-09T06:57:12.777619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[6])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:57:26.380424Z","iopub.execute_input":"2023-06-09T06:57:26.380907Z","iopub.status.idle":"2023-06-09T06:57:29.979940Z","shell.execute_reply.started":"2023-06-09T06:57:26.380853Z","shell.execute_reply":"2023-06-09T06:57:29.978549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[7])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:57:38.849036Z","iopub.execute_input":"2023-06-09T06:57:38.849575Z","iopub.status.idle":"2023-06-09T06:57:42.418451Z","shell.execute_reply.started":"2023-06-09T06:57:38.849525Z","shell.execute_reply":"2023-06-09T06:57:42.417308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[8])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:57:59.504619Z","iopub.execute_input":"2023-06-09T06:57:59.505049Z","iopub.status.idle":"2023-06-09T06:58:01.762637Z","shell.execute_reply.started":"2023-06-09T06:57:59.505008Z","shell.execute_reply":"2023-06-09T06:58:01.761378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[9])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:58:06.758130Z","iopub.execute_input":"2023-06-09T06:58:06.758690Z","iopub.status.idle":"2023-06-09T06:58:10.771230Z","shell.execute_reply.started":"2023-06-09T06:58:06.758640Z","shell.execute_reply":"2023-06-09T06:58:10.770042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[10])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:58:16.345986Z","iopub.execute_input":"2023-06-09T06:58:16.346409Z","iopub.status.idle":"2023-06-09T06:58:18.418596Z","shell.execute_reply.started":"2023-06-09T06:58:16.346369Z","shell.execute_reply":"2023-06-09T06:58:18.417453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[11])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:58:25.026106Z","iopub.execute_input":"2023-06-09T06:58:25.026639Z","iopub.status.idle":"2023-06-09T06:58:28.404020Z","shell.execute_reply.started":"2023-06-09T06:58:25.026589Z","shell.execute_reply":"2023-06-09T06:58:28.402667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[12])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:58:35.185423Z","iopub.execute_input":"2023-06-09T06:58:35.185821Z","iopub.status.idle":"2023-06-09T06:58:37.337847Z","shell.execute_reply.started":"2023-06-09T06:58:35.185784Z","shell.execute_reply":"2023-06-09T06:58:37.336520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[13])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:58:41.801422Z","iopub.execute_input":"2023-06-09T06:58:41.801920Z","iopub.status.idle":"2023-06-09T06:58:45.300168Z","shell.execute_reply.started":"2023-06-09T06:58:41.801873Z","shell.execute_reply":"2023-06-09T06:58:45.299007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[14])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:58:50.237303Z","iopub.execute_input":"2023-06-09T06:58:50.237723Z","iopub.status.idle":"2023-06-09T06:58:52.360955Z","shell.execute_reply.started":"2023-06-09T06:58:50.237682Z","shell.execute_reply":"2023-06-09T06:58:52.359635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[15])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:59:02.774587Z","iopub.execute_input":"2023-06-09T06:59:02.775125Z","iopub.status.idle":"2023-06-09T06:59:07.834477Z","shell.execute_reply.started":"2023-06-09T06:59:02.775075Z","shell.execute_reply":"2023-06-09T06:59:07.832887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[16])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:59:12.735900Z","iopub.execute_input":"2023-06-09T06:59:12.736426Z","iopub.status.idle":"2023-06-09T06:59:16.117200Z","shell.execute_reply.started":"2023-06-09T06:59:12.736377Z","shell.execute_reply":"2023-06-09T06:59:16.115995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[17])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:59:20.819134Z","iopub.execute_input":"2023-06-09T06:59:20.819700Z","iopub.status.idle":"2023-06-09T06:59:24.143838Z","shell.execute_reply.started":"2023-06-09T06:59:20.819643Z","shell.execute_reply":"2023-06-09T06:59:24.142678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[18])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:59:29.012872Z","iopub.execute_input":"2023-06-09T06:59:29.013402Z","iopub.status.idle":"2023-06-09T06:59:32.305645Z","shell.execute_reply.started":"2023-06-09T06:59:29.013342Z","shell.execute_reply":"2023-06-09T06:59:32.304390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[19])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:59:42.256388Z","iopub.execute_input":"2023-06-09T06:59:42.256785Z","iopub.status.idle":"2023-06-09T06:59:44.413404Z","shell.execute_reply.started":"2023-06-09T06:59:42.256750Z","shell.execute_reply":"2023-06-09T06:59:44.412246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[20])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:59:49.447108Z","iopub.execute_input":"2023-06-09T06:59:49.447533Z","iopub.status.idle":"2023-06-09T06:59:51.721041Z","shell.execute_reply.started":"2023-06-09T06:59:49.447492Z","shell.execute_reply":"2023-06-09T06:59:51.719784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[21])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T06:59:56.259492Z","iopub.execute_input":"2023-06-09T06:59:56.260017Z","iopub.status.idle":"2023-06-09T06:59:59.639711Z","shell.execute_reply.started":"2023-06-09T06:59:56.259967Z","shell.execute_reply":"2023-06-09T06:59:59.638515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[22])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:00:05.250665Z","iopub.execute_input":"2023-06-09T07:00:05.251169Z","iopub.status.idle":"2023-06-09T07:00:09.930281Z","shell.execute_reply.started":"2023-06-09T07:00:05.251122Z","shell.execute_reply":"2023-06-09T07:00:09.928926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[23])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:00:14.608478Z","iopub.execute_input":"2023-06-09T07:00:14.608974Z","iopub.status.idle":"2023-06-09T07:00:18.051771Z","shell.execute_reply.started":"2023-06-09T07:00:14.608928Z","shell.execute_reply":"2023-06-09T07:00:18.050582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/val_file_names[24])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:00:22.476692Z","iopub.execute_input":"2023-06-09T07:00:22.477206Z","iopub.status.idle":"2023-06-09T07:00:25.996936Z","shell.execute_reply.started":"2023-06-09T07:00:22.477158Z","shell.execute_reply":"2023-06-09T07:00:25.995624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I've run the `model_type.interp.plot_top_losses()` method on a separate instance, and gathered the file names of the top loss images. We'll examine the predictions on these images below.","metadata":{}},{"cell_type":"code","source":"top_loss_images = [\n    'c6350443191a.jpg',\n    '366b69368f99.jpg',\n    '536b28ae1a7e.jpg',\n    '9b62dbdded7b.jpg',\n    'ca30ad3528c4.jpg',\n    'c226d88f9d0d.jpg',\n    '00f5404753cf.jpg',\n    '5fd0b2fd2087.jpg', \n    '0ccb2bf2bafd.jpg',\n    'b99a20b437b4.jpg', \n    '6ae113ad2454.jpg', \n    'c7c5aeda29c3.jpg'\n]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:01:34.895123Z","iopub.execute_input":"2023-06-09T07:01:34.895573Z","iopub.status.idle":"2023-06-09T07:01:34.901698Z","shell.execute_reply.started":"2023-06-09T07:01:34.895533Z","shell.execute_reply":"2023-06-09T07:01:34.900318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[0])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:01:38.634176Z","iopub.execute_input":"2023-06-09T07:01:38.634722Z","iopub.status.idle":"2023-06-09T07:01:42.236036Z","shell.execute_reply.started":"2023-06-09T07:01:38.634672Z","shell.execute_reply":"2023-06-09T07:01:42.234895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[1])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:01:48.525307Z","iopub.execute_input":"2023-06-09T07:01:48.525743Z","iopub.status.idle":"2023-06-09T07:01:50.698370Z","shell.execute_reply.started":"2023-06-09T07:01:48.525704Z","shell.execute_reply":"2023-06-09T07:01:50.696242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[2])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:02:04.264525Z","iopub.execute_input":"2023-06-09T07:02:04.265052Z","iopub.status.idle":"2023-06-09T07:02:07.175188Z","shell.execute_reply.started":"2023-06-09T07:02:04.265002Z","shell.execute_reply":"2023-06-09T07:02:07.173654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[3])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:02:12.120627Z","iopub.execute_input":"2023-06-09T07:02:12.121171Z","iopub.status.idle":"2023-06-09T07:02:16.467114Z","shell.execute_reply.started":"2023-06-09T07:02:12.121116Z","shell.execute_reply":"2023-06-09T07:02:16.465833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[4])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:02:24.194302Z","iopub.execute_input":"2023-06-09T07:02:24.194719Z","iopub.status.idle":"2023-06-09T07:02:26.354733Z","shell.execute_reply.started":"2023-06-09T07:02:24.194681Z","shell.execute_reply":"2023-06-09T07:02:26.353581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[5])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:02:44.807022Z","iopub.execute_input":"2023-06-09T07:02:44.807570Z","iopub.status.idle":"2023-06-09T07:02:49.250620Z","shell.execute_reply.started":"2023-06-09T07:02:44.807522Z","shell.execute_reply":"2023-06-09T07:02:49.249412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[6])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:02:57.960372Z","iopub.execute_input":"2023-06-09T07:02:57.960875Z","iopub.status.idle":"2023-06-09T07:03:01.448106Z","shell.execute_reply.started":"2023-06-09T07:02:57.960827Z","shell.execute_reply":"2023-06-09T07:03:01.446655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[7])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:03:24.995477Z","iopub.execute_input":"2023-06-09T07:03:24.995986Z","iopub.status.idle":"2023-06-09T07:03:28.285369Z","shell.execute_reply.started":"2023-06-09T07:03:24.995938Z","shell.execute_reply":"2023-06-09T07:03:28.283857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[8])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:03:38.168922Z","iopub.execute_input":"2023-06-09T07:03:38.169363Z","iopub.status.idle":"2023-06-09T07:03:40.429239Z","shell.execute_reply.started":"2023-06-09T07:03:38.169318Z","shell.execute_reply":"2023-06-09T07:03:40.427923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[9])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:03:47.198592Z","iopub.execute_input":"2023-06-09T07:03:47.199076Z","iopub.status.idle":"2023-06-09T07:03:49.398926Z","shell.execute_reply.started":"2023-06-09T07:03:47.199032Z","shell.execute_reply":"2023-06-09T07:03:49.396380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[10])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:03:58.755460Z","iopub.execute_input":"2023-06-09T07:03:58.755862Z","iopub.status.idle":"2023-06-09T07:04:00.967687Z","shell.execute_reply.started":"2023-06-09T07:03:58.755827Z","shell.execute_reply":"2023-06-09T07:04:00.966443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/top_loss_images[11])\npred_dict = model_type.end2end_detect(img, val_tfms, loaded_model, class_map=class_map, detection_threshold=0.5, display_label=False)\npred_dict['img']","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:04:05.597344Z","iopub.execute_input":"2023-06-09T07:04:05.597756Z","iopub.status.idle":"2023-06-09T07:04:08.071562Z","shell.execute_reply.started":"2023-06-09T07:04:05.597721Z","shell.execute_reply":"2023-06-09T07:04:08.070223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Cleanup:\n!rm -r /kaggle/working/all_dot_scatter_images/\n!rm -r /kaggle/working/all_dot_scatter_VOC_XML_files/\n!rm /kaggle/working/icevision_install.sh","metadata":{"execution":{"iopub.status.busy":"2023-06-09T07:04:24.840100Z","iopub.execute_input":"2023-06-09T07:04:24.840527Z","iopub.status.idle":"2023-06-09T07:04:28.670793Z","shell.execute_reply.started":"2023-06-09T07:04:24.840489Z","shell.execute_reply":"2023-06-09T07:04:28.669193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}