{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":23870,"databundleVersionId":1781260,"sourceType":"competition"},{"sourceId":23812,"sourceType":"datasetVersion","datasetId":17810},{"sourceId":1991969,"sourceType":"datasetVersion","datasetId":1191154},{"sourceId":2169393,"sourceType":"datasetVersion","datasetId":1302315},{"sourceId":4302261,"sourceType":"datasetVersion","datasetId":2534553},{"sourceId":182990523,"sourceType":"kernelVersion"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport os\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:39:05.411302Z","iopub.execute_input":"2024-06-16T12:39:05.411953Z","iopub.status.idle":"2024-06-16T12:39:05.724767Z","shell.execute_reply.started":"2024-06-16T12:39:05.411924Z","shell.execute_reply":"2024-06-16T12:39:05.723995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nimport os\n\nsource = '/kaggle/input/cyc2cyc-rerun/checkpoints/train'\ndestination = '/kaggle/working/prev_input'\n\nshutil.copytree(source, destination)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:35:22.049328Z","iopub.execute_input":"2024-06-16T12:35:22.049702Z","iopub.status.idle":"2024-06-16T12:37:01.130025Z","shell.execute_reply.started":"2024-06-16T12:35:22.049673Z","shell.execute_reply":"2024-06-16T12:37:01.129169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"CLEAN IMAGES","metadata":{}},{"cell_type":"code","source":"directory = '/kaggle/input/chest-xray-pneumonia/chest_xray/train/NORMAL/'\n\nimage_paths = [os.path.join(directory, file) for file in os.listdir(directory) if file.lower().endswith(('png', 'jpg', 'jpeg', 'gif', 'bmp'))]\n\nmore_clean = pd.DataFrame(image_paths, columns=['image_name'])\n\nmore_clean.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.151322Z","iopub.execute_input":"2024-06-16T10:08:32.151778Z","iopub.status.idle":"2024-06-16T10:08:32.40396Z","shell.execute_reply.started":"2024-06-16T10:08:32.151746Z","shell.execute_reply":"2024-06-16T10:08:32.402879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"more_clean.iloc[0]","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.405415Z","iopub.execute_input":"2024-06-16T10:08:32.40581Z","iopub.status.idle":"2024-06-16T10:08:32.414344Z","shell.execute_reply.started":"2024-06-16T10:08:32.405773Z","shell.execute_reply":"2024-06-16T10:08:32.413329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_objects = pd.read_csv(\"/kaggle/input/foreign-objects-in-chest-xrays/object-CXR/train.csv\")\nclean_objects.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.417073Z","iopub.execute_input":"2024-06-16T10:08:32.417401Z","iopub.status.idle":"2024-06-16T10:08:32.481826Z","shell.execute_reply.started":"2024-06-16T10:08:32.417375Z","shell.execute_reply":"2024-06-16T10:08:32.480765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_objects = clean_objects[clean_objects['annotation'].isnull()]\nclean_objects.drop(['annotation'],inplace=True,axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.483462Z","iopub.execute_input":"2024-06-16T10:08:32.484448Z","iopub.status.idle":"2024-06-16T10:08:32.496444Z","shell.execute_reply.started":"2024-06-16T10:08:32.484391Z","shell.execute_reply":"2024-06-16T10:08:32.495492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_objects.reset_index(inplace=True,drop=True)\nclean_objects.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.497677Z","iopub.execute_input":"2024-06-16T10:08:32.498015Z","iopub.status.idle":"2024-06-16T10:08:32.508534Z","shell.execute_reply.started":"2024-06-16T10:08:32.497951Z","shell.execute_reply":"2024-06-16T10:08:32.507254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_objects['image_name'] = '/kaggle/input/foreign-objects-in-chest-xrays/object-CXR/train/' + clean_objects['image_name']","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.510166Z","iopub.execute_input":"2024-06-16T10:08:32.510505Z","iopub.status.idle":"2024-06-16T10:08:32.517603Z","shell.execute_reply.started":"2024-06-16T10:08:32.510475Z","shell.execute_reply":"2024-06-16T10:08:32.516599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_objects.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.519035Z","iopub.execute_input":"2024-06-16T10:08:32.519388Z","iopub.status.idle":"2024-06-16T10:08:32.533472Z","shell.execute_reply.started":"2024-06-16T10:08:32.519325Z","shell.execute_reply":"2024-06-16T10:08:32.532352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_combined = pd.concat([clean_objects, more_clean], ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.5348Z","iopub.execute_input":"2024-06-16T10:08:32.535182Z","iopub.status.idle":"2024-06-16T10:08:32.543521Z","shell.execute_reply.started":"2024-06-16T10:08:32.535152Z","shell.execute_reply":"2024-06-16T10:08:32.542404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_combined.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.54805Z","iopub.execute_input":"2024-06-16T10:08:32.548412Z","iopub.status.idle":"2024-06-16T10:08:32.555876Z","shell.execute_reply.started":"2024-06-16T10:08:32.548381Z","shell.execute_reply":"2024-06-16T10:08:32.554841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_combined.tail(5)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.557154Z","iopub.execute_input":"2024-06-16T10:08:32.557451Z","iopub.status.idle":"2024-06-16T10:08:32.569549Z","shell.execute_reply.started":"2024-06-16T10:08:32.557423Z","shell.execute_reply":"2024-06-16T10:08:32.568476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_combined.to_csv('/kaggle/working/clean_objects.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.571192Z","iopub.execute_input":"2024-06-16T10:08:32.571535Z","iopub.status.idle":"2024-06-16T10:08:32.606951Z","shell.execute_reply.started":"2024-06-16T10:08:32.571496Z","shell.execute_reply":"2024-06-16T10:08:32.6058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"OBJECTS IMAGES","metadata":{}},{"cell_type":"code","source":"objects2 = pd.read_csv(\"/kaggle/input/foreign-objects-in-chest-xrays/object-CXR/train.csv\")\nobjects2.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.608262Z","iopub.execute_input":"2024-06-16T10:08:32.608575Z","iopub.status.idle":"2024-06-16T10:08:32.650329Z","shell.execute_reply.started":"2024-06-16T10:08:32.608545Z","shell.execute_reply":"2024-06-16T10:08:32.649034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects2.dropna(inplace=True)\nobjects2.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.652302Z","iopub.execute_input":"2024-06-16T10:08:32.65284Z","iopub.status.idle":"2024-06-16T10:08:32.671246Z","shell.execute_reply.started":"2024-06-16T10:08:32.652796Z","shell.execute_reply":"2024-06-16T10:08:32.670046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects2.drop(['annotation'],inplace=True,axis=1)\nobjects2.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.673197Z","iopub.execute_input":"2024-06-16T10:08:32.673629Z","iopub.status.idle":"2024-06-16T10:08:32.687193Z","shell.execute_reply.started":"2024-06-16T10:08:32.673589Z","shell.execute_reply":"2024-06-16T10:08:32.685565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects2['image_name'] = '/kaggle/input/foreign-objects-in-chest-xrays/object-CXR/train/' + objects2['image_name']","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.688614Z","iopub.execute_input":"2024-06-16T10:08:32.689788Z","iopub.status.idle":"2024-06-16T10:08:32.697871Z","shell.execute_reply.started":"2024-06-16T10:08:32.689744Z","shell.execute_reply":"2024-06-16T10:08:32.696558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects2.rename(columns={'image_name': 'Path'}, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.699705Z","iopub.execute_input":"2024-06-16T10:08:32.700533Z","iopub.status.idle":"2024-06-16T10:08:32.708191Z","shell.execute_reply.started":"2024-06-16T10:08:32.70049Z","shell.execute_reply":"2024-06-16T10:08:32.706904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects2.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.710119Z","iopub.execute_input":"2024-06-16T10:08:32.710502Z","iopub.status.idle":"2024-06-16T10:08:32.723221Z","shell.execute_reply.started":"2024-06-16T10:08:32.710468Z","shell.execute_reply":"2024-06-16T10:08:32.721812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"directory = '/kaggle/input/support-devices/Support_devices/Chexpert_Support_devices_subset/new_data/'\n\nimage_paths = [os.path.join(directory, file) for file in os.listdir(directory) if file.lower().endswith(('png', 'jpg', 'jpeg', 'gif', 'bmp'))]\n\nmore_objects = pd.DataFrame(image_paths, columns=['Path'])\n\nmore_objects.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.724889Z","iopub.execute_input":"2024-06-16T10:08:32.725308Z","iopub.status.idle":"2024-06-16T10:08:32.911115Z","shell.execute_reply.started":"2024-06-16T10:08:32.725279Z","shell.execute_reply":"2024-06-16T10:08:32.910072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects = pd.read_csv('/kaggle/input/chexpert/train.csv')\nobjects.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:32.912448Z","iopub.execute_input":"2024-06-16T10:08:32.912748Z","iopub.status.idle":"2024-06-16T10:08:33.804369Z","shell.execute_reply.started":"2024-06-16T10:08:32.912722Z","shell.execute_reply":"2024-06-16T10:08:33.803302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects = objects[(objects['Frontal/Lateral']=='Frontal') & (objects['Support Devices']==1.0)]\nobjects.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:33.805757Z","iopub.execute_input":"2024-06-16T10:08:33.806142Z","iopub.status.idle":"2024-06-16T10:08:33.893809Z","shell.execute_reply.started":"2024-06-16T10:08:33.806111Z","shell.execute_reply":"2024-06-16T10:08:33.892617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects.drop(columns=list(objects.iloc[:,1:].columns),inplace=True,axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:33.895293Z","iopub.execute_input":"2024-06-16T10:08:33.895668Z","iopub.status.idle":"2024-06-16T10:08:33.912174Z","shell.execute_reply.started":"2024-06-16T10:08:33.895635Z","shell.execute_reply":"2024-06-16T10:08:33.910815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects.reset_index(inplace=True,drop=True)\nobjects","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:33.913641Z","iopub.execute_input":"2024-06-16T10:08:33.91403Z","iopub.status.idle":"2024-06-16T10:08:33.926498Z","shell.execute_reply.started":"2024-06-16T10:08:33.913963Z","shell.execute_reply":"2024-06-16T10:08:33.925215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects['Path'] = objects['Path'].str.replace('CheXpert-v1.0-small', '/kaggle/input/chexpert')","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:33.927904Z","iopub.execute_input":"2024-06-16T10:08:33.928954Z","iopub.status.idle":"2024-06-16T10:08:34.01681Z","shell.execute_reply.started":"2024-06-16T10:08:33.928921Z","shell.execute_reply":"2024-06-16T10:08:34.015733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:34.018293Z","iopub.execute_input":"2024-06-16T10:08:34.018607Z","iopub.status.idle":"2024-06-16T10:08:34.029195Z","shell.execute_reply.started":"2024-06-16T10:08:34.01858Z","shell.execute_reply":"2024-06-16T10:08:34.027932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects_combined = pd.concat([more_objects, objects], ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:34.03063Z","iopub.execute_input":"2024-06-16T10:08:34.03096Z","iopub.status.idle":"2024-06-16T10:08:34.038416Z","shell.execute_reply.started":"2024-06-16T10:08:34.030933Z","shell.execute_reply":"2024-06-16T10:08:34.037475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects_combined = pd.concat([objects2, objects_combined], ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:34.039575Z","iopub.execute_input":"2024-06-16T10:08:34.039954Z","iopub.status.idle":"2024-06-16T10:08:34.050695Z","shell.execute_reply.started":"2024-06-16T10:08:34.039923Z","shell.execute_reply":"2024-06-16T10:08:34.049676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects_combined.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:34.056881Z","iopub.execute_input":"2024-06-16T10:08:34.057377Z","iopub.status.idle":"2024-06-16T10:08:34.06739Z","shell.execute_reply.started":"2024-06-16T10:08:34.057334Z","shell.execute_reply":"2024-06-16T10:08:34.06624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects_combined.to_csv('/kaggle/working/objects.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:08:34.06873Z","iopub.execute_input":"2024-06-16T10:08:34.069138Z","iopub.status.idle":"2024-06-16T10:08:34.488472Z","shell.execute_reply.started":"2024-06-16T10:08:34.069107Z","shell.execute_reply":"2024-06-16T10:08:34.487241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -q git+https://github.com/tensorflow/examples.git","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:09.738838Z","iopub.execute_input":"2024-06-16T12:40:09.739209Z","iopub.status.idle":"2024-06-16T12:40:34.572771Z","shell.execute_reply.started":"2024-06-16T12:40:09.739167Z","shell.execute_reply":"2024-06-16T12:40:34.571795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nimport tensorflow_datasets as tfds\nfrom tensorflow_examples.models.pix2pix import pix2pix as p2p\n\nimport time\nimport matplotlib.pyplot as plt\nfrom IPython.display import clear_output\n\nAUTOTUNE = tf.data.AUTOTUNE","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:34.574717Z","iopub.execute_input":"2024-06-16T12:40:34.57502Z","iopub.status.idle":"2024-06-16T12:40:34.612498Z","shell.execute_reply.started":"2024-06-16T12:40:34.57499Z","shell.execute_reply":"2024-06-16T12:40:34.611664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(objects_combined.shape)\nprint(clean_combined.shape)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:15.866469Z","iopub.execute_input":"2024-06-16T10:09:15.867095Z","iopub.status.idle":"2024-06-16T10:09:15.872677Z","shell.execute_reply.started":"2024-06-16T10:09:15.867062Z","shell.execute_reply":"2024-06-16T10:09:15.87158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects_head = objects_combined.head(6000)\nclean_objects_head = clean_combined.head(5341)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:15.874065Z","iopub.execute_input":"2024-06-16T10:09:15.874428Z","iopub.status.idle":"2024-06-16T10:09:15.913514Z","shell.execute_reply.started":"2024-06-16T10:09:15.874394Z","shell.execute_reply":"2024-06-16T10:09:15.912427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"objects_head['Path'][1]","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:15.915023Z","iopub.execute_input":"2024-06-16T10:09:15.915859Z","iopub.status.idle":"2024-06-16T10:09:15.925515Z","shell.execute_reply.started":"2024-06-16T10:09:15.915825Z","shell.execute_reply":"2024-06-16T10:09:15.924428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_objects_head['image_name'][1]","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:15.927052Z","iopub.execute_input":"2024-06-16T10:09:15.927741Z","iopub.status.idle":"2024-06-16T10:09:15.934921Z","shell.execute_reply.started":"2024-06-16T10:09:15.927703Z","shell.execute_reply":"2024-06-16T10:09:15.933931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\ndef get_image_info(image_path):\n    \"\"\"\n    Returns the type of image (color or grayscale), the number of channels, and the size (width and height).\n    Args:\n        image_path (str): Path to the image file.\n    Returns:\n        tuple: A tuple containing the image type (str), the number of channels (int), the width (int), and the height (int).\n    \"\"\"\n    # Load the image using OpenCV\n    image = cv2.imread(image_path)\n    # Get the number of channels\n    num_channels = image.shape[2] if len(image.shape) > 2 else 1\n    # Determine the image type based on the number of channels\n    if num_channels == 3:\n        image_type = \"Color\"\n    elif num_channels == 1:\n        image_type = \"Grayscale\"\n    else:\n        image_type = f\"Unknown ({num_channels} channels)\"\n    # Get the image size (width and height)\n    height, width = image.shape[:2]\n    return image_type, num_channels, width, height\n \n# Example usage\nimage_path = clean_objects_head['image_name'][5]\nimage_type, num_channels, width, height = get_image_info(image_path)\nprint(f\"Image Type: {image_type}\")\nprint(f\"Number of Channels: {num_channels}\")\nprint(f\"Width: {width} pixels\")\nprint(f\"Height: {height} pixels\")","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:15.936119Z","iopub.execute_input":"2024-06-16T10:09:15.936432Z","iopub.status.idle":"2024-06-16T10:09:16.033376Z","shell.execute_reply.started":"2024-06-16T10:09:15.936398Z","shell.execute_reply":"2024-06-16T10:09:16.032343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_path = objects_head['Path'][5]\nimage_type, num_channels, width, height = get_image_info(image_path)\nprint(f\"Image Type: {image_type}\")\nprint(f\"Number of Channels: {num_channels}\")\nprint(f\"Width: {width} pixels\")\nprint(f\"Height: {height} pixels\")","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.034649Z","iopub.execute_input":"2024-06-16T10:09:16.034956Z","iopub.status.idle":"2024-06-16T10:09:16.094437Z","shell.execute_reply.started":"2024-06-16T10:09:16.034929Z","shell.execute_reply":"2024-06-16T10:09:16.093341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"object_domain = list(objects_head['Path'])\nlen(object_domain)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.09617Z","iopub.execute_input":"2024-06-16T10:09:16.096753Z","iopub.status.idle":"2024-06-16T10:09:16.104925Z","shell.execute_reply.started":"2024-06-16T10:09:16.096714Z","shell.execute_reply":"2024-06-16T10:09:16.103863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clean_object_domain = list(clean_objects_head['image_name'])\nlen(clean_object_domain)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.106368Z","iopub.execute_input":"2024-06-16T10:09:16.106723Z","iopub.status.idle":"2024-06-16T10:09:16.117432Z","shell.execute_reply.started":"2024-06-16T10:09:16.106695Z","shell.execute_reply":"2024-06-16T10:09:16.116519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(object_domain[0:5])\nprint('------------')\nprint(clean_object_domain[0:5])","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.118781Z","iopub.execute_input":"2024-06-16T10:09:16.119207Z","iopub.status.idle":"2024-06-16T10:09:16.127234Z","shell.execute_reply.started":"2024-06-16T10:09:16.119156Z","shell.execute_reply":"2024-06-16T10:09:16.12606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Set the image dimensions\nimg_height = 256\nimg_width = 256\n\n# Define the buffer size and batch size\nbuffer_size = 1000\nbatch_size = 1","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.128607Z","iopub.execute_input":"2024-06-16T10:09:16.128952Z","iopub.status.idle":"2024-06-16T10:09:16.136213Z","shell.execute_reply.started":"2024-06-16T10:09:16.128923Z","shell.execute_reply":"2024-06-16T10:09:16.135331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n# Split the lists into training and test sets\nrandom.seed(42)  # Set a seed for reproducibility\nrandom.shuffle(object_domain)\nrandom.shuffle(clean_object_domain)\n\ntrain_size = int(0.8 * len(object_domain))  # Use 80% for training","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.141823Z","iopub.execute_input":"2024-06-16T10:09:16.142272Z","iopub.status.idle":"2024-06-16T10:09:16.160116Z","shell.execute_reply.started":"2024-06-16T10:09:16.142243Z","shell.execute_reply":"2024-06-16T10:09:16.159209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_size","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.161483Z","iopub.execute_input":"2024-06-16T10:09:16.161894Z","iopub.status.idle":"2024-06-16T10:09:16.174959Z","shell.execute_reply.started":"2024-06-16T10:09:16.161839Z","shell.execute_reply":"2024-06-16T10:09:16.173906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"object_domain_train_images = object_domain[:train_size]\nobject_domain_test_images = object_domain[train_size:]\n\nclean_object_domain_train_images = clean_object_domain[:train_size]\nclean_object_domain_test_images = clean_object_domain[train_size:]\n","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.176157Z","iopub.execute_input":"2024-06-16T10:09:16.17653Z","iopub.status.idle":"2024-06-16T10:09:16.184199Z","shell.execute_reply.started":"2024-06-16T10:09:16.176501Z","shell.execute_reply":"2024-06-16T10:09:16.183279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"object_domain_train_images[0:5]","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.185552Z","iopub.execute_input":"2024-06-16T10:09:16.186204Z","iopub.status.idle":"2024-06-16T10:09:16.195353Z","shell.execute_reply.started":"2024-06-16T10:09:16.186165Z","shell.execute_reply":"2024-06-16T10:09:16.194314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# A = OBJECTS !\n# B = NO OBJECTS !\n\n# Create training datasets\ntrain_dataset_object = tf.data.Dataset.from_tensor_slices(object_domain_train_images)\ntrain_dataset_clean_object = tf.data.Dataset.from_tensor_slices(clean_object_domain_train_images)\n\n# Create test datasets\ntest_dataset_object = tf.data.Dataset.from_tensor_slices(object_domain_test_images)\ntest_dataset_clean_object = tf.data.Dataset.from_tensor_slices(clean_object_domain_test_images)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.196683Z","iopub.execute_input":"2024-06-16T10:09:16.197094Z","iopub.status.idle":"2024-06-16T10:09:16.920402Z","shell.execute_reply.started":"2024-06-16T10:09:16.197062Z","shell.execute_reply":"2024-06-16T10:09:16.919479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset_object","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.921593Z","iopub.execute_input":"2024-06-16T10:09:16.92194Z","iopub.status.idle":"2024-06-16T10:09:16.929254Z","shell.execute_reply.started":"2024-06-16T10:09:16.921912Z","shell.execute_reply":"2024-06-16T10:09:16.928044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_image(image_path):\n    image = tf.io.read_file(image_path)\n    image = tf.image.decode_jpeg(image, channels=3)\n    image = tf.image.resize(image, [img_height, img_width])\n    image = tf.cast(image, tf.float32) / 127.5 - 1.0 \n    return image\n \ndef random_crop(image):\n    cropped_image = tf.image.random_crop(image, size=[img_height, img_width, 3])\n    return cropped_image\n \ndef random_jitter(image):\n    image = tf.image.resize(image, [286, 286], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)\n \n    image = random_crop(image)\n \n    image = tf.image.random_flip_left_right(image)\n \n    return image\n \ndef preprocess_image_train(image_path):\n    image = load_image(image_path)\n    image = random_jitter(image)\n    return image\n \ndef preprocess_image_test(image_path):\n    image = load_image(image_path)\n    return image\n \ntrain_dataset_object = train_dataset_object.map(preprocess_image_train, num_parallel_calls=tf.data.experimental.AUTOTUNE)\ntrain_dataset_clean_object = train_dataset_clean_object.map(preprocess_image_train, num_parallel_calls=tf.data.experimental.AUTOTUNE)\ntest_dataset_object = test_dataset_object.map(preprocess_image_test, num_parallel_calls=tf.data.experimental.AUTOTUNE)\ntest_dataset_clean_object = test_dataset_clean_object.map(preprocess_image_test, num_parallel_calls=tf.data.experimental.AUTOTUNE)\n \ntrain_dataset_object = train_dataset_object.cache().shuffle(buffer_size).batch(batch_size)\ntrain_dataset_clean_object = train_dataset_clean_object.cache().shuffle(buffer_size).batch(batch_size)\ntest_dataset_object = test_dataset_object.cache().batch(batch_size)\ntest_dataset_clean_object = test_dataset_clean_object.cache().batch(batch_size)\n ","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:16.930824Z","iopub.execute_input":"2024-06-16T10:09:16.931523Z","iopub.status.idle":"2024-06-16T10:09:17.340044Z","shell.execute_reply.started":"2024-06-16T10:09:16.931483Z","shell.execute_reply":"2024-06-16T10:09:17.339132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_object = next(iter(train_dataset_object))\nsample_no_object = next(iter(train_dataset_clean_object))","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:17.341497Z","iopub.execute_input":"2024-06-16T10:09:17.34238Z","iopub.status.idle":"2024-06-16T10:09:54.920178Z","shell.execute_reply.started":"2024-06-16T10:09:17.342338Z","shell.execute_reply":"2024-06-16T10:09:54.919049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.subplot(121)\nplt.title('Object CXR')\nplt.imshow(sample_object[0] * 0.5 + 0.5)\n\nplt.subplot(122)\nplt.title('Object CXR with random jitter')\nplt.imshow(random_jitter(sample_object[0]) * 0.5 + 0.5)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:54.921624Z","iopub.execute_input":"2024-06-16T10:09:54.921959Z","iopub.status.idle":"2024-06-16T10:09:55.672826Z","shell.execute_reply.started":"2024-06-16T10:09:54.921931Z","shell.execute_reply":"2024-06-16T10:09:55.671638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.subplot(121)\nplt.title('No Object CXR')\nplt.imshow(sample_no_object[0] * 0.5 + 0.5)\n\nplt.subplot(122)\nplt.title('No Object CXR with random jitter')\nplt.imshow(random_jitter(sample_no_object[0]) * 0.5 + 0.5)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:55.674074Z","iopub.execute_input":"2024-06-16T10:09:55.674407Z","iopub.status.idle":"2024-06-16T10:09:56.264174Z","shell.execute_reply.started":"2024-06-16T10:09:55.674376Z","shell.execute_reply":"2024-06-16T10:09:56.263003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"NEW MODEL!","metadata":{"execution":{"iopub.status.busy":"2024-06-15T13:16:27.67212Z","iopub.execute_input":"2024-06-15T13:16:27.672644Z","iopub.status.idle":"2024-06-15T13:16:27.681148Z","shell.execute_reply.started":"2024-06-15T13:16:27.672606Z","shell.execute_reply":"2024-06-15T13:16:27.679811Z"}}},{"cell_type":"code","source":"# HERE IF WRITTEN","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:09:56.265545Z","iopub.execute_input":"2024-06-16T10:09:56.265899Z","iopub.status.idle":"2024-06-16T10:09:56.271309Z","shell.execute_reply.started":"2024-06-16T10:09:56.265868Z","shell.execute_reply":"2024-06-16T10:09:56.269963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"OUTPUT_CHANNELS = 3\n\ngenerator_g = p2p.unet_generator(OUTPUT_CHANNELS)\ngenerator_f = p2p.unet_generator(OUTPUT_CHANNELS)\n\ndiscriminator_x = p2p.discriminator(norm_type='instancenorm', target=False)\ndiscriminator_y = p2p.discriminator(norm_type='instancenorm', target=False)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:42.208101Z","iopub.execute_input":"2024-06-16T12:40:42.208959Z","iopub.status.idle":"2024-06-16T12:40:43.519038Z","shell.execute_reply.started":"2024-06-16T12:40:42.208926Z","shell.execute_reply":"2024-06-16T12:40:43.518221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"to_no_object = generator_g(sample_object)\nto_object = generator_f(sample_no_object)\nplt.figure(figsize=(8, 8))\ncontrast = 8\n\nimgs = [sample_object, to_no_object, sample_no_object, to_object]\ntitle = ['Object', 'To No_Object', 'No_Object', 'To Object']\n\nfor i in range(len(imgs)):\n  plt.subplot(2, 2, i+1)\n  plt.title(title[i])\n  if i % 2 == 0:\n    plt.imshow(imgs[i][0] * 0.5 + 0.5)\n  else:\n    plt.imshow(imgs[i][0] * 0.5 * contrast + 0.5)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:10:15.103407Z","iopub.execute_input":"2024-06-16T10:10:15.1042Z","iopub.status.idle":"2024-06-16T10:10:18.320482Z","shell.execute_reply.started":"2024-06-16T10:10:15.104163Z","shell.execute_reply":"2024-06-16T10:10:18.319434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 8))\n\nplt.subplot(121)\nplt.title('Is a real no object?')\nplt.imshow(discriminator_y(sample_no_object)[0, ..., -1], cmap='RdBu_r')\n\nplt.subplot(122)\nplt.title('Is a real object?')\nplt.imshow(discriminator_x(sample_object)[0, ..., -1], cmap='RdBu_r')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:10:18.322212Z","iopub.execute_input":"2024-06-16T10:10:18.322539Z","iopub.status.idle":"2024-06-16T10:10:19.575012Z","shell.execute_reply.started":"2024-06-16T10:10:18.322512Z","shell.execute_reply":"2024-06-16T10:10:19.573908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Loss function**","metadata":{}},{"cell_type":"code","source":"LAMBDA = 10","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:50.640076Z","iopub.execute_input":"2024-06-16T12:40:50.641044Z","iopub.status.idle":"2024-06-16T12:40:50.644828Z","shell.execute_reply.started":"2024-06-16T12:40:50.641012Z","shell.execute_reply":"2024-06-16T12:40:50.643982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss_obj = tf.keras.losses.BinaryCrossentropy(from_logits=True)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:50.888312Z","iopub.execute_input":"2024-06-16T12:40:50.888567Z","iopub.status.idle":"2024-06-16T12:40:50.892486Z","shell.execute_reply.started":"2024-06-16T12:40:50.888546Z","shell.execute_reply":"2024-06-16T12:40:50.891606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def discriminator_loss(real, generated):\n  real_loss = loss_obj(tf.ones_like(real), real)\n\n  generated_loss = loss_obj(tf.zeros_like(generated), generated)\n\n  total_disc_loss = real_loss + generated_loss\n\n  return total_disc_loss * 0.5","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:51.186961Z","iopub.execute_input":"2024-06-16T12:40:51.187279Z","iopub.status.idle":"2024-06-16T12:40:51.192449Z","shell.execute_reply.started":"2024-06-16T12:40:51.187253Z","shell.execute_reply":"2024-06-16T12:40:51.191408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def generator_loss(generated):\n  return loss_obj(tf.ones_like(generated), generated)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:53.108067Z","iopub.execute_input":"2024-06-16T12:40:53.108932Z","iopub.status.idle":"2024-06-16T12:40:53.112977Z","shell.execute_reply.started":"2024-06-16T12:40:53.108897Z","shell.execute_reply":"2024-06-16T12:40:53.112098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def calc_cycle_loss(real_image, cycled_image):\n  loss1 = tf.reduce_mean(tf.abs(real_image - cycled_image))\n\n  return LAMBDA * loss1","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:53.399473Z","iopub.execute_input":"2024-06-16T12:40:53.399732Z","iopub.status.idle":"2024-06-16T12:40:53.403913Z","shell.execute_reply.started":"2024-06-16T12:40:53.399709Z","shell.execute_reply":"2024-06-16T12:40:53.402988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def identity_loss(real_image, same_image):\n  loss = tf.reduce_mean(tf.abs(real_image - same_image))\n  return LAMBDA * 0.5 * loss","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:53.648705Z","iopub.execute_input":"2024-06-16T12:40:53.649249Z","iopub.status.idle":"2024-06-16T12:40:53.653453Z","shell.execute_reply.started":"2024-06-16T12:40:53.64922Z","shell.execute_reply":"2024-06-16T12:40:53.65255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"generator_g_optimizer = tf.keras.optimizers.Adam(2e-4, beta_1=0.5)\ngenerator_f_optimizer = tf.keras.optimizers.Adam(2e-4, beta_1=0.5)\n\ndiscriminator_x_optimizer = tf.keras.optimizers.Adam(2e-4, beta_1=0.5)\ndiscriminator_y_optimizer = tf.keras.optimizers.Adam(2e-4, beta_1=0.5)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:54.003694Z","iopub.execute_input":"2024-06-16T12:40:54.00446Z","iopub.status.idle":"2024-06-16T12:40:54.023681Z","shell.execute_reply.started":"2024-06-16T12:40:54.00443Z","shell.execute_reply":"2024-06-16T12:40:54.022931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint_path = \"/kaggle/working/prev_input\"\n\nckpt = tf.train.Checkpoint(generator_g=generator_g,\n                           generator_f=generator_f,\n                           discriminator_x=discriminator_x,\n                           discriminator_y=discriminator_y,\n                           generator_g_optimizer=generator_g_optimizer,\n                           generator_f_optimizer=generator_f_optimizer,\n                           discriminator_x_optimizer=discriminator_x_optimizer,\n                           discriminator_y_optimizer=discriminator_y_optimizer)\n\nckpt_manager = tf.train.CheckpointManager(ckpt, checkpoint_path, max_to_keep=5)\n\n# if a checkpoint exists, restore the latest checkpoint.\nif ckpt_manager.latest_checkpoint:\n  ckpt.restore(ckpt_manager.latest_checkpoint)\n  print ('Latest checkpoint restored!!')","metadata":{"execution":{"iopub.status.busy":"2024-06-16T12:40:59.960166Z","iopub.execute_input":"2024-06-16T12:40:59.961002Z","iopub.status.idle":"2024-06-16T12:41:00.569363Z","shell.execute_reply.started":"2024-06-16T12:40:59.960969Z","shell.execute_reply":"2024-06-16T12:41:00.568366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Model training**","metadata":{}},{"cell_type":"code","source":"EPOCHS = 50","metadata":{"execution":{"iopub.status.busy":"2024-06-16T10:10:46.181192Z","iopub.execute_input":"2024-06-16T10:10:46.182154Z","iopub.status.idle":"2024-06-16T10:10:46.186736Z","shell.execute_reply.started":"2024-06-16T10:10:46.182119Z","shell.execute_reply":"2024-06-16T10:10:46.185623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def generate_images(model, test_input):\n  prediction = model(test_input)\n\n  plt.figure(figsize=(12, 12))\n\n  display_list = [test_input[0], prediction[0]]\n  title = ['Input Image', 'Predicted Image']\n\n  for i in range(2):\n    plt.subplot(1, 2, i+1)\n    plt.title(title[i])\n    # getting the pixel values between [0, 1] to plot it.\n    plt.imshow(display_list[i] * 0.5 + 0.5)\n    plt.axis('off')\n  plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T09:22:18.237253Z","iopub.execute_input":"2024-06-16T09:22:18.237654Z","iopub.status.idle":"2024-06-16T09:22:18.244225Z","shell.execute_reply.started":"2024-06-16T09:22:18.237622Z","shell.execute_reply":"2024-06-16T09:22:18.243297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"@tf.function\ndef train_step(real_x, real_y):\n  # persistent is set to True because the tape is used more than\n  # once to calculate the gradients.\n  with tf.GradientTape(persistent=True) as tape:\n    # Generator G translates X -> Y\n    # Generator F translates Y -> X.\n\n    fake_y = generator_g(real_x, training=True)\n    cycled_x = generator_f(fake_y, training=True)\n\n    fake_x = generator_f(real_y, training=True)\n    cycled_y = generator_g(fake_x, training=True)\n\n    # same_x and same_y are used for identity loss.\n    same_x = generator_f(real_x, training=True)\n    same_y = generator_g(real_y, training=True)\n\n    disc_real_x = discriminator_x(real_x, training=True)\n    disc_real_y = discriminator_y(real_y, training=True)\n\n    disc_fake_x = discriminator_x(fake_x, training=True)\n    disc_fake_y = discriminator_y(fake_y, training=True)\n\n    # calculate the loss\n    gen_g_loss = generator_loss(disc_fake_y)\n    gen_f_loss = generator_loss(disc_fake_x)\n\n    total_cycle_loss = calc_cycle_loss(real_x, cycled_x) + calc_cycle_loss(real_y, cycled_y)\n\n    # Total generator loss = adversarial loss + cycle loss\n    total_gen_g_loss = gen_g_loss + total_cycle_loss + identity_loss(real_y, same_y)\n    total_gen_f_loss = gen_f_loss + total_cycle_loss + identity_loss(real_x, same_x)\n\n    disc_x_loss = discriminator_loss(disc_real_x, disc_fake_x)\n    disc_y_loss = discriminator_loss(disc_real_y, disc_fake_y)\n\n  # Calculate the gradients for generator and discriminator\n  generator_g_gradients = tape.gradient(total_gen_g_loss, \n                                        generator_g.trainable_variables)\n  generator_f_gradients = tape.gradient(total_gen_f_loss, \n                                        generator_f.trainable_variables)\n\n  discriminator_x_gradients = tape.gradient(disc_x_loss, \n                                            discriminator_x.trainable_variables)\n  discriminator_y_gradients = tape.gradient(disc_y_loss, \n                                            discriminator_y.trainable_variables)\n\n  # Apply the gradients to the optimizer\n  generator_g_optimizer.apply_gradients(zip(generator_g_gradients, \n                                            generator_g.trainable_variables))\n\n  generator_f_optimizer.apply_gradients(zip(generator_f_gradients, \n                                            generator_f.trainable_variables))\n\n  discriminator_x_optimizer.apply_gradients(zip(discriminator_x_gradients,\n                                                discriminator_x.trainable_variables))\n\n  discriminator_y_optimizer.apply_gradients(zip(discriminator_y_gradients,\n                                                discriminator_y.trainable_variables))","metadata":{"execution":{"iopub.status.busy":"2024-06-16T09:22:20.641789Z","iopub.execute_input":"2024-06-16T09:22:20.642124Z","iopub.status.idle":"2024-06-16T09:22:20.653936Z","shell.execute_reply.started":"2024-06-16T09:22:20.6421Z","shell.execute_reply":"2024-06-16T09:22:20.652942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for epoch in range(EPOCHS):\n  start = time.time()\n\n  n = 0\n  for image_x, image_y in tf.data.Dataset.zip((train_dataset_object, train_dataset_clean_object)):\n    train_step(image_x, image_y)\n    if n % 10 == 0:\n      print ('.', end='')\n    n += 1\n\n  clear_output(wait=True)\n  # Using a consistent image (sample_horse) so that the progress of the model\n  # is clearly visible.\n  generate_images(generator_g, sample_object)\n\n  if (epoch + 1) % 5 == 0:\n    ckpt_save_path = ckpt_manager.save()\n    print ('Saving checkpoint for epoch {} at {}'.format(epoch+1,\n                                                         ckpt_save_path))\n\n  print ('Time taken for epoch {} is {} sec\\n'.format(epoch + 1,\n                                                      time.time()-start))","metadata":{"execution":{"iopub.status.busy":"2024-06-16T09:22:20.65571Z","iopub.execute_input":"2024-06-16T09:22:20.656024Z","iopub.status.idle":"2024-06-16T09:46:55.660926Z","shell.execute_reply.started":"2024-06-16T09:22:20.656001Z","shell.execute_reply":"2024-06-16T09:46:55.6594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**GENERATING**","metadata":{}},{"cell_type":"code","source":"for inp in test_dataset_object.take(5):\n  generate_images(generator_g, inp)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T17:57:41.173604Z","iopub.execute_input":"2024-06-15T17:57:41.174309Z","iopub.status.idle":"2024-06-15T17:57:43.439498Z","shell.execute_reply.started":"2024-06-15T17:57:41.174268Z","shell.execute_reply":"2024-06-15T17:57:43.438426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for inp in test_dataset_clean_object.take(5):\n  generate_images(generator_f, inp)","metadata":{"execution":{"iopub.status.busy":"2024-06-11T13:26:37.493867Z","iopub.execute_input":"2024-06-11T13:26:37.494252Z","iopub.status.idle":"2024-06-11T13:26:40.086076Z","shell.execute_reply.started":"2024-06-11T13:26:37.494224Z","shell.execute_reply":"2024-06-11T13:26:40.08518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Columns\n\nStudyInstanceUID - unique ID for each image\n\nETT - Abnormal - endotracheal tube placement abnormal\n\nETT - Borderline - endotracheal tube placement borderline abnormal\n\nETT - Normal - endotracheal tube placement normal\n\nNGT - Abnormal - nasogastric tube placement abnormal\n\nNGT - Borderline - nasogastric tube placement borderline abnormal\n\nNGT - Incompletely Imaged - nasogastric tube placement inconclusive due to imaging\n\nNGT - Normal - nasogastric tube placement borderline normal\n\nCVC - Abnormal - central venous catheter placement abnormal\n\nCVC - Borderline - central venous catheter placement borderline abnormal\n\nCVC - Normal - central venous catheter placement normal\n\nSwan Ganz Catheter Present\n\nPatientID - unique ID for each patient in the dataset","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/ranzcr-clip-catheter-line-classification/train.csv')\ndf.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-14T18:56:26.365709Z","iopub.execute_input":"2024-06-14T18:56:26.366183Z","iopub.status.idle":"2024-06-14T18:56:26.533275Z","shell.execute_reply.started":"2024-06-14T18:56:26.366146Z","shell.execute_reply":"2024-06-14T18:56:26.531906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-14T19:39:36.913089Z","iopub.execute_input":"2024-06-14T19:39:36.916451Z","iopub.status.idle":"2024-06-14T19:39:36.961456Z","shell.execute_reply.started":"2024-06-14T19:39:36.91628Z","shell.execute_reply":"2024-06-14T19:39:36.959908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}