{"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-05-16T11:33:31.924650Z","iopub.execute_input":"2023-05-16T11:33:31.925362Z","iopub.status.idle":"2023-05-16T11:33:32.887367Z","shell.execute_reply.started":"2023-05-16T11:33:31.925322Z","shell.execute_reply":"2023-05-16T11:33:32.885715Z"},"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 cuda10 master","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:33:35.911033Z","iopub.execute_input":"2023-05-16T11:33:35.911812Z","iopub.status.idle":"2023-05-16T11:37:36.372390Z","shell.execute_reply.started":"2023-05-16T11:33:35.911743Z","shell.execute_reply":"2023-05-16T11:37:36.371135Z"},"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-05-16T11:38:48.703222Z","iopub.execute_input":"2023-05-16T11:38:48.704421Z","iopub.status.idle":"2023-05-16T11:38:48.714340Z","shell.execute_reply.started":"2023-05-16T11:38:48.704371Z","shell.execute_reply":"2023-05-16T11:38:48.713031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from icevision.all import *","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:39:00.693475Z","iopub.execute_input":"2023-05-16T11:39:00.693900Z","iopub.status.idle":"2023-05-16T11:40:13.097864Z","shell.execute_reply.started":"2023-05-16T11:39:00.693860Z","shell.execute_reply":"2023-05-16T11:40:13.096569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Let's begin!\")","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:40:15.722566Z","iopub.execute_input":"2023-05-16T11:40:15.722992Z","iopub.status.idle":"2023-05-16T11:40:15.729000Z","shell.execute_reply.started":"2023-05-16T11:40:15.722951Z","shell.execute_reply":"2023-05-16T11:40:15.727678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Preparation","metadata":{}},{"cell_type":"code","source":"from pathlib import Path\n\ncompetition_data_path = Path('/kaggle/input/benetech-making-graphs-accessible')\n!ls {competition_data_path}","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:40:17.788704Z","iopub.execute_input":"2023-05-16T11:40:17.789153Z","iopub.status.idle":"2023-05-16T11:40:18.750537Z","shell.execute_reply.started":"2023-05-16T11:40:17.789112Z","shell.execute_reply":"2023-05-16T11:40:18.749134Z"},"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-05-16T11:40:25.633449Z","iopub.execute_input":"2023-05-16T11:40:25.633896Z","iopub.status.idle":"2023-05-16T11:40:26.589894Z","shell.execute_reply.started":"2023-05-16T11:40:25.633855Z","shell.execute_reply":"2023-05-16T11:40:26.588517Z"},"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-05-16T11:40:26.592393Z","iopub.execute_input":"2023-05-16T11:40:26.592862Z","iopub.status.idle":"2023-05-16T11:40:26.598511Z","shell.execute_reply.started":"2023-05-16T11:40:26.592814Z","shell.execute_reply":"2023-05-16T11:40:26.597112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extra_data_path = Path('/kaggle/input/b-m-g-a-extra-data')\n!ls {extra_data_path}","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:40:30.878283Z","iopub.execute_input":"2023-05-16T11:40:30.879382Z","iopub.status.idle":"2023-05-16T11:40:31.864444Z","shell.execute_reply.started":"2023-05-16T11:40:30.879330Z","shell.execute_reply":"2023-05-16T11:40:31.863047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extra_images_path = extra_data_path/'tick_mark_extra_345'/'tick_mark_extra_345'\ncompetition_VOC_XML_path = extra_data_path/'labels_tick_mark_60379_VOC_XML'/'labels_tick_mark_60379_VOC_XML'\nextra_VOC_XML_path = extra_data_path/'labels_tick_mark_extra_345_VOC_XML'/'labels_tick_mark_extra_345_VOC_XML'","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:40:36.643853Z","iopub.execute_input":"2023-05-16T11:40:36.644277Z","iopub.status.idle":"2023-05-16T11:40:36.650867Z","shell.execute_reply.started":"2023-05-16T11:40:36.644240Z","shell.execute_reply":"2023-05-16T11:40:36.648813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's create a single folder in our working directory, and copy all the images into it.","metadata":{}},{"cell_type":"code","source":"working_dir = Path('/kaggle/working/')\nall_images_path = working_dir/'all_images'\nall_images_path.mkdir()","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:40:39.465940Z","iopub.execute_input":"2023-05-16T11:40:39.466463Z","iopub.status.idle":"2023-05-16T11:40:39.472444Z","shell.execute_reply.started":"2023-05-16T11:40:39.466413Z","shell.execute_reply":"2023-05-16T11:40:39.471148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"First, we'll copy the competition images:","metadata":{}},{"cell_type":"code","source":"from tqdm.notebook import tqdm\nimport shutil\n\norigin = str(competition_images_path) + '/'\ntarget = str(all_images_path) + '/'\ni = 0\nfor file_path in tqdm(sorted(competition_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-05-16T11:40:43.564499Z","iopub.execute_input":"2023-05-16T11:40:43.565015Z","iopub.status.idle":"2023-05-16T11:48:11.258260Z","shell.execute_reply.started":"2023-05-16T11:40:43.564968Z","shell.execute_reply":"2023-05-16T11:48:11.256893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Next, we'll copy the extra images:","metadata":{}},{"cell_type":"code","source":"origin = str(extra_images_path) + '/'\ni = 0\nfor file_path in sorted(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-05-16T11:56:37.328703Z","iopub.execute_input":"2023-05-16T11:56:37.329194Z","iopub.status.idle":"2023-05-16T11:56:40.565807Z","shell.execute_reply.started":"2023-05-16T11:56:37.329146Z","shell.execute_reply":"2023-05-16T11:56:40.564533Z"},"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 sorted(all_images_path.glob(\"*.jpg\")):\n    i += 1\nprint(f\"{i} image files found.\")","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:56:40.568094Z","iopub.execute_input":"2023-05-16T11:56:40.568831Z","iopub.status.idle":"2023-05-16T11:56:41.621624Z","shell.execute_reply.started":"2023-05-16T11:56:40.568786Z","shell.execute_reply":"2023-05-16T11:56:41.620293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"60578 + 345","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:56:45.233325Z","iopub.execute_input":"2023-05-16T11:56:45.233748Z","iopub.status.idle":"2023-05-16T11:56:45.242070Z","shell.execute_reply.started":"2023-05-16T11:56:45.233708Z","shell.execute_reply":"2023-05-16T11:56:45.240912Z"},"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 VOC XML files into it.","metadata":{}},{"cell_type":"code","source":"all_VOC_XML_path = working_dir/'all_VOC_XML'\nall_VOC_XML_path.mkdir()","metadata":{"execution":{"iopub.status.busy":"2023-05-16T11:56:49.625797Z","iopub.execute_input":"2023-05-16T11:56:49.626216Z","iopub.status.idle":"2023-05-16T11:56:49.631921Z","shell.execute_reply.started":"2023-05-16T11:56:49.626177Z","shell.execute_reply":"2023-05-16T11:56:49.630603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"First, we'll copy the VOC XML files corresponding to the competition images:","metadata":{}},{"cell_type":"code","source":"origin = str(competition_VOC_XML_path) + '/'\ntarget = str(all_VOC_XML_path) + '/'\ni = 0\nfor file_path in tqdm(sorted(competition_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-05-16T11:56:53.899878Z","iopub.execute_input":"2023-05-16T11:56:53.900287Z","iopub.status.idle":"2023-05-16T12:03:37.184117Z","shell.execute_reply.started":"2023-05-16T11:56:53.900252Z","shell.execute_reply":"2023-05-16T12:03:37.182871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Next, we'll copy the VOC XML files corresponding to the extra images:","metadata":{}},{"cell_type":"code","source":"origin = str(extra_VOC_XML_path) + '/'\ni = 0\nfor file_path in sorted(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-05-16T12:04:00.771027Z","iopub.execute_input":"2023-05-16T12:04:00.771558Z","iopub.status.idle":"2023-05-16T12:04:02.580918Z","shell.execute_reply.started":"2023-05-16T12:04:00.771516Z","shell.execute_reply":"2023-05-16T12:04:02.579429Z"},"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-05-16T12:04:05.490962Z","iopub.execute_input":"2023-05-16T12:04:05.491489Z","iopub.status.idle":"2023-05-16T12:04:07.781137Z","shell.execute_reply.started":"2023-05-16T12:04:05.491434Z","shell.execute_reply":"2023-05-16T12:04:07.780024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"60379 + 345","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:04:11.848323Z","iopub.execute_input":"2023-05-16T12:04:11.848730Z","iopub.status.idle":"2023-05-16T12:04:11.856065Z","shell.execute_reply.started":"2023-05-16T12:04:11.848690Z","shell.execute_reply":"2023-05-16T12:04:11.854738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now, let's create a data frame containing the image file names, sources and chart types.","metadata":{}},{"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-05-16T12:04:22.269244Z","iopub.execute_input":"2023-05-16T12:04:22.269658Z","iopub.status.idle":"2023-05-16T12:10:41.466833Z","shell.execute_reply.started":"2023-05-16T12:04:22.269613Z","shell.execute_reply":"2023-05-16T12:10:41.465625Z"},"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-05-16T12:11:23.658880Z","iopub.execute_input":"2023-05-16T12:11:23.659314Z","iopub.status.idle":"2023-05-16T12:11:23.712052Z","shell.execute_reply.started":"2023-05-16T12:11:23.659275Z","shell.execute_reply":"2023-05-16T12:11:23.710844Z"},"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_tick_mark_16px.csv')\ncorrupt_files_df","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:28.413633Z","iopub.execute_input":"2023-05-16T12:11:28.414065Z","iopub.status.idle":"2023-05-16T12:11:28.437850Z","shell.execute_reply.started":"2023-05-16T12:11:28.414027Z","shell.execute_reply":"2023-05-16T12:11:28.436774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.loc[~ df['img_file_name'].isin(corrupt_files_df['corrupt_file'])]\nlen(df)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:32.111226Z","iopub.execute_input":"2023-05-16T12:11:32.111643Z","iopub.status.idle":"2023-05-16T12:11:32.141015Z","shell.execute_reply.started":"2023-05-16T12:11:32.111597Z","shell.execute_reply":"2023-05-16T12:11:32.139773Z"},"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('/kaggle/input/b-m-g-a-extra-data/Validation_Scheme_Tick_Mark.png')\nval_scheme","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:36.857509Z","iopub.execute_input":"2023-05-16T12:11:36.857945Z","iopub.status.idle":"2023-05-16T12:11:36.959931Z","shell.execute_reply.started":"2023-05-16T12:11:36.857901Z","shell.execute_reply":"2023-05-16T12:11:36.958866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names = []\ntrain_file_names = []","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:40.575134Z","iopub.execute_input":"2023-05-16T12:11:40.575541Z","iopub.status.idle":"2023-05-16T12:11:40.581178Z","shell.execute_reply.started":"2023-05-16T12:11:40.575502Z","shell.execute_reply":"2023-05-16T12:11:40.579960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We'll go chart type by chart type, and add the respective file names to the above lists.","metadata":{}},{"cell_type":"markdown","source":"## 'line'","metadata":{}},{"cell_type":"code","source":"line_extracted = df.loc[(df['source'] == 'extracted') & (df['chart_type'] == 'line')]\nlen(line_extracted)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:44.061567Z","iopub.execute_input":"2023-05-16T12:11:44.062081Z","iopub.status.idle":"2023-05-16T12:11:44.094500Z","shell.execute_reply.started":"2023-05-16T12:11:44.062030Z","shell.execute_reply":"2023-05-16T12:11:44.093471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shuffle the rows:","metadata":{}},{"cell_type":"code","source":"line_extracted = line_extracted.sample(frac=1, random_state=42, ignore_index=True)\nline_extracted","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:47.108316Z","iopub.execute_input":"2023-05-16T12:11:47.108720Z","iopub.status.idle":"2023-05-16T12:11:47.127433Z","shell.execute_reply.started":"2023-05-16T12:11:47.108683Z","shell.execute_reply":"2023-05-16T12:11:47.126134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"line_extracted_in_val = line_extracted.iloc[:223]\nline_extracted_in_train = line_extracted.iloc[223:]\nlen(line_extracted_in_val), len(line_extracted_in_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:50.955260Z","iopub.execute_input":"2023-05-16T12:11:50.955673Z","iopub.status.idle":"2023-05-16T12:11:50.963482Z","shell.execute_reply.started":"2023-05-16T12:11:50.955632Z","shell.execute_reply":"2023-05-16T12:11:50.962301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names.extend(line_extracted_in_val['img_file_name'].tolist())\ntrain_file_names.extend(line_extracted_in_train['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:52.383392Z","iopub.execute_input":"2023-05-16T12:11:52.383823Z","iopub.status.idle":"2023-05-16T12:11:52.394821Z","shell.execute_reply.started":"2023-05-16T12:11:52.383780Z","shell.execute_reply":"2023-05-16T12:11:52.393457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"line_generated = df.loc[(df['source'] == 'generated') & (df['chart_type'] == 'line')]\nlen(line_generated)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:55.481310Z","iopub.execute_input":"2023-05-16T12:11:55.481721Z","iopub.status.idle":"2023-05-16T12:11:55.513911Z","shell.execute_reply.started":"2023-05-16T12:11:55.481682Z","shell.execute_reply":"2023-05-16T12:11:55.512722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shuffle the rows:","metadata":{}},{"cell_type":"code","source":"line_generated = line_generated.sample(frac=1, random_state=42, ignore_index=True)\nline_generated","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:11:58.743639Z","iopub.execute_input":"2023-05-16T12:11:58.744073Z","iopub.status.idle":"2023-05-16T12:11:58.765878Z","shell.execute_reply.started":"2023-05-16T12:11:58.744034Z","shell.execute_reply":"2023-05-16T12:11:58.764836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"line_generated_in_train = line_generated.iloc[:537]\nlen(line_generated_in_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:02.364773Z","iopub.execute_input":"2023-05-16T12:12:02.365200Z","iopub.status.idle":"2023-05-16T12:12:02.372558Z","shell.execute_reply.started":"2023-05-16T12:12:02.365161Z","shell.execute_reply":"2023-05-16T12:12:02.371308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_file_names.extend(line_generated_in_train['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:02.822107Z","iopub.execute_input":"2023-05-16T12:12:02.824474Z","iopub.status.idle":"2023-05-16T12:12:02.844732Z","shell.execute_reply.started":"2023-05-16T12:12:02.824305Z","shell.execute_reply":"2023-05-16T12:12:02.843133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 'vertical_bar'","metadata":{}},{"cell_type":"code","source":"vertical_bar_extracted = df.loc[(df['source'] == 'extracted') & (df['chart_type'] == 'vertical_bar')]\nlen(vertical_bar_extracted)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:10.169203Z","iopub.execute_input":"2023-05-16T12:12:10.169613Z","iopub.status.idle":"2023-05-16T12:12:10.198613Z","shell.execute_reply.started":"2023-05-16T12:12:10.169568Z","shell.execute_reply":"2023-05-16T12:12:10.197121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shuffle the rows:","metadata":{}},{"cell_type":"code","source":"vertical_bar_extracted = vertical_bar_extracted.sample(frac=1, random_state=42, ignore_index=True)\nvertical_bar_extracted","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:11.734896Z","iopub.execute_input":"2023-05-16T12:12:11.735306Z","iopub.status.idle":"2023-05-16T12:12:11.750781Z","shell.execute_reply.started":"2023-05-16T12:12:11.735268Z","shell.execute_reply":"2023-05-16T12:12:11.749540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vertical_bar_extracted_in_val = vertical_bar_extracted.iloc[:257]\nvertical_bar_extracted_in_train = vertical_bar_extracted.iloc[257:]\nlen(vertical_bar_extracted_in_val), len(vertical_bar_extracted_in_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:15.036225Z","iopub.execute_input":"2023-05-16T12:12:15.036721Z","iopub.status.idle":"2023-05-16T12:12:15.046927Z","shell.execute_reply.started":"2023-05-16T12:12:15.036674Z","shell.execute_reply":"2023-05-16T12:12:15.045742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names.extend(vertical_bar_extracted_in_val['img_file_name'].tolist())\ntrain_file_names.extend(vertical_bar_extracted_in_train['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:15.639924Z","iopub.execute_input":"2023-05-16T12:12:15.640431Z","iopub.status.idle":"2023-05-16T12:12:15.651176Z","shell.execute_reply.started":"2023-05-16T12:12:15.640385Z","shell.execute_reply":"2023-05-16T12:12:15.650045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vertical_bar_generated = df.loc[(df['source'] == 'generated') & (df['chart_type'] == 'vertical_bar')]\nlen(vertical_bar_generated)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:16.979448Z","iopub.execute_input":"2023-05-16T12:12:16.979999Z","iopub.status.idle":"2023-05-16T12:12:17.027822Z","shell.execute_reply.started":"2023-05-16T12:12:16.979947Z","shell.execute_reply":"2023-05-16T12:12:17.026692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shuffle the rows:","metadata":{}},{"cell_type":"code","source":"vertical_bar_generated = vertical_bar_generated.sample(frac=1, random_state=42, ignore_index=True)\nvertical_bar_generated","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:21.190550Z","iopub.execute_input":"2023-05-16T12:12:21.191094Z","iopub.status.idle":"2023-05-16T12:12:21.222179Z","shell.execute_reply.started":"2023-05-16T12:12:21.191044Z","shell.execute_reply":"2023-05-16T12:12:21.221071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vertical_bar_generated_in_train = vertical_bar_generated.iloc[:437]\nlen(vertical_bar_generated_in_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:21.699377Z","iopub.execute_input":"2023-05-16T12:12:21.699937Z","iopub.status.idle":"2023-05-16T12:12:21.712856Z","shell.execute_reply.started":"2023-05-16T12:12:21.699883Z","shell.execute_reply":"2023-05-16T12:12:21.711712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_file_names.extend(vertical_bar_generated_in_train['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:25.365538Z","iopub.execute_input":"2023-05-16T12:12:25.366091Z","iopub.status.idle":"2023-05-16T12:12:25.379996Z","shell.execute_reply.started":"2023-05-16T12:12:25.366040Z","shell.execute_reply":"2023-05-16T12:12:25.378712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 'scatter'","metadata":{}},{"cell_type":"code","source":"scatter_extracted = df.loc[(df['source'] == 'extracted') & (df['chart_type'] == 'scatter')]\nlen(scatter_extracted)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:35.329019Z","iopub.execute_input":"2023-05-16T12:12:35.329422Z","iopub.status.idle":"2023-05-16T12:12:35.358214Z","shell.execute_reply.started":"2023-05-16T12:12:35.329385Z","shell.execute_reply":"2023-05-16T12:12:35.356916Z"},"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-05-16T12:12:38.476313Z","iopub.execute_input":"2023-05-16T12:12:38.476724Z","iopub.status.idle":"2023-05-16T12:12:38.493090Z","shell.execute_reply.started":"2023-05-16T12:12:38.476684Z","shell.execute_reply":"2023-05-16T12:12:38.491862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scatter_extracted_in_val = scatter_extracted.iloc[:115]\nscatter_extracted_in_train = scatter_extracted.iloc[115:]\nlen(scatter_extracted_in_val), len(scatter_extracted_in_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:41.890523Z","iopub.execute_input":"2023-05-16T12:12:41.890981Z","iopub.status.idle":"2023-05-16T12:12:41.899064Z","shell.execute_reply.started":"2023-05-16T12:12:41.890938Z","shell.execute_reply":"2023-05-16T12:12:41.897848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names.extend(scatter_extracted_in_val['img_file_name'].tolist())\ntrain_file_names.extend(scatter_extracted_in_train['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:42.295173Z","iopub.execute_input":"2023-05-16T12:12:42.295531Z","iopub.status.idle":"2023-05-16T12:12:42.303568Z","shell.execute_reply.started":"2023-05-16T12:12:42.295497Z","shell.execute_reply":"2023-05-16T12:12:42.302464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scatter_generated = df.loc[(df['source'] == 'generated') & (df['chart_type'] == 'scatter')]\nlen(scatter_generated)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:42.844151Z","iopub.execute_input":"2023-05-16T12:12:42.844514Z","iopub.status.idle":"2023-05-16T12:12:42.874916Z","shell.execute_reply.started":"2023-05-16T12:12:42.844479Z","shell.execute_reply":"2023-05-16T12:12:42.873703Z"},"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-05-16T12:12:46.475811Z","iopub.execute_input":"2023-05-16T12:12:46.476221Z","iopub.status.idle":"2023-05-16T12:12:46.494963Z","shell.execute_reply.started":"2023-05-16T12:12:46.476184Z","shell.execute_reply":"2023-05-16T12:12:46.493500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scatter_generated_in_train = scatter_generated.iloc[:282]\nlen(scatter_generated_in_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:49.825932Z","iopub.execute_input":"2023-05-16T12:12:49.826435Z","iopub.status.idle":"2023-05-16T12:12:49.834255Z","shell.execute_reply.started":"2023-05-16T12:12:49.826386Z","shell.execute_reply":"2023-05-16T12:12:49.833121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_file_names.extend(scatter_generated_in_train['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:50.272408Z","iopub.execute_input":"2023-05-16T12:12:50.272842Z","iopub.status.idle":"2023-05-16T12:12:50.281789Z","shell.execute_reply.started":"2023-05-16T12:12:50.272797Z","shell.execute_reply":"2023-05-16T12:12:50.280455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 'dot'","metadata":{}},{"cell_type":"code","source":"dot = df.loc[df['chart_type'] == 'dot']\nlen(dot)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:54.204442Z","iopub.execute_input":"2023-05-16T12:12:54.204911Z","iopub.status.idle":"2023-05-16T12:12:54.225305Z","shell.execute_reply.started":"2023-05-16T12:12:54.204865Z","shell.execute_reply":"2023-05-16T12:12:54.224000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shuffle the rows:","metadata":{}},{"cell_type":"code","source":"dot = dot.sample(frac=1, random_state=42, ignore_index=True)\ndot","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:55.852301Z","iopub.execute_input":"2023-05-16T12:12:55.852749Z","iopub.status.idle":"2023-05-16T12:12:55.870448Z","shell.execute_reply.started":"2023-05-16T12:12:55.852705Z","shell.execute_reply":"2023-05-16T12:12:55.869159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dot_in_val = dot.iloc[:337]\ndot_in_train = dot.iloc[337:657]\nlen(dot_in_val), len(dot_in_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:12:58.400530Z","iopub.execute_input":"2023-05-16T12:12:58.401078Z","iopub.status.idle":"2023-05-16T12:12:58.410265Z","shell.execute_reply.started":"2023-05-16T12:12:58.401009Z","shell.execute_reply":"2023-05-16T12:12:58.408898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names.extend(dot_in_val['img_file_name'].tolist())\ntrain_file_names.extend(dot_in_train['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:13:01.544515Z","iopub.execute_input":"2023-05-16T12:13:01.544961Z","iopub.status.idle":"2023-05-16T12:13:01.553144Z","shell.execute_reply.started":"2023-05-16T12:13:01.544920Z","shell.execute_reply":"2023-05-16T12:13:01.551911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 'horizontal_bar'","metadata":{}},{"cell_type":"code","source":"horizontal_bar = df.loc[df['chart_type'] == 'horizontal_bar']\nlen(horizontal_bar)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:13:04.282188Z","iopub.execute_input":"2023-05-16T12:13:04.282601Z","iopub.status.idle":"2023-05-16T12:13:04.300265Z","shell.execute_reply.started":"2023-05-16T12:13:04.282563Z","shell.execute_reply":"2023-05-16T12:13:04.298672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_file_names.extend(horizontal_bar['img_file_name'].tolist())\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:13:06.949682Z","iopub.execute_input":"2023-05-16T12:13:06.950239Z","iopub.status.idle":"2023-05-16T12:13:06.958005Z","shell.execute_reply.started":"2023-05-16T12:13:06.950197Z","shell.execute_reply":"2023-05-16T12:13:06.956871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"extras = [str(i) + '_.jpg' for i in range(345)]\ntrain_file_names.extend(extras)\nlen(val_file_names), len(train_file_names)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:13:07.411351Z","iopub.execute_input":"2023-05-16T12:13:07.411725Z","iopub.status.idle":"2023-05-16T12:13:07.419618Z","shell.execute_reply.started":"2023-05-16T12:13:07.411686Z","shell.execute_reply":"2023-05-16T12:13:07.418155Z"},"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]\nval_file_names[:5]","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:13:10.626025Z","iopub.execute_input":"2023-05-16T12:13:10.626439Z","iopub.status.idle":"2023-05-16T12:13:10.634005Z","shell.execute_reply.started":"2023-05-16T12:13:10.626402Z","shell.execute_reply":"2023-05-16T12:13:10.632869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_file_names = [f_n[:-4] for f_n in train_file_names]\ntrain_file_names[:5]","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:13:11.077073Z","iopub.execute_input":"2023-05-16T12:13:11.077473Z","iopub.status.idle":"2023-05-16T12:13:11.086097Z","shell.execute_reply.started":"2023-05-16T12:13:11.077436Z","shell.execute_reply":"2023-05-16T12:13:11.084827Z"},"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-05-16T12:13:14.654652Z","iopub.execute_input":"2023-05-16T12:13:14.655091Z","iopub.status.idle":"2023-05-16T12:13:14.659899Z","shell.execute_reply.started":"2023-05-16T12:13:14.655051Z","shell.execute_reply":"2023-05-16T12:13:14.658624Z"},"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-05-16T12:13:15.713501Z","iopub.execute_input":"2023-05-16T12:13:15.713939Z","iopub.status.idle":"2023-05-16T12:13:17.227967Z","shell.execute_reply.started":"2023-05-16T12:13:15.713899Z","shell.execute_reply":"2023-05-16T12:13:17.226819Z"},"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-05-16T12:13:19.898246Z","iopub.execute_input":"2023-05-16T12:13:19.898977Z","iopub.status.idle":"2023-05-16T12:14:44.501862Z","shell.execute_reply.started":"2023-05-16T12:13:19.898892Z","shell.execute_reply":"2023-05-16T12:14:44.500891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"parser.class_map","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:21:57.184824Z","iopub.execute_input":"2023-05-16T12:21:57.185282Z","iopub.status.idle":"2023-05-16T12:21:57.193905Z","shell.execute_reply.started":"2023-05-16T12:21:57.185243Z","shell.execute_reply":"2023-05-16T12:21:57.192714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_records), len(val_records)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:21:59.281856Z","iopub.execute_input":"2023-05-16T12:21:59.282258Z","iopub.status.idle":"2023-05-16T12:21:59.289055Z","shell.execute_reply.started":"2023-05-16T12:21:59.282222Z","shell.execute_reply":"2023-05-16T12:21:59.287948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_records[0]","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:22:01.908515Z","iopub.execute_input":"2023-05-16T12:22:01.908955Z","iopub.status.idle":"2023-05-16T12:22:01.916663Z","shell.execute_reply.started":"2023-05-16T12:22:01.908915Z","shell.execute_reply":"2023-05-16T12:22:01.915462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_records[0]","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:22:04.073780Z","iopub.execute_input":"2023-05-16T12:22:04.074209Z","iopub.status.idle":"2023-05-16T12:22:04.082213Z","shell.execute_reply.started":"2023-05-16T12:22:04.074171Z","shell.execute_reply":"2023-05-16T12:22:04.080812Z"},"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-05-16T12:22:08.347885Z","iopub.execute_input":"2023-05-16T12:22:08.348316Z","iopub.status.idle":"2023-05-16T12:22:08.357799Z","shell.execute_reply.started":"2023-05-16T12:22:08.348276Z","shell.execute_reply":"2023-05-16T12:22:08.356502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"128 * 5","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:22:11.479190Z","iopub.execute_input":"2023-05-16T12:22:11.479607Z","iopub.status.idle":"2023-05-16T12:22:11.486488Z","shell.execute_reply.started":"2023-05-16T12:22:11.479561Z","shell.execute_reply":"2023-05-16T12:22:11.485341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Transforms:\nimage_size = 640\ntrain_tfms = tfms.A.Adapter([tfms.A.OneOf([tfms.A.CLAHE(p=0.25), tfms.A.RGBShift(p=0.25), tfms.A.MultiplicativeNoise(p=0.25), tfms.A.ColorJitter(p=0.25)], p=0.75), *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-05-16T12:22:11.895558Z","iopub.execute_input":"2023-05-16T12:22:11.895979Z","iopub.status.idle":"2023-05-16T12:22:11.906484Z","shell.execute_reply.started":"2023-05-16T12:22:11.895938Z","shell.execute_reply":"2023-05-16T12:22:11.905390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_tfms.tfms_list","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:22:14.089662Z","iopub.execute_input":"2023-05-16T12:22:14.090105Z","iopub.status.idle":"2023-05-16T12:22:14.097656Z","shell.execute_reply.started":"2023-05-16T12:22:14.090066Z","shell.execute_reply":"2023-05-16T12:22:14.096401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_tfms.tfms_list","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:22:16.216535Z","iopub.execute_input":"2023-05-16T12:22:16.216954Z","iopub.status.idle":"2023-05-16T12:22:16.224403Z","shell.execute_reply.started":"2023-05-16T12:22:16.216914Z","shell.execute_reply":"2023-05-16T12:22:16.223175Z"},"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-05-16T12:22:16.664239Z","iopub.execute_input":"2023-05-16T12:22:16.664683Z","iopub.status.idle":"2023-05-16T12:22:16.672482Z","shell.execute_reply.started":"2023-05-16T12:22:16.664644Z","shell.execute_reply":"2023-05-16T12:22:16.671230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Show a few elements of `train_ds` with augmentations & 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-05-16T12:22:18.979724Z","iopub.execute_input":"2023-05-16T12:22:18.980163Z","iopub.status.idle":"2023-05-16T12:22:22.790363Z","shell.execute_reply.started":"2023-05-16T12:22:18.980120Z","shell.execute_reply":"2023-05-16T12:22:22.785994Z"},"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-05-16T12:22:22.792119Z","iopub.execute_input":"2023-05-16T12:22:22.792791Z","iopub.status.idle":"2023-05-16T12:22:26.001708Z","shell.execute_reply.started":"2023-05-16T12:22:22.792733Z","shell.execute_reply":"2023-05-16T12:22:26.000688Z"},"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-05-16T12:24:36.642150Z","iopub.execute_input":"2023-05-16T12:24:36.642597Z","iopub.status.idle":"2023-05-16T12:24:36.651149Z","shell.execute_reply.started":"2023-05-16T12:24:36.642557Z","shell.execute_reply":"2023-05-16T12:24:36.649866Z"},"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-05-16T12:24:46.415905Z","iopub.execute_input":"2023-05-16T12:24:46.416436Z","iopub.status.idle":"2023-05-16T12:24:48.492195Z","shell.execute_reply.started":"2023-05-16T12:24:46.416386Z","shell.execute_reply":"2023-05-16T12:24:48.490890Z"},"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-05-16T12:24:49.913402Z","iopub.execute_input":"2023-05-16T12:24:49.913932Z","iopub.status.idle":"2023-05-16T12:24:49.923171Z","shell.execute_reply.started":"2023-05-16T12:24:49.913879Z","shell.execute_reply":"2023-05-16T12:24:49.921716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_dl), len(val_dl)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:24:50.797872Z","iopub.execute_input":"2023-05-16T12:24:50.798382Z","iopub.status.idle":"2023-05-16T12:24:50.811777Z","shell.execute_reply.started":"2023-05-16T12:24:50.798335Z","shell.execute_reply":"2023-05-16T12:24:50.809772Z"},"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-05-16T12:24:54.471006Z","iopub.execute_input":"2023-05-16T12:24:54.471506Z","iopub.status.idle":"2023-05-16T12:25:06.343119Z","shell.execute_reply.started":"2023-05-16T12:24:54.471460Z","shell.execute_reply":"2023-05-16T12:25:06.341887Z"},"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-05-16T12:25:17.045366Z","iopub.execute_input":"2023-05-16T12:25:17.045907Z","iopub.status.idle":"2023-05-16T12:25:26.778103Z","shell.execute_reply.started":"2023-05-16T12:25:17.045857Z","shell.execute_reply":"2023-05-16T12:25:26.776884Z"},"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-05-16T12:25:37.528569Z","iopub.execute_input":"2023-05-16T12:25:37.529119Z","iopub.status.idle":"2023-05-16T12:25:37.544440Z","shell.execute_reply.started":"2023-05-16T12:25:37.529069Z","shell.execute_reply":"2023-05-16T12:25:37.543294Z"},"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-05-16T12:25:38.506529Z","iopub.execute_input":"2023-05-16T12:25:38.507517Z","iopub.status.idle":"2023-05-16T12:25:38.521806Z","shell.execute_reply.started":"2023-05-16T12:25:38.507464Z","shell.execute_reply":"2023-05-16T12:25:38.520545Z"},"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-05-16T12:25:44.280669Z","iopub.execute_input":"2023-05-16T12:25:44.281203Z","iopub.status.idle":"2023-05-16T12:25:44.291166Z","shell.execute_reply.started":"2023-05-16T12:25:44.281155Z","shell.execute_reply":"2023-05-16T12:25:44.289958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.callback.tracker import SaveModelCallback\n\ncb = SaveModelCallback(monitor='Accuracy', fname='tick_mark', every_epoch=True)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:25:48.997100Z","iopub.execute_input":"2023-05-16T12:25:48.997675Z","iopub.status.idle":"2023-05-16T12:25:49.004295Z","shell.execute_reply.started":"2023-05-16T12:25:48.997625Z","shell.execute_reply":"2023-05-16T12:25:49.002963Z"},"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-05-16T12:25:52.371087Z","iopub.execute_input":"2023-05-16T12:25:52.371576Z","iopub.status.idle":"2023-05-16T12:25:52.413951Z","shell.execute_reply.started":"2023-05-16T12:25:52.371532Z","shell.execute_reply":"2023-05-16T12:25:52.412857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.lr_find()","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:25:55.416916Z","iopub.execute_input":"2023-05-16T12:25:55.417428Z","iopub.status.idle":"2023-05-16T12:26:46.734457Z","shell.execute_reply.started":"2023-05-16T12:25:55.417381Z","shell.execute_reply":"2023-05-16T12:26:46.733078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fine_tune(10, 3e-3, freeze_epochs=1)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T12:26:52.714485Z","iopub.execute_input":"2023-05-16T12:26:52.715037Z","iopub.status.idle":"2023-05-16T13:37:12.314189Z","shell.execute_reply.started":"2023-05-16T12:26:52.714988Z","shell.execute_reply":"2023-05-16T13:37:12.311826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.load('tick_mark_5')","metadata":{"execution":{"iopub.status.busy":"2023-05-16T13:37:18.567119Z","iopub.execute_input":"2023-05-16T13:37:18.567540Z","iopub.status.idle":"2023-05-16T13:37:18.758191Z","shell.execute_reply.started":"2023-05-16T13:37:18.567503Z","shell.execute_reply":"2023-05-16T13:37:18.756867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import icevision\n\nicevision.__version__","metadata":{"execution":{"iopub.status.busy":"2023-05-16T13:37:23.058961Z","iopub.execute_input":"2023-05-16T13:37:23.059368Z","iopub.status.idle":"2023-05-16T13:37:23.066818Z","shell.execute_reply.started":"2023-05-16T13:37:23.059333Z","shell.execute_reply":"2023-05-16T13:37:23.065612Z"},"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-tick_mark.pth\", \n    meta={'icevision_version': '0.12.0'}\n)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T13:37:31.734925Z","iopub.execute_input":"2023-05-16T13:37:31.735455Z","iopub.status.idle":"2023-05-16T13:37:32.411453Z","shell.execute_reply.started":"2023-05-16T13:37:31.735403Z","shell.execute_reply":"2023-05-16T13:37:32.410102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint_and_model = model_from_checkpoint('/kaggle/working/faster_rcnn-tick_mark.pth')\ntype(checkpoint_and_model)","metadata":{"execution":{"iopub.status.busy":"2023-05-16T13:37:36.407798Z","iopub.execute_input":"2023-05-16T13:37:36.408316Z","iopub.status.idle":"2023-05-16T13:37:37.868671Z","shell.execute_reply.started":"2023-05-16T13:37:36.408270Z","shell.execute_reply":"2023-05-16T13:37:37.859366Z"},"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-05-16T13:37:43.224892Z","iopub.execute_input":"2023-05-16T13:37:43.225432Z","iopub.status.idle":"2023-05-16T13:37:43.235033Z","shell.execute_reply.started":"2023-05-16T13:37:43.225381Z","shell.execute_reply":"2023-05-16T13:37:43.232858Z"},"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-05-16T13:37:47.180265Z","iopub.execute_input":"2023-05-16T13:37:47.180814Z","iopub.status.idle":"2023-05-16T13:39:46.932738Z","shell.execute_reply.started":"2023-05-16T13:37:47.180739Z","shell.execute_reply":"2023-05-16T13:39:46.931576Z"},"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-05-16T13:40:03.428321Z","iopub.execute_input":"2023-05-16T13:40:03.428845Z","iopub.status.idle":"2023-05-16T13:40:03.440292Z","shell.execute_reply.started":"2023-05-16T13:40:03.428794Z","shell.execute_reply":"2023-05-16T13:40:03.438981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics[1].plot()","metadata":{"execution":{"iopub.status.busy":"2023-05-16T13:40:07.097369Z","iopub.execute_input":"2023-05-16T13:40:07.097894Z","iopub.status.idle":"2023-05-16T13:40:07.608200Z","shell.execute_reply.started":"2023-05-16T13:40:07.097841Z","shell.execute_reply":"2023-05-16T13:40:07.606580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's examine the model's predictions on 8 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-05-16T13:40:21.845197Z","iopub.execute_input":"2023-05-16T13:40:21.845638Z","iopub.status.idle":"2023-05-16T13:40:21.851379Z","shell.execute_reply.started":"2023-05-16T13:40:21.845597Z","shell.execute_reply":"2023-05-16T13:40:21.850057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random.seed(21)\nrandom.shuffle(val_file_names)\nval_file_names[:8]","metadata":{"execution":{"iopub.status.busy":"2023-05-16T13:40:25.756749Z","iopub.execute_input":"2023-05-16T13:40:25.757232Z","iopub.status.idle":"2023-05-16T13:40:25.767870Z","shell.execute_reply.started":"2023-05-16T13:40:25.757189Z","shell.execute_reply":"2023-05-16T13:40:25.766573Z"},"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-05-16T13:40:47.141522Z","iopub.execute_input":"2023-05-16T13:40:47.141963Z","iopub.status.idle":"2023-05-16T13:40:50.126967Z","shell.execute_reply.started":"2023-05-16T13:40:47.141926Z","shell.execute_reply":"2023-05-16T13:40:50.125771Z"},"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-05-16T13:41:11.130374Z","iopub.execute_input":"2023-05-16T13:41:11.130811Z","iopub.status.idle":"2023-05-16T13:41:13.893347Z","shell.execute_reply.started":"2023-05-16T13:41:11.130749Z","shell.execute_reply":"2023-05-16T13:41:13.892033Z"},"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-05-16T13:41:31.746887Z","iopub.execute_input":"2023-05-16T13:41:31.747302Z","iopub.status.idle":"2023-05-16T13:41:34.036855Z","shell.execute_reply.started":"2023-05-16T13:41:31.747264Z","shell.execute_reply":"2023-05-16T13:41:34.035694Z"},"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-05-16T13:41:51.270674Z","iopub.execute_input":"2023-05-16T13:41:51.271112Z","iopub.status.idle":"2023-05-16T13:41:54.448234Z","shell.execute_reply.started":"2023-05-16T13:41:51.271073Z","shell.execute_reply":"2023-05-16T13:41:54.446947Z"},"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-05-16T13:42:17.733112Z","iopub.execute_input":"2023-05-16T13:42:17.733514Z","iopub.status.idle":"2023-05-16T13:42:20.648596Z","shell.execute_reply.started":"2023-05-16T13:42:17.733477Z","shell.execute_reply":"2023-05-16T13:42:20.647154Z"},"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-05-16T13:42:49.011024Z","iopub.execute_input":"2023-05-16T13:42:49.011452Z","iopub.status.idle":"2023-05-16T13:42:52.385436Z","shell.execute_reply.started":"2023-05-16T13:42:49.011413Z","shell.execute_reply":"2023-05-16T13:42:52.383977Z"},"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-05-16T13:43:11.032365Z","iopub.execute_input":"2023-05-16T13:43:11.032810Z","iopub.status.idle":"2023-05-16T13:43:13.238534Z","shell.execute_reply.started":"2023-05-16T13:43:11.032746Z","shell.execute_reply":"2023-05-16T13:43:13.237198Z"},"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-05-16T13:43:30.431823Z","iopub.execute_input":"2023-05-16T13:43:30.432236Z","iopub.status.idle":"2023-05-16T13:43:32.797967Z","shell.execute_reply.started":"2023-05-16T13:43:30.432200Z","shell.execute_reply":"2023-05-16T13:43:32.796828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Finally, let's take a look at some of the top loss images.\n\n**Note:** The `model_type.interp.plot_top_losses()` method is exhausting the 13GB of RAM provided by Kaggle. Hence, I've run it 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":"img = Image.open(all_images_path/'359088265664.jpg')\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-05-16T13:43:55.562720Z","iopub.execute_input":"2023-05-16T13:43:55.563153Z","iopub.status.idle":"2023-05-16T13:43:58.433956Z","shell.execute_reply.started":"2023-05-16T13:43:55.563117Z","shell.execute_reply":"2023-05-16T13:43:58.432743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'9092699b6681.jpg')\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-05-16T13:44:14.123732Z","iopub.execute_input":"2023-05-16T13:44:14.124159Z","iopub.status.idle":"2023-05-16T13:44:17.112034Z","shell.execute_reply.started":"2023-05-16T13:44:14.124119Z","shell.execute_reply":"2023-05-16T13:44:17.110750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'b840c79e40e0.jpg')\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-05-16T13:44:38.156417Z","iopub.execute_input":"2023-05-16T13:44:38.156987Z","iopub.status.idle":"2023-05-16T13:44:41.163315Z","shell.execute_reply.started":"2023-05-16T13:44:38.156932Z","shell.execute_reply":"2023-05-16T13:44:41.162046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'0e46c988beac.jpg')\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-05-16T13:45:12.594121Z","iopub.execute_input":"2023-05-16T13:45:12.594548Z","iopub.status.idle":"2023-05-16T13:45:14.724935Z","shell.execute_reply.started":"2023-05-16T13:45:12.594508Z","shell.execute_reply":"2023-05-16T13:45:14.723746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'e832d98c37b2.jpg')\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-05-16T13:45:33.495015Z","iopub.execute_input":"2023-05-16T13:45:33.495525Z","iopub.status.idle":"2023-05-16T13:45:36.456205Z","shell.execute_reply.started":"2023-05-16T13:45:33.495476Z","shell.execute_reply":"2023-05-16T13:45:36.454985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'90c504a8b320.jpg')\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-05-16T13:45:52.341613Z","iopub.execute_input":"2023-05-16T13:45:52.342145Z","iopub.status.idle":"2023-05-16T13:45:54.638907Z","shell.execute_reply.started":"2023-05-16T13:45:52.342087Z","shell.execute_reply":"2023-05-16T13:45:54.637413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'53360355b73c.jpg')\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-05-16T13:46:16.415785Z","iopub.execute_input":"2023-05-16T13:46:16.416204Z","iopub.status.idle":"2023-05-16T13:46:18.654945Z","shell.execute_reply.started":"2023-05-16T13:46:16.416166Z","shell.execute_reply":"2023-05-16T13:46:18.653764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'64374ed8c87a.jpg')\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-05-16T13:46:42.208566Z","iopub.execute_input":"2023-05-16T13:46:42.209026Z","iopub.status.idle":"2023-05-16T13:46:44.402371Z","shell.execute_reply.started":"2023-05-16T13:46:42.208984Z","shell.execute_reply":"2023-05-16T13:46:44.401129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'8f678bd731ba.jpg')\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-05-16T13:47:01.297819Z","iopub.execute_input":"2023-05-16T13:47:01.298262Z","iopub.status.idle":"2023-05-16T13:47:03.529450Z","shell.execute_reply.started":"2023-05-16T13:47:01.298223Z","shell.execute_reply":"2023-05-16T13:47:03.528161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Image.open(all_images_path/'ed4a7c1f1267.jpg')\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-05-16T13:47:26.171287Z","iopub.execute_input":"2023-05-16T13:47:26.171702Z","iopub.status.idle":"2023-05-16T13:47:28.480743Z","shell.execute_reply.started":"2023-05-16T13:47:26.171665Z","shell.execute_reply":"2023-05-16T13:47:28.479508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Cleanup:\n!rm -r /kaggle/working/all_images/\n!rm -r /kaggle/working/all_VOC_XML/\n!rm /kaggle/working/icevision_install.sh","metadata":{"execution":{"iopub.status.busy":"2023-05-16T13:48:58.554251Z","iopub.execute_input":"2023-05-16T13:48:58.554704Z","iopub.status.idle":"2023-05-16T13:49:05.072774Z","shell.execute_reply.started":"2023-05-16T13:48:58.554664Z","shell.execute_reply":"2023-05-16T13:49:05.071119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}