{"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":"none","dataSources":[{"sourceId":39272,"databundleVersionId":4629629,"sourceType":"competition"},{"sourceId":4619805,"sourceType":"datasetVersion","datasetId":2688675},{"sourceId":4976318,"sourceType":"datasetVersion","datasetId":2693468}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"raw","source":"%%capture \n\n# Clone yolov5 repository\n!git clone https://github.com/ultralytics/yolov5","metadata":{"execution":{"iopub.status.busy":"2024-02-25T19:37:17.93325Z","iopub.execute_input":"2024-02-25T19:37:17.933685Z","iopub.status.idle":"2024-02-25T19:37:19.042599Z","shell.execute_reply.started":"2024-02-25T19:37:17.933613Z","shell.execute_reply":"2024-02-25T19:37:19.041299Z"}}},{"cell_type":"code","source":"%%capture \n\n# Clone yolov5 repository\n!git clone https://github.com/ultralytics/yolov5","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:16:34.17141Z","iopub.execute_input":"2024-03-24T05:16:34.172762Z","iopub.status.idle":"2024-03-24T05:16:38.052215Z","shell.execute_reply.started":"2024-03-24T05:16:34.172696Z","shell.execute_reply":"2024-03-24T05:16:38.050348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport glob\nimport random\nimport cv2\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-24T05:16:44.648802Z","iopub.execute_input":"2024-03-24T05:16:44.650121Z","iopub.status.idle":"2024-03-24T05:16:48.648556Z","shell.execute_reply.started":"2024-03-24T05:16:44.650055Z","shell.execute_reply":"2024-03-24T05:16:48.647077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# TensorFlow libraries\nimport tensorflow as tf\nfrom tensorflow.keras.applications.resnet_v2 import ResNet50V2\nfrom tensorflow.keras.optimizers import RMSprop\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\n\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\n\n# basic libraries\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import classification_report, confusion_matrix\n\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport cv2\nimport os\n\nimport glob\nfrom glob import glob","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:16:51.850184Z","iopub.execute_input":"2024-03-24T05:16:51.850882Z","iopub.status.idle":"2024-03-24T05:17:11.644583Z","shell.execute_reply.started":"2024-03-24T05:16:51.850839Z","shell.execute_reply":"2024-03-24T05:17:11.643278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load trained model\nmodel = torch.hub.load('./yolov5', 'custom', path='/kaggle/input/rsna-breast-cancer-detection-roi-model/rsna-roi-003.pt', source='local')\n","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:17:16.057318Z","iopub.execute_input":"2024-03-24T05:17:16.058348Z","iopub.status.idle":"2024-03-24T05:17:40.98067Z","shell.execute_reply.started":"2024-03-24T05:17:16.058276Z","shell.execute_reply":"2024-03-24T05:17:40.979289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_csv = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")\ntest_csv = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:18:16.696071Z","iopub.execute_input":"2024-03-24T05:18:16.696649Z","iopub.status.idle":"2024-03-24T05:18:16.897088Z","shell.execute_reply.started":"2024-03-24T05:18:16.696611Z","shell.execute_reply":"2024-03-24T05:18:16.895574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_csv","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:18:54.771454Z","iopub.execute_input":"2024-03-24T05:18:54.772398Z","iopub.status.idle":"2024-03-24T05:18:54.795564Z","shell.execute_reply.started":"2024-03-24T05:18:54.772351Z","shell.execute_reply":"2024-03-24T05:18:54.79384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_csv","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.DataFrame(np.concatenate([['Total'] * len(train_csv) , ['Cancer'] *  len(train_csv[train_csv['cancer'] == 1]), ['Non Cancer'] *  len(train_csv[(train_csv['cancer'] == 0)])]), columns = [\"class\"])\n\nsns.countplot(x = 'class', data = data)","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:20:25.979445Z","iopub.execute_input":"2024-03-24T05:20:25.980785Z","iopub.status.idle":"2024-03-24T05:20:26.316902Z","shell.execute_reply.started":"2024-03-24T05:20:25.980731Z","shell.execute_reply":"2024-03-24T05:20:26.315368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.DataFrame(np.concatenate([['Total'] * len(train_csv) , ['malignant cancer'] *  len(train_csv[train_csv['cancer'] == 1]), ['Invasive Cancer'] *  len(train_csv[(train_csv['invasive'] == 1)& train_csv['cancer']==1])]), columns = [\"class\"])\n\nsns.countplot(x = 'class', data = data)\n\n\n\n# data = pd.DataFrame(np.concatenate([['Biopsy but Not Malignant'] * len(DF_train[(DF_train['biopsy'] == 1) & (DF_train['cancer'] == 0)]) , ['Malignant Cancer'] *  len(DF_train[DF_train['cancer'] == 1]), ['Invasive Cancer'] *  len(DF_train[(DF_train['cancer'] == 1) & (DF_train['invasive'] == 1)])]), columns = [\"class\"])\n\n# sns.countplot(x = 'class', data = data)","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:20:41.088034Z","iopub.execute_input":"2024-03-24T05:20:41.0896Z","iopub.status.idle":"2024-03-24T05:20:41.24739Z","shell.execute_reply.started":"2024-03-24T05:20:41.08954Z","shell.execute_reply":"2024-03-24T05:20:41.245998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_subset_0 = train_csv[train_csv.cancer == 0]\ntrain_subset_1 = train_csv[train_csv.cancer == 1]\nprint(train_subset_0.shape, train_subset_1.shape)\nprint(train_subset_0.laterality.value_counts())\nprint(train_subset_1.laterality.value_counts())","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:20:44.93601Z","iopub.execute_input":"2024-03-24T05:20:44.936675Z","iopub.status.idle":"2024-03-24T05:20:44.97047Z","shell.execute_reply.started":"2024-03-24T05:20:44.936624Z","shell.execute_reply":"2024-03-24T05:20:44.96886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_subset_1","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(train_subset_0))\nprint(len(train_subset_1))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_subset_0_L = train_subset_0[train_subset_0.laterality == \"L\"].iloc[:588,]\n# train_subset_0_R = train_subset_0[train_subset_0.laterality == \"R\"].iloc[:570,]\n# train_subset_main = pd.concat([train_subset_0_L, train_subset_0_R, train_subset_1])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_subset_0_L = train_subset_0[train_subset_0.laterality == \"L\"].iloc[:3000,]\ntrain_subset_0_R = train_subset_0[train_subset_0.laterality == \"R\"].iloc[:3000,]\ntrain_subset_main = pd.concat([train_subset_0_L, train_subset_0_R, train_subset_1])","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:20:56.719314Z","iopub.execute_input":"2024-03-24T05:20:56.719848Z","iopub.status.idle":"2024-03-24T05:20:56.764025Z","shell.execute_reply.started":"2024-03-24T05:20:56.719806Z","shell.execute_reply":"2024-03-24T05:20:56.762373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(train_subset_main))","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:21:00.948795Z","iopub.execute_input":"2024-03-24T05:21:00.949397Z","iopub.status.idle":"2024-03-24T05:21:00.959024Z","shell.execute_reply.started":"2024-03-24T05:21:00.949337Z","shell.execute_reply":"2024-03-24T05:21:00.956737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_subset_main","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_subset_main.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.mkdir('/kaggle/working/input_transformed/')","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:21:05.240469Z","iopub.execute_input":"2024-03-24T05:21:05.240969Z","iopub.status.idle":"2024-03-24T05:21:05.247665Z","shell.execute_reply.started":"2024-03-24T05:21:05.240932Z","shell.execute_reply":"2024-03-24T05:21:05.246235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.mkdir('/kaggle/working/input_transformed/0/')\nos.mkdir('/kaggle/working/input_transformed/1/')","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:21:09.320772Z","iopub.execute_input":"2024-03-24T05:21:09.321282Z","iopub.status.idle":"2024-03-24T05:21:09.327772Z","shell.execute_reply.started":"2024-03-24T05:21:09.321249Z","shell.execute_reply":"2024-03-24T05:21:09.326592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def reshape_and_normalize(images):\n    \n    # Reshape the images to add an extra dimension\n    # images = images[..., np.newaxis]\n    \n    # Normalize pixel values\n    images = images / 255.0\n    \n    ### END CODE HERE\n    return images","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:21:14.376766Z","iopub.execute_input":"2024-03-24T05:21:14.377248Z","iopub.status.idle":"2024-03-24T05:21:14.384838Z","shell.execute_reply.started":"2024-03-24T05:21:14.377215Z","shell.execute_reply":"2024-03-24T05:21:14.383144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nfrom tqdm import tqdm\n# shutil.copyfile(src, dst)","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:21:17.936708Z","iopub.execute_input":"2024-03-24T05:21:17.938082Z","iopub.status.idle":"2024-03-24T05:21:17.943818Z","shell.execute_reply.started":"2024-03-24T05:21:17.938032Z","shell.execute_reply":"2024-03-24T05:21:17.942056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p_id = train_subset_main.patient_id\ni_id = train_subset_main.image_id\ncncr = train_subset_main.cancer\nfor pp, ii, cc in tqdm(zip(p_id, i_id, cncr)):\n    tmpFile = str(pp) + \"_\" + str(ii) + \".png\"\n    tmpSrc = \"/kaggle/input/rsna-breast-cancer-512-pngs/\" + tmpFile\n    tmpDst = \"/kaggle/working/input_transformed/\" + str(cc) + \"/\" + tmpFile\n    shutil.copyfile(tmpSrc, tmpDst)","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:21:21.618988Z","iopub.execute_input":"2024-03-24T05:21:21.619475Z","iopub.status.idle":"2024-03-24T05:22:51.039774Z","shell.execute_reply.started":"2024-03-24T05:21:21.619439Z","shell.execute_reply":"2024-03-24T05:22:51.038386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\n\nimg = mpimg.imread('/kaggle/working/input_transformed/0/10412_1057358723.png')\nprint(img)\n\n# img2 = (img * 255).astype(np.uint8)\n# print(img2)\nimage_height, image_width = img.shape\nprint(\"Image dimensions: Height =\", image_height, \"Width =\", image_width)\n\nplt.imshow(img)\nplt.axis('off')  # optional\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-21T19:37:19.641201Z","iopub.execute_input":"2024-03-21T19:37:19.6416Z","iopub.status.idle":"2024-03-21T19:37:19.679935Z","shell.execute_reply.started":"2024-03-21T19:37:19.641561Z","shell.execute_reply":"2024-03-21T19:37:19.679242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# Read the image\nimage = cv2.imread('/kaggle/working/input_transformed/0/10412_1057358723.png')  # Replace 'your_image_path.jpg' with the path to your image\n\n# Access the shape of the image\nheight, width, channels = image.shape\n\nprint(\"Number of channels:\", channels)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:23:50.011563Z","iopub.execute_input":"2024-03-24T05:23:50.012325Z","iopub.status.idle":"2024-03-24T05:23:50.037937Z","shell.execute_reply.started":"2024-03-24T05:23:50.01227Z","shell.execute_reply":"2024-03-24T05:23:50.036467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img=mpimg.imread('/kaggle/input/rsna-breast-cancer-512-pngs/10006_1459541791.png')\nprint(img)","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nnormal_images=glob.glob('/kaggle/working/input_transformed/0/*.png')\nprint(len(normal_images))\nprint()","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:23:54.727942Z","iopub.execute_input":"2024-03-24T05:23:54.728461Z","iopub.status.idle":"2024-03-24T05:23:54.76435Z","shell.execute_reply.started":"2024-03-24T05:23:54.728423Z","shell.execute_reply":"2024-03-24T05:23:54.762783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# See normal images from the training dataset.\nfig, axes = plt.subplots(nrows = 2, ncols = 5, figsize = (15, 10), subplot_kw = {'xticks':[], 'yticks':[]})\nfor i, ax in enumerate(axes.flat):\n    img = cv2.imread(normal_images[i])\n    ax.imshow(img)\n    ax.set_title('Normal')\nfig.tight_layout()    \n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:23:57.989907Z","iopub.execute_input":"2024-03-24T05:23:57.990477Z","iopub.status.idle":"2024-03-24T05:23:59.223869Z","shell.execute_reply.started":"2024-03-24T05:23:57.990433Z","shell.execute_reply":"2024-03-24T05:23:59.222259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ncancer_images=glob.glob('/kaggle/working/input_transformed/1/*.png')\nprint(len(cancer_images))\n","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:24:03.317867Z","iopub.execute_input":"2024-03-24T05:24:03.318388Z","iopub.status.idle":"2024-03-24T05:24:03.332728Z","shell.execute_reply.started":"2024-03-24T05:24:03.318347Z","shell.execute_reply":"2024-03-24T05:24:03.331067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# See cancer images from the training dataset.\nfig, axes = plt.subplots(nrows = 2, ncols = 5, figsize = (15, 10), subplot_kw = {'xticks':[], 'yticks':[]})\nfor i, ax in enumerate(axes.flat):\n    img = cv2.imread(cancer_images[i])\n    ax.imshow(img)\n    ax.set_title('Cancer')\nfig.tight_layout()    \n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:24:06.699931Z","iopub.execute_input":"2024-03-24T05:24:06.700881Z","iopub.status.idle":"2024-03-24T05:24:07.362261Z","shell.execute_reply.started":"2024-03-24T05:24:06.700821Z","shell.execute_reply":"2024-03-24T05:24:07.361002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # See normal images from the training dataset.\n# fig, axes = plt.subplots(nrows = 2, ncols = 5, figsize = (15, 10), subplot_kw = {'xticks':[], 'yticks':[]})\n# for i, ax in enumerate(axes.flat):\n#     img = cv2.imread(cancer_images[i])\n#     ax.imshow(img)\n#     ax.set_title('Cancer')\n# fig.tight_layout()    \n\n# plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# %matplotlib inline\n# images = []\n\n# for img_file in random.sample(cancer_images, 25):  # it is fixed to 25 random predictions - if you want to change it remeber to change plot_roi as well\n    \n#     # Read file from file\n#     frame = cv2.imread(img_file)\n    \n#     # Make prediction\n#     detections = model(frame)\n    \n#     # Convert results to Pandas style\n#     results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    \n#     # Plot result (in 99.99% it predicts only one instance - certainly you can assure that only best prediction is used)\n#     for result in results:\n#         images.append(cv2.rectangle(frame, (int(result['xmin']), int(result['ymin'])), (int(result['xmax']), int(result['ymax'])), (255,0,0), 4))\n\n# # Plot result\n# fig, axes = plt.subplots(5, 5, figsize=(20,20))\n    \n# for idx, image in enumerate(images):\n#     i = idx % 5 \n#     j = idx // 5 \n#     axes[i, j].imshow(image)\n\n# plt.subplots_adjust(wspace=0, hspace=.2)\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:24:41.36873Z","iopub.execute_input":"2024-03-24T05:24:41.369227Z","iopub.status.idle":"2024-03-24T05:24:41.378212Z","shell.execute_reply.started":"2024-03-24T05:24:41.369191Z","shell.execute_reply":"2024-03-24T05:24:41.375782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\nimages = []\n\nfor img_file in random.sample(cancer_images, 25):  # it is fixed to 25 random predictions - if you want to change it remeber to change plot_roi as well\n    \n    # Read file from file\n    frame = cv2.imread(img_file)\n    \n    # Make prediction\n    detections = model(frame)\n    \n    # Convert results to Pandas style\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    \n    # Plot result (in 99.99% it predicts only one instance - certainly you can assure that only best prediction is used)\n    for result in results:\n        images.append(cv2.rectangle(frame, (int(result['xmin']), int(result['ymin'])), (int(result['xmax']), int(result['ymax'])), (255,0,0), 4))\n\n# Plot result\nfig, axes = plt.subplots(5, 5, figsize=(20,20))\n    \nfor idx, image in enumerate(images):\n    i = idx % 5 \n    j = idx // 5 \n    axes[i, j].imshow(image)\n\nplt.subplots_adjust(wspace=0, hspace=.2)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:24:49.508848Z","iopub.execute_input":"2024-03-24T05:24:49.509349Z","iopub.status.idle":"2024-03-24T05:25:01.071374Z","shell.execute_reply.started":"2024-03-24T05:24:49.50931Z","shell.execute_reply":"2024-03-24T05:25:01.069433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import os\n# import cv2\n\n# # Define the folder path\n# folder_path = 'input_transformed/0/'\n\n# # Iterate through all files in the folder\n# for filename in os.listdir(folder_path):\n#     # Check if the file is an image\n#     if filename.endswith(('.png', '.jpg', '.jpeg')):\n#         # Read the image\n#         image_path = os.path.join(folder_path, filename)\n#         img = cv2.imread(image_path)\n#         # Get the dimensions of the image (height, width)\n#         height, width, _ = img.shape\n#         # Print the dimensions\n#         print(f\"Image: {filename}, Size: {width}x{height}\")\n","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import os\n# import cv2\n# import shutil\n\n# # Define the paths to the input images and the output directory\n# input_folder_0 = '/kaggle/working/input_transformed/0/'\n# input_folder_1 = '/kaggle/working/input_transformed/1/'\n# output_folder = '/kaggle/working/cropped/'\n\n# # Create output folders if they do not exist\n# os.makedirs(os.path.join(output_folder, '0'), exist_ok=True)\n# os.makedirs(os.path.join(output_folder, '1'), exist_ok=True)\n\n# # Process images in folder 0\n# for img_file in os.listdir(input_folder_0):\n#     image_path = os.path.join(input_folder_0, img_file)\n#     frame = cv2.imread(image_path)\n#     detections = model(frame)\n#     results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n#     for result in results:\n#         # Extract coordinates\n#         xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n#         # Crop the image\n#         cropped_img = frame[ymin:ymax, xmin:xmax]\n#         # Save the cropped image\n#         cv2.imwrite(os.path.join(output_folder, '0', img_file), cropped_img)\n\n# # Process images in folder 1\n# for img_file in os.listdir(input_folder_1):\n#     image_path = os.path.join(input_folder_1, img_file)\n#     frame = cv2.imread(image_path)\n#     detections = model(frame)\n#     results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n#     for result in results:\n#         # Extract coordinates\n#         xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n#         # Crop the image\n#         cropped_img = frame[ymin:ymax, xmin:xmax]\n#         # Save the cropped image\n#         cv2.imwrite(os.path.join(output_folder, '1', img_file), cropped_img)\n\n# print(\"Cropping and saving images complete.\")\n","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ###########\n\n# import os\n# import cv2\n# import shutil\n\n# # Define the paths to the input images and the output directory\n# input_folder_0 = '/kaggle/working/input_transformed/0/'\n# input_folder_1 = '/kaggle/working/input_transformed/1/'\n# output_folder = '/kaggle/working/croppedtest/'\n\n# # Create output folders if they do not exist\n# os.makedirs(os.path.join(output_folder, '0'), exist_ok=True)\n# os.makedirs(os.path.join(output_folder, '1'), exist_ok=True)\n\n# # Process images in folder 0\n# for img_file in os.listdir(input_folder_0):\n#     image_path = os.path.join(input_folder_0, img_file)\n#     frame = cv2.imread(image_path)\n#     detections = model(frame)\n#     results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n#     for result in results:\n#         # Extract coordinates\n#         xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n#         # Crop the image\n#         cropped_img = frame[ymin:ymax, xmin:xmax]\n#         # Save the cropped image\n#         cv2.imwrite(os.path.join(output_folder, '0', img_file), cropped_img)\n\n# # Process images in folder 1\n# for img_file in os.listdir(input_folder_1):\n#     image_path = os.path.join(input_folder_1, img_file)\n#     frame = cv2.imread(image_path)\n#     detections = model(frame)\n#     results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n#     for result in results:\n#         # Extract coordinates\n#         xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n#         # Crop the image\n#         cropped_img = frame[ymin:ymax, xmin:xmax]\n        \n#         # Save the cropped image\n#         cv2.imwrite(os.path.join(output_folder, '1', img_file), cropped_img)\n\n# print(\"Cropping and saving images complete.\")\n","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#rgb images\nimport os\nimport cv2\nimport shutil\n\n# Define the paths to the input images and the output directory\ninput_folder_0 = '/kaggle/working/input_transformed/0/'\ninput_folder_1 = '/kaggle/working/input_transformed/1/'\noutput_folder = '/kaggle/working/croppedtestRgb/'\n\n# Create output folders if they do not exist\nos.makedirs(os.path.join(output_folder, '0'), exist_ok=True)\nos.makedirs(os.path.join(output_folder, '1'), exist_ok=True)\n\n# Process images in folder 0\nfor img_file in os.listdir(input_folder_0):\n    image_path = os.path.join(input_folder_0, img_file)\n    frame = cv2.imread(image_path)\n    detections = model(frame)\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    for result in results:\n        # Extract coordinates\n        xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n        # Crop the image\n        cropped_img = frame[ymin:ymax, xmin:xmax]\n        # Resize the cropped image to 256x256\n        cropped_img_resized = cv2.resize(cropped_img, (256, 256))\n        # Save the resized cropped image\n        cv2.imwrite(os.path.join(output_folder, '0', img_file), cropped_img_resized)\n        \n\n# Process images in folder 1\nfor img_file in os.listdir(input_folder_1):\n    image_path = os.path.join(input_folder_1, img_file)\n    frame = cv2.imread(image_path)\n    detections = model(frame)\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    for result in results:\n        # Extract coordinates\n        xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n        # Crop the image\n        cropped_img = frame[ymin:ymax, xmin:xmax]\n        # Resize the cropped image to 256x256\n        cropped_img_resized = cv2.resize(cropped_img, (256, 256))\n        # Save the resized cropped image\n        cv2.imwrite(os.path.join(output_folder, '1', img_file), cropped_img_resized)\n\nprint(\"Cropping and saving images complete.\")\n","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:25:43.93308Z","iopub.execute_input":"2024-03-24T05:25:43.933637Z","iopub.status.idle":"2024-03-24T05:56:48.91297Z","shell.execute_reply.started":"2024-03-24T05:25:43.933595Z","shell.execute_reply":"2024-03-24T05:56:48.911364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#grey scale convesion\n\nimport cv2\nimport os\n\n# Define the paths to the input images and the output directory\ninput_folder_0 = '/kaggle/working/input_transformed/0/'\ninput_folder_1 = '/kaggle/working/input_transformed/1/'\noutput_folder = '/kaggle/working/croppedtest/'\n\n# Create output folders if they do not exist\nos.makedirs(os.path.join(output_folder, '0'), exist_ok=True)\nos.makedirs(os.path.join(output_folder, '1'), exist_ok=True)\n\n# Process images in folder 0\nfor img_file in os.listdir(input_folder_0):\n    image_path = os.path.join(input_folder_0, img_file)\n    frame = cv2.imread(image_path)\n    detections = model(frame)\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    for result in results:\n        # Extract coordinates\n        xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n        # Crop the image\n        cropped_img = frame[ymin:ymax, xmin:xmax]\n        # Resize the cropped image to 256x256\n        cropped_img_resized = cv2.resize(cropped_img, (256, 256))\n        # Convert the cropped image to grayscale\n        cropped_img_gray = cv2.cvtColor(cropped_img_resized, cv2.COLOR_BGR2GRAY)\n        #for checkingn\n        width, channels = cropped_img_gray.shape\n        print(\"Number of channels:\", width)\n        # Save the grayscale cropped image\n        cv2.imwrite(os.path.join(output_folder, '0', img_file), cropped_img_gray)\n\n# Process images in folder 1\nfor img_file in os.listdir(input_folder_1):\n    image_path = os.path.join(input_folder_1, img_file)\n    frame = cv2.imread(image_path)\n    detections = model(frame)\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    for result in results:\n        # Extract coordinates\n        xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n        # Crop the image\n        cropped_img = frame[ymin:ymax, xmin:xmax]\n        # Resize the cropped image to 256x256\n        cropped_img_resized = cv2.resize(cropped_img, (256, 256))\n        # Convert the cropped image to grayscale\n        cropped_img_gray = cv2.cvtColor(cropped_img_resized, cv2.COLOR_BGR2GRAY)\n        # Save the grayscale cropped image\n        \n        cv2.imwrite(os.path.join(output_folder, '1', img_file), cropped_img_gray)\n\nprint(\"Cropping and saving images complete.\")\n","metadata":{"execution":{"iopub.status.busy":"2024-03-24T05:58:26.793346Z","iopub.execute_input":"2024-03-24T05:58:26.794538Z","iopub.status.idle":"2024-03-24T06:29:30.759228Z","shell.execute_reply.started":"2024-03-24T05:58:26.794458Z","shell.execute_reply":"2024-03-24T06:29:30.757993Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport os\n\n# Define the paths to the input images and the output directory\ninput_folder_0 = '/kaggle/working/input_transformed/0/'\ninput_folder_1 = '/kaggle/working/input_transformed/1/'\noutput_folder = '/kaggle/working/croppedtest/'\n\n# Create output folders if they do not exist\nos.makedirs(os.path.join(output_folder, '0'), exist_ok=True)\nos.makedirs(os.path.join(output_folder, '1'), exist_ok=True)\n\n# Process images in folder 0\nfor img_file in os.listdir(input_folder_0):\n    image_path = os.path.join(input_folder_0, img_file)\n    frame = cv2.imread(image_path)\n    print(\"Original Image Color Mode:\", frame.shape)  # Print original image color mode\n    detections = model(frame)\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    for result in results:\n        # Extract coordinates\n        xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n        # Crop the image\n        cropped_img = frame[ymin:ymax, xmin:xmax]\n        # Resize the cropped image to 256x256\n        cropped_img_resized = cv2.resize(cropped_img, (256, 256))\n        # Convert the cropped image to grayscale\n        cropped_img_gray = cv2.cvtColor(cropped_img_resized, cv2.COLOR_BGR2GRAY)\n        print(\"Converted Image Color Mode:\", cropped_img_gray.shape)  # Print converted image color mode\n        # Save the grayscale cropped image\n        cv2.imwrite(os.path.join(output_folder, '0', img_file), cropped_img_gray)\n\n# Process images in folder 1\nfor img_file in os.listdir(input_folder_1):\n    image_path = os.path.join(input_folder_1, img_file)\n    frame = cv2.imread(image_path)\n    print(\"Original Image Color Mode:\", frame.shape)  # Print original image color mode\n    detections = model(frame)\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    for result in results:\n        # Extract coordinates\n        xmin, ymin, xmax, ymax = int(result['xmin']), int(result['ymin']), int(result['xmax']), int(result['ymax'])\n        # Crop the image\n        cropped_img = frame[ymin:ymax, xmin:xmax]\n        # Resize the cropped image to 256x256\n        cropped_img_resized = cv2.resize(cropped_img, (256, 256))\n        # Convert the cropped image to grayscale\n        cropped_img_gray = cv2.cvtColor(cropped_img_resized, cv2.COLOR_BGR2GRAY)\n        print(\"Converted Image Color Mode:\", cropped_img_gray.shape)  # Print converted image color mode\n        # Save the grayscale cropped image\n        cv2.imwrite(os.path.join(output_folder, '1', img_file), cropped_img_gray)\n\nprint(\"Cropping and saving images complete.\")\n","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import os\n# import cv2\n# import shutil\n\n# # Define the fixed dimensions for resizing\n# target_width = 512\n# target_height = 512\n\n# # Define the paths to the input images and the output directory\n# input_folder_0 = '/kaggle/working/input_transformed/0/'\n# input_folder_1 = '/kaggle/working/input_transformed/1/'\n# output_folder = '/kaggle/working/croppedtest/'\n\n# # Create output folders if they do not exist\n# os.makedirs(os.path.join(output_folder, '0'), exist_ok=True)\n# os.makedirs(os.path.join(output_folder, '1'), exist_ok=True)\n\n# def resize_image(image_path, target_width, target_height):\n#     # Read the image\n#     image = cv2.imread(image_path)\n#     # Resize the image\n#     resized_image = cv2.resize(image, (target_width, target_height))\n#     return resized_image\n\n# # Process images in folder 0\n# for img_file in os.listdir(input_folder_0):\n#     image_path = os.path.join(input_folder_0, img_file)\n#     # Resize the image\n#     resized_img = resize_image(image_path, target_width, target_height)\n#     # Save the resized image\n#     cv2.imwrite(os.path.join(output_folder, '0', img_file), resized_img)\n\n# # Process images in folder 1\n# for img_file in os.listdir(input_folder_1):\n#     image_path = os.path.join(input_folder_1, img_file)\n#     # Resize the image\n#     resized_img = resize_image(image_path, target_width, target_height)\n#     # Save the resized image\n#     cv2.imwrite(os.path.join(output_folder, '1', img_file), resized_img)\n\n# print(\"Resizing and saving images complete.\")\n","metadata":{"jupyter":{"source_hidden":true}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import os\n# import cv2\n\n# # Define the folder path\n# folder_path = 'croppedtest/1/'\n\n# # Iterate through all files in the folder\n# for filename in os.listdir(folder_path):\n#     # Check if the file is an image\n#     if filename.endswith(('.png', '.jpg', '.jpeg')):\n#         # Read the image\n#         image_path = os.path.join(folder_path, filename)\n#         img = cv2.imread(image_path)\n#         # Get the dimensions of the image (height, width)\n#         height, width, _ = img.shape\n#         # Print the dimensions\n#         print(f\"Image: {filename}, Size: {width}x{height}\")\n","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cropped_images1=glob.glob('/kaggle/working/cropped/1/*.png')\n# print(len(cropped_images1))\n","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# fig, axes = plt.subplots(nrows = 2, ncols = 5, figsize = (15, 10), subplot_kw = {'xticks':[], 'yticks':[]})\n# for i, ax in enumerate(axes.flat):\n#     img = cv2.imread(cropped_images1[i])\n#     ax.imshow(img)\n#     ax.set_title('Cancer')\n# fig.tight_layout()    \n\n# plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cropped_images0=glob.glob('/kaggle/working/cropped/0/*.png')\n# print(len(cropped_images0))","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# fig, axes = plt.subplots(nrows = 2, ncols = 5, figsize = (15, 10), subplot_kw = {'xticks':[], 'yticks':[]})\n# for i, ax in enumerate(axes.flat):\n#     img = cv2.imread(cropped_images0[i])\n#     ax.imshow(img)\n#     ax.set_title('Normal')\n# fig.tight_layout()    \n\n# plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cropped_images1=glob.glob('/kaggle/working/croppedtest/1/*.png')\nprint(len(cropped_images1))\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(nrows = 2, ncols = 5, figsize = (15, 10), subplot_kw = {'xticks':[], 'yticks':[]})\nfor i, ax in enumerate(axes.flat):\n    img = cv2.imread(cropped_images1[i])\n    ax.imshow(img)\n    ax.set_title('Cancer')\nfig.tight_layout()    \n\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cropped_images0=glob.glob('/kaggle/working/croppedtest/0/*.png')\nprint(len(cropped_images1))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(nrows = 2, ncols = 5, figsize = (15, 10), subplot_kw = {'xticks':[], 'yticks':[]})\nfor i, ax in enumerate(axes.flat):\n    img = cv2.imread(cropped_images0[i])\n    ax.imshow(img)\n    ax.set_title('Normal')\nfig.tight_layout()    \n\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# Read the image\nimage = cv2.imread('/kaggle/working/croppedtest/1/5608_908319767.png')  # Replace 'your_image_path.jpg' with the path to your image\n\n# Access the shape of the image\nheight, width, channels = image.shape\n\nprint(\"Number of channels:\", channels)\nprint(\"HEight:\", height)\nprint(\"width :\", width)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:04:26.960432Z","iopub.execute_input":"2024-03-21T20:04:26.960805Z","iopub.status.idle":"2024-03-21T20:04:26.967957Z","shell.execute_reply.started":"2024-03-21T20:04:26.960775Z","shell.execute_reply":"2024-03-21T20:04:26.966907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"/kaggle/working/croppedtest/\",\n    color_mode='rgb',\n    image_size=(256, 256),\n    shuffle=True,\n    validation_split=0.2,\n    subset=\"training\",\n    seed=2023)","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#grey scale\ntrain_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"/kaggle/working/croppedtest/\",\n    color_mode='grayscale',\n    image_size=(256, 256),\n    shuffle=True,\n    validation_split=0.2,\n    subset=\"training\",\n    seed=2023)","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:04:31.278577Z","iopub.execute_input":"2024-03-21T20:04:31.278981Z","iopub.status.idle":"2024-03-21T20:04:31.639218Z","shell.execute_reply.started":"2024-03-21T20:04:31.278946Z","shell.execute_reply":"2024-03-21T20:04:31.638395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#grey scale\ntrain_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"/kaggle/working/croppedtest/\",\n    color_mode='rgb',\n    image_size=(256, 256),\n    shuffle=True,\n    validation_split=0.2,\n    subset=\"training\",\n    seed=2023)","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:44:27.146412Z","iopub.execute_input":"2024-03-21T20:44:27.146822Z","iopub.status.idle":"2024-03-21T20:44:27.449765Z","shell.execute_reply.started":"2024-03-21T20:44:27.14679Z","shell.execute_reply":"2024-03-21T20:44:27.448941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"/kaggle/working/croppedtest/\",\n    color_mode='rgb',\n    image_size=(256, 256),\n    shuffle=True,\n    validation_split=0.2,\n    subset=\"validation\",\n    seed=2023)","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"/kaggle/working/croppedtest/\",\n    color_mode='grayscale',  # Change color_mode to 'grayscale'\n    image_size=(256, 256),\n    shuffle=True,\n    validation_split=0.2,\n    subset=\"validation\",\n    seed=2023)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:04:36.228957Z","iopub.execute_input":"2024-03-21T20:04:36.229398Z","iopub.status.idle":"2024-03-21T20:04:36.531309Z","shell.execute_reply.started":"2024-03-21T20:04:36.229367Z","shell.execute_reply":"2024-03-21T20:04:36.530272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"/kaggle/working/croppedtest/\",\n    color_mode='rgb',  # Change color_mode to 'grayscale'\n    image_size=(256, 256),\n    shuffle=True,\n    validation_split=0.2,\n    subset=\"validation\",\n    seed=2023)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:44:33.333761Z","iopub.execute_input":"2024-03-21T20:44:33.334151Z","iopub.status.idle":"2024-03-21T20:44:33.63443Z","shell.execute_reply.started":"2024-03-21T20:44:33.334117Z","shell.execute_reply":"2024-03-21T20:44:33.633371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"","metadata":{},"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":"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n\n# Define data augmentation parameters\ndatagen = ImageDataGenerator(\n    rotation_range=20,      # Rotate images randomly by up to 20 degrees\n    width_shift_range=0.2,  # Shift images horizontally by up to 20% of the width\n    height_shift_range=0.2, # Shift images vertically by up to 20% of the height\n    shear_range=0.2,        # Shear transformations\n    zoom_range=0.2,         # Zoom images by up to 20%\n    horizontal_flip=True,   # Flip images horizontally\n    fill_mode='nearest'     # Fill in missing pixels using the nearest available pixel\n)\n\n# Apply data augmentation to the training dataset\ntrain_datagen = datagen.flow_from_directory(\n    \"/kaggle/working/croppedtest/\",\n    target_size=(256, 256),\n    batch_size=36,\n    class_mode='binary',\n    subset='training' # Specify that this is the training subset\n)\n\n\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_datagen)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.layers import Dropout","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import layers\n\n# Now you can use layers from TensorFlow.keras\n","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:04:46.440183Z","iopub.execute_input":"2024-03-21T20:04:46.440569Z","iopub.status.idle":"2024-03-21T20:04:46.444306Z","shell.execute_reply.started":"2024-03-21T20:04:46.440536Z","shell.execute_reply":"2024-03-21T20:04:46.443465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import layers, Sequential\n\nnum_classes = 2\n\nmodel = Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(256, 256, 1)),# Adjust input shape for grayscale images\n\n    layers.Conv2D(16, 3, padding='same', activation='relu'),  \n    layers.MaxPooling2D(),   \n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(), \n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(1, activation='sigmoid')  # Sigmoid activation for binary classification\n])\n\nmodel.summary()\n","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:04:43.030153Z","iopub.execute_input":"2024-03-21T20:04:43.030511Z","iopub.status.idle":"2024-03-21T20:04:43.259458Z","shell.execute_reply.started":"2024-03-21T20:04:43.030484Z","shell.execute_reply":"2024-03-21T20:04:43.258471Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Compile the model\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:04:53.358918Z","iopub.execute_input":"2024-03-21T20:04:53.359291Z","iopub.status.idle":"2024-03-21T20:04:53.378724Z","shell.execute_reply.started":"2024-03-21T20:04:53.359263Z","shell.execute_reply":"2024-03-21T20:04:53.377704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"callback = tf.keras.callbacks.EarlyStopping(monitor = \"val_loss\", mode = \"min\", patience = 4)\n\nhistory = model.fit(train_ds, validation_data = valid_ds, epochs = 15, callbacks = callback)","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:05:01.020452Z","iopub.execute_input":"2024-03-21T20:05:01.020841Z","iopub.status.idle":"2024-03-21T20:18:30.589124Z","shell.execute_reply.started":"2024-03-21T20:05:01.020809Z","shell.execute_reply":"2024-03-21T20:18:30.58756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = history.history['accuracy']\nval_accuracy = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (15,10))\n\nplt.subplot(2, 2, 1)\nplt.plot(accuracy, label = \"Training Accuracy\")\nplt.plot(val_accuracy, label = \"Validation Accuracy\")\nplt.ylim(0.4, 1)\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Accuracy\")\nplt.xlabel('epoch')\nplt.ylabel('accuracy')\n\n\nplt.subplot(2, 2, 2)\nplt.plot(loss, label = \"Training Loss\")\nplt.plot(val_loss, label = \"Validation Loss\")\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Loss\")\nplt.xlabel('epoch')\nplt.ylabel('loss')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model = ResNet50V2(weights = 'imagenet', input_shape = (256, 256, 3), include_top = False)\n\nfor layer in base_model.layers:\n    layer.trainable = False\n    \nmodel = Sequential()\nmodel.add(base_model)\nmodel.add(GlobalAveragePooling2D())\nmodel.add(Dense(128, activation = 'relu'))\nmodel.add(Dropout(0.2))\nmodel.add(Dense(1, activation = 'sigmoid'))\n\nmodel.compile(optimizer = \"adam\", loss = 'binary_crossentropy', metrics = [\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:44:47.197534Z","iopub.execute_input":"2024-03-21T20:44:47.198345Z","iopub.status.idle":"2024-03-21T20:44:49.70576Z","shell.execute_reply.started":"2024-03-21T20:44:47.198305Z","shell.execute_reply":"2024-03-21T20:44:49.704623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:44:50.925579Z","iopub.execute_input":"2024-03-21T20:44:50.925988Z","iopub.status.idle":"2024-03-21T20:44:50.963368Z","shell.execute_reply.started":"2024-03-21T20:44:50.925954Z","shell.execute_reply":"2024-03-21T20:44:50.962454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"callback = tf.keras.callbacks.EarlyStopping(monitor = \"val_loss\", mode = \"min\", patience = 4)\n\nhistory = model.fit(train_ds, validation_data = valid_ds, epochs = 15, callbacks = callback)","metadata":{"execution":{"iopub.status.busy":"2024-03-21T20:44:56.416478Z","iopub.execute_input":"2024-03-21T20:44:56.416834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = history.history['accuracy']\nval_accuracy = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (15,10))\n\nplt.subplot(2, 2, 1)\nplt.plot(accuracy, label = \"Training Accuracy\")\nplt.plot(val_accuracy, label = \"Validation Accuracy\")\nplt.ylim(0.4, 1)\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Accuracy\")\nplt.xlabel('epoch')\nplt.ylabel('accuracy')\n\n\nplt.subplot(2, 2, 2)\nplt.plot(loss, label = \"Training Loss\")\nplt.plot(val_loss, label = \"Validation Loss\")\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Loss\")\nplt.xlabel('epoch')\nplt.ylabel('loss')","metadata":{"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":{},"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":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_ds,\n    validation_data=valid_ds,\n    epochs=20,\n)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models\n\n# Define input shape for grayscale images\nimage_height, image_width, num_channels = 256, 256, 3  # Assuming grayscale images of size 256x256\n\n# Define CNN model architecture\nmodel = models.Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(image_height, image_width, num_channels)),\n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D((2, 2)),\n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D((2, 2)),\n    layers.Conv2D(128, 3, padding='same', activation='relu'), \n    layers.MaxPooling2D((2, 2)),\n    layers.Conv2D(256, 3, padding='same', activation='relu'),    \n    layers.MaxPooling2D((2, 2)),\n    layers.Flatten(),\n    layers.Dense(512, activation='relu'),\n#     layers.Dropout(0.5),\n    layers.Dense(1, activation='sigmoid')  # Sigmoid for binary classification\n])\n\n# Compile the model\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['accuracy'])\n\n# Display the model summary\nmodel.summary()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Compile the model\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['accuracy'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_ds,\n    validation_data=valid_ds,\n    epochs=20,\n)","metadata":{"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":"from tensorflow.keras import layers, Sequential\n\nnum_classes = 2\n\nmodel = Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(256, 256, 3)),\n    layers.Conv2D(16, 3, padding='same', activation='relu'),  \n    layers.MaxPooling2D(),   \n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(), \n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(num_classes, activation='sigmoid')  # Sigmoid activation for binary classification\n])\n\nmodel.summary()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import layers, Sequential\n\nnum_classes = 2\n\nmodel = Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(256, 256, 3)),\n    layers.Conv2D(16, 3, padding='same', activation='relu'),  \n    layers.MaxPooling2D(),   \n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Dropout(0.2),\n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dropout(0.4),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(1, activation='sigmoid')  # Sigmoid activation for binary classification\n])\n\nmodel.summary()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Compile the model\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['accuracy'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_ds,\n    validation_data=valid_ds,\n    epochs=20,\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##TEST##","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import layers, Sequential\n\nnum_classes = 2\n\nmodel = Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(256, 256, 3)),# Adjust input shape for grayscale images\n\n    layers.Conv2D(16, 3, padding='same', activation='relu'),  \n    layers.MaxPooling2D(),   \n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(), \n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(1, activation='sigmoid')  # Sigmoid activation for binary classification\n])\n\nmodel.summary()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Compile the model\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['accuracy'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_ds,\n    validation_data=valid_ds,\n    epochs=20,\n#     callbacks=callbacks\n)\n","metadata":{"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":"num_classes = 2\n\nmodel = Sequential([\n  layers.experimental.preprocessing.Rescaling(1./255, input_shape=(512, 512, 3)),\n  layers.Conv2D(16, 3, padding='same', activation='relu'),  \n  layers.MaxPooling2D(),   \n  layers.Conv2D(32, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Dropout(0.2),\n  layers.Conv2D(64, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Flatten(),\n  layers.Dense(128, activation='relu'),\n  layers.Dense(num_classes)\n])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#####\nnum_classes=2\nmodel = Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(512, 512, 3)),\n    layers.Conv2D(16, 3, padding='same', activation='relu'),  \n    layers.MaxPooling2D(),   \n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(num_classes)\n])\n\n\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam',\n              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n              metrics=['accuracy'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class myCallback(tf.keras.callbacks.Callback):\n    # Define the method that checks the accuracy at the end of each epoch\n    def on_epoch_end(self, epoch, logs={}):\n        if logs.get('accuracy') is not None and logs.get('accuracy') >= 0.95:\n            print(\"\\nReached 99.5% accuracy so cancelling training!\") \n            # Stop training once the above condition is met\n            self.model.stop_training = True","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs=15\nhistory = model.fit(\n  train_ds,\n  validation_data=valid_ds,\n  epochs=epochs\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Evaluate the model\ntest_loss, test_acc = model.evaluate(test_dataset)\nprint(\"Test Accuracy:\", test_acc)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models\n\n# Define CNN model architecture\nmodel = models.Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(512, 512, 3)),  # Rescaling layer\n    layers.Conv2D(32, (3, 3), activation='relu'),\n    layers.MaxPooling2D((2, 2)),\n    layers.Conv2D(64, (3, 3), activation='relu'),\n    layers.MaxPooling2D((2, 2)),\n    layers.Conv2D(128, (3, 3), activation='relu'),\n    layers.MaxPooling2D((2, 2)),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dropout(0.5),\n    layers.Dense(1, activation='sigmoid')  # Sigmoid for binary classification\n])\n\n\n# # Train the model\n# history = model.fit(train_dataset,\n#                     epochs=epochs,\n#                     validation_data=validation_dataset)\n\n# Evaluate the model\n# test_loss, test_acc = model.evaluate(test_dataset)\n# print(\"Test Accuracy:\", test_acc)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Compile the model\nmodel.compile(optimizer='adam',\n              loss='binary_crossentropy',\n              metrics=['accuracy'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_ds,\n    validation_data=valid_ds,\n    epochs=20,\n#     callbacks=callbacks\n)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = history.history['accuracy']\nval_accuracy = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (15,10))\n\nplt.subplot(2, 2, 1)\nplt.plot(accuracy, label = \"Training Accuracy\")\nplt.plot(val_accuracy, label = \"Validation Accuracy\")\nplt.ylim(0.4, 1)\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Accuracy\")\nplt.xlabel('epoch')\nplt.ylabel('accuracy')\n\n\nplt.subplot(2, 2, 2)\nplt.plot(loss, label = \"Training Loss\")\nplt.plot(val_loss, label = \"Validation Loss\")\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Loss\")\nplt.xlabel('epoch')\nplt.ylabel('loss')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"######\nnum_classes=2\nfrom tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau\n\n# Define callbacks for early stopping and learning rate reduction\nearly_stopping = EarlyStopping(monitor='val_accuracy', patience=5, restore_best_weights=True)\nreduce_lr = ReduceLROnPlateau(monitor='val_accuracy', factor=0.2, patience=3, min_lr=1e-6)\n\ncallbacks = [early_stopping, reduce_lr]\n\n# Define the model architecture\nmodel = Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(512, 512, 3)),\n    layers.Conv2D(16, 3, padding='same', activation='relu'),  \n    layers.MaxPooling2D(),   \n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Dropout(0.2),\n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(num_classes)\n])\n\n\n# Train the model with callbacks\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#####\n# Compile the model\nmodel.compile(optimizer='adam',\n              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n              metrics=['accuracy'])\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#####\nhistory = model.fit(\n    train_ds,\n    validation_data=valid_ds,\n    epochs=20,\n    callbacks=callbacks\n)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model = ResNet50V2(weights = 'imagenet', input_shape = (512, 512, 3), include_top = False)\n\nfor layer in base_model.layers:\n    layer.trainable = False\n    \nmodel = Sequential()\nmodel.add(base_model)\nmodel.add(GlobalAveragePooling2D())\nmodel.add(Dense(128, activation = 'relu'))\nmodel.add(Dropout(0.2))\nmodel.add(Dense(1, activation = 'sigmoid'))\n\nmodel.compile(optimizer = \"adam\", loss = 'binary_crossentropy', metrics = [\"accuracy\"])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"callback = tf.keras.callbacks.EarlyStopping(monitor = \"val_loss\", mode = \"min\", patience = 4)\n\nhistory = model.fit(train_ds, validation_data = valid_ds, epochs = 15, callbacks = callback)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = history.history['accuracy']\nval_accuracy = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (15,10))\n\nplt.subplot(2, 2, 1)\nplt.plot(accuracy, label = \"Training Accuracy\")\nplt.plot(val_accuracy, label = \"Validation Accuracy\")\nplt.ylim(0.4, 1)\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Accuracy\")\nplt.xlabel('epoch')\nplt.ylabel('accuracy')\n\n\nplt.subplot(2, 2, 2)\nplt.plot(loss, label = \"Training Loss\")\nplt.plot(val_loss, label = \"Validation Loss\")\nplt.legend(['Train', 'Validation'], loc = 'upper left')\nplt.title(\"Training vs Validation Loss\")\nplt.xlabel('epoch')\nplt.ylabel('loss')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\nimages = []\n\nfor img_file in random.sample(train_images, 25):  # it is fixed to 25 random predictions - if you want to change it remeber to change plot_roi as well\n    \n    # Read file from file\n    frame = cv2.imread(img_file)\n    \n    # Make prediction\n    detections = model(frame)\n    \n    # Convert results to Pandas style\n    results = detections.pandas().xyxy[0].to_dict(orient=\"records\")\n    \n    # Plot result (in 99.99% it predicts only one instance - certainly you can assure that only best prediction is used)\n    for result in results:\n        images.append(cv2.rectangle(frame, (int(result['xmin']), int(result['ymin'])), (int(result['xmax']), int(result['ymax'])), (255,0,0), 4))\n\n# Plot result\nfig, axes = plt.subplots(5, 5, figsize=(20,20))\n    \nfor idx, image in enumerate(images):\n    i = idx % 5 \n    j = idx // 5 \n    axes[i, j].imshow(image)\n\nplt.subplots_adjust(wspace=0, hspace=.2)\nplt.show()","metadata":{"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":"code","source":"import matplotlib.pyplot as plt\nimport os\n\n# Define the path to the folder containing the images\nfolder_path = '/kaggle/working/input_transformed/1/'\n\n# Get a list of image files in the folder\nimage_files = os.listdir(folder_path)\n\n# Display the images\nnum_images_to_display = 5  # You can change this number as per your requirement\nfig, axes = plt.subplots(1, num_images_to_display, figsize=(20, 4))\n\nfor i in range(num_images_to_display):\n    # Read the image\n    image_path = os.path.join(folder_path, image_files[i])\n    image = plt.imread(image_path)\n    image=image/255.0\n    print(image)\n    \n    # Display the image\n    axes[i].imshow(image)\n    axes[i].axis('off')\n\nplt.show()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(image_files)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(image_files))\nprint(image_files[1])\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}