{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":6799,"databundleVersionId":4225553,"sourceType":"competition"}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# ImageNet Object Detection","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os,cv2,keras\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport tensorflow as tf\nimport glob\nimport xml.etree.ElementTree as ET","metadata":{"execution":{"iopub.status.busy":"2023-11-21T21:32:01.628666Z","iopub.execute_input":"2023-11-21T21:32:01.629084Z","iopub.status.idle":"2023-11-21T21:32:15.265286Z","shell.execute_reply.started":"2023-11-21T21:32:01.629052Z","shell.execute_reply":"2023-11-21T21:32:15.2638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Understanding the ImageNet dataset","metadata":{}},{"cell_type":"code","source":"p = '/kaggle/input/imagenet-object-localization-challenge/ILSVRC'\nannotations_train = glob.glob(p+'/Annotations/CLS-LOC/train/**/**')\ndata_train = glob.glob(p+'/Data/CLS-LOC/train/**/**')\n\nannotations_test = glob.glob(p+'/Annotations/CLS-LOC/val/**')\ndata_test = glob.glob(p+'/Data/CLS-LOC/val/**')","metadata":{"execution":{"iopub.status.busy":"2023-11-21T21:32:15.267325Z","iopub.execute_input":"2023-11-21T21:32:15.268239Z","iopub.status.idle":"2023-11-21T21:44:56.189442Z","shell.execute_reply.started":"2023-11-21T21:32:15.268175Z","shell.execute_reply":"2023-11-21T21:44:56.188268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Annotations training size: {len(annotations_train)}\")\nprint(f\"Data training size: {len(data_train)}\")\n\nprint(f\"Validation annotation size: {len(annotations_test)}\")\nprint(f\"Validation data size: {len(data_test)}\")","metadata":{"execution":{"iopub.status.busy":"2023-11-21T21:47:46.530866Z","iopub.execute_input":"2023-11-21T21:47:46.531288Z","iopub.status.idle":"2023-11-21T21:47:46.538448Z","shell.execute_reply.started":"2023-11-21T21:47:46.531255Z","shell.execute_reply":"2023-11-21T21:47:46.537095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Annotations Format","metadata":{}},{"cell_type":"code","source":"import xml.etree.ElementTree as ET\n\n# Path to your XML file\nxml_file_path = annotations_test[0]\n\n# Parse the XML file\ntree = ET.parse(xml_file_path)\nroot = tree.getroot()\n\n# Function to print XML elements and their text content recursively\ndef print_xml_element(element, indent=0):\n    print('  ' * indent + f\"{element.tag}: {element.text}\")\n    for child in element:\n        print_xml_element(child, indent + 1)\n\n# Print the XML content\nprint_xml_element(root)","metadata":{"execution":{"iopub.status.busy":"2023-11-21T21:44:56.20001Z","iopub.execute_input":"2023-11-21T21:44:56.200393Z","iopub.status.idle":"2023-11-21T21:44:56.215513Z","shell.execute_reply.started":"2023-11-21T21:44:56.200361Z","shell.execute_reply":"2023-11-21T21:44:56.214129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Image Analysis","metadata":{}},{"cell_type":"code","source":"image_path = data_test[0]\n\n# Load the image\nimg = mpimg.imread(image_path)\n\n# Display the image using matplotlib\nplt.imshow(img)\nplt.axis('off')  # Turn off axis labels\nplt.show()\n\n# Read the image using OpenCV\nimage = cv2.imread(image_path)\n\n# Get the image shape (height, width, channels)\nimage_shape = image.shape\n\n# Print the image shape\nprint(\"Image Shape (OpenCV):\", image_shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-21T21:44:56.21697Z","iopub.execute_input":"2023-11-21T21:44:56.217826Z","iopub.status.idle":"2023-11-21T21:44:56.535124Z","shell.execute_reply.started":"2023-11-21T21:44:56.217791Z","shell.execute_reply":"2023-11-21T21:44:56.53399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_path = data_test[40]\n\n# Load the image\nimg = mpimg.imread(image_path)\n\n# Display the image using matplotlib\nplt.imshow(img)\nplt.axis('off')  # Turn off axis labels\nplt.show()\n\n# Read the image using OpenCV\nimage = cv2.imread(image_path)\n\n# Get the image shape (height, width, channels)\nimage_shape = image.shape\n\n# Print the image shape\nprint(\"Image Shape (OpenCV):\", image_shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-21T21:48:43.966128Z","iopub.execute_input":"2023-11-21T21:48:43.966682Z","iopub.status.idle":"2023-11-21T21:48:44.284138Z","shell.execute_reply.started":"2023-11-21T21:48:43.966639Z","shell.execute_reply":"2023-11-21T21:48:44.283243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Preprocessing ","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}