{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":45867,"databundleVersionId":6924515,"sourceType":"competition"},{"sourceId":6774400,"sourceType":"datasetVersion","datasetId":3895136},{"sourceId":6774553,"sourceType":"datasetVersion","datasetId":3898019},{"sourceId":6862644,"sourceType":"datasetVersion","datasetId":3944110},{"sourceId":6984590,"sourceType":"datasetVersion","datasetId":4014175},{"sourceId":7143890,"sourceType":"datasetVersion","datasetId":4123551},{"sourceId":7173990,"sourceType":"datasetVersion","datasetId":4145347}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!ls /kaggle/input/pyvips-python-and-deb-package-gpu\n# intall the deb packages\n!yes | dpkg -i --force-depends /kaggle/input/pyvips-python-and-deb-package/linux_packages/archives/*.deb\n# install the python wrapper\n!pip install pyvips -f /kaggle/input/pyvips-python-and-deb-package/python_packages/ --no-index\n!pip list | grep pyvips\n\nfrom IPython import display\ndisplay.clear_output()\n","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:07:40.568765Z","iopub.execute_input":"2023-12-12T04:07:40.569158Z","iopub.status.idle":"2023-12-12T04:08:57.843936Z","shell.execute_reply.started":"2023-12-12T04:07:40.569123Z","shell.execute_reply":"2023-12-12T04:08:57.842301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os, glob\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport re\n\nDATASET_FOLDER = \"/kaggle/input/UBC-OCEAN/\"\nIMAGES_FOLDER = \"./test_tiles\"\n\nos.environ['VIPS_CONCURRENCY'] = '4'\nos.environ['VIPS_DISC_THRESHOLD'] = '15gb'","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:08:57.84644Z","iopub.execute_input":"2023-12-12T04:08:57.846837Z","iopub.status.idle":"2023-12-12T04:08:58.244195Z","shell.execute_reply.started":"2023-12-12T04:08:57.846797Z","shell.execute_reply":"2023-12-12T04:08:58.243344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nimport numpy as np\nimport pandas as pd\nfrom PIL import Image\nimport io\n","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:08:58.245693Z","iopub.execute_input":"2023-12-12T04:08:58.246335Z","iopub.status.idle":"2023-12-12T04:09:11.744335Z","shell.execute_reply.started":"2023-12-12T04:08:58.246297Z","shell.execute_reply":"2023-12-12T04:09:11.743293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch \nmodel_Net = torch.jit.load('/kaggle/input/stainnet/model_scripted.pt')\n","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:11.746769Z","iopub.execute_input":"2023-12-12T04:09:11.747519Z","iopub.status.idle":"2023-12-12T04:09:14.916864Z","shell.execute_reply.started":"2023-12-12T04:09:11.74748Z","shell.execute_reply":"2023-12-12T04:09:14.915129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n#model_Net = StainNet()\n\nmodel_Net.load_state_dict(torch.load(\"/kaggle/input/stainnet/StainNet-Public_layer3_ch32 (1).pth\",map_location=torch.device('cpu')))\nmodel_Net.eval()\n\ndef norm(image):\n    image = np.array(image).astype(np.float32)\n    image = image.transpose((2, 0, 1))\n    image = ((image / 255) - 0.5) / 0.5\n    image=image[np.newaxis, ...]\n    image=torch.from_numpy(image)\n    return image\n\ndef un_norm(image):\n    image = image.cpu().detach().numpy()[0]\n    image = ((image * 0.5 + 0.5) * 255).astype(np.uint8).transpose((1,2,0))\n    return image\n\ndef stain_normalize1(source, verbose=False):\n    with torch.no_grad():\n        img_net=model_Net(norm(source))\n        img_net=un_norm(img_net)\n        if verbose: plt.imshow(img_net); plt.show()\n        return img_net","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:14.918498Z","iopub.execute_input":"2023-12-12T04:09:14.91924Z","iopub.status.idle":"2023-12-12T04:09:14.957047Z","shell.execute_reply.started":"2023-12-12T04:09:14.919198Z","shell.execute_reply":"2023-12-12T04:09:14.955737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob \nimage_list = glob.glob(\"/kaggle/input/ubc-ovarian-cancer-competition-supplemental-masks/*.png\")","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:14.958669Z","iopub.execute_input":"2023-12-12T04:09:14.959791Z","iopub.status.idle":"2023-12-12T04:09:15.000251Z","shell.execute_reply.started":"2023-12-12T04:09:14.959746Z","shell.execute_reply":"2023-12-12T04:09:14.999024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import re \nimagepathlist=[]\nfor imagepath in image_list :\n    \n\n    # Use regular expression to extract the picture ID\n    match = re.search(r'(\\d+).png$', imagepath)\n\n    if match:\n        picture_id = match.group(1)\n      \n        imagepathlist.append(int(picture_id))\n    else:\n        print(\"Picture ID not found in the input string.\")\n","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:15.001768Z","iopub.execute_input":"2023-12-12T04:09:15.002192Z","iopub.status.idle":"2023-12-12T04:09:15.009498Z","shell.execute_reply.started":"2023-12-12T04:09:15.002155Z","shell.execute_reply":"2023-12-12T04:09:15.008504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ntrain_df=pd.read_csv(\"/kaggle/input/UBC-OCEAN/train.csv\")\nsupp_df=train_df[train_df['image_id'].isin(imagepathlist)]\n\nsupp_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:15.010889Z","iopub.execute_input":"2023-12-12T04:09:15.01156Z","iopub.status.idle":"2023-12-12T04:09:15.064562Z","shell.execute_reply.started":"2023-12-12T04:09:15.011522Z","shell.execute_reply":"2023-12-12T04:09:15.063435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nlabel_to_be_replace=['CC','EC','HGSC','LGSC','MC','Others']\nlabel_to_be_replaced=[0,1,2,3,4,5]\nsupp_df.loc[:, 'label'] = supp_df['label'].replace(label_to_be_replace, label_to_be_replaced)\nsupp_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:15.065977Z","iopub.execute_input":"2023-12-12T04:09:15.066327Z","iopub.status.idle":"2023-12-12T04:09:15.080404Z","shell.execute_reply.started":"2023-12-12T04:09:15.066294Z","shell.execute_reply":"2023-12-12T04:09:15.079564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pyvips\nimport numpy as np\nimport random\nfrom PIL import Image\nfrom IPython import display\nfrom tqdm import tqdm\ndef extract_image_tiles(\n    p_img,label, folder, size: int = 2048, scale: float = 0.5,\n    drop_thr: float = 0.6, white_thr: int = 240, max_samples: int = 50\n) -> list:\n    \n    name, _ = os.path.splitext(os.path.basename(p_img))\n \n    im = pyvips.Image.new_from_file(p_img)\n    w = h = size\n    # https://stackoverflow.com/a/47581978/4521646\n   \n    \n    # random subsample\n\n    count=0\n    files = []\n        # Read the list from the JSON file\n    with open(f\"/kaggle/input/listjson-of-annotated-files/indexlist/{name}.json\", 'r') as file:\n        loaded_list = json.load(file)\n\n    random.shuffle(loaded_list)\n    for y, y_, x, x_,cell_type in tqdm(loaded_list):        # https://libvips.github.io/pyvips/vimage.html#pyvips.Image.crop\n        if cell_type==0:\n            count+=1\n            folder=\"/kaggle/working/test_tiles/undefined\"\n            p_img = os.path.join(folder, f\"label-{label}-{int(x_ / w)}-{int(y_ / h)}.png\")\n        if count>100:\n                continue\n    #for y, y_, x, x_ in tqdm(idxs, total=len(idxs)):        # https://libvips.github.io/pyvips/vimage.html#pyvips.Image.crop\n        tile = im.crop(x, y, min(w, im.width - x), min(h, im.height - y)).numpy()[..., :3]\n        if tile.shape[:2] != (h, w):\n            tile_ = tile\n            tile_size = (h, w) if tile.ndim == 2 else (h, w, tile.shape[2])\n            tile = np.zeros(tile_size, dtype=tile.dtype)\n            tile[:tile_.shape[0], :tile_.shape[1], ...] = tile_\n        black_bg = np.sum(tile, axis=2) == 0\n        tile[black_bg, :] = 255\n        tile=stain_normalize1(tile)\n        \n        if cell_type==1:\n            folder=\"/kaggle/working/test_tiles/tumourous/\"\n            p_img = os.path.join(folder, f\"name-{name}label-{label}-{int(x_ / w)}-{int(y_ / h)}.png\")\n        elif cell_type==2:\n            folder=\"/kaggle/working/test_tiles/necrosis/\"\n            p_img = os.path.join(folder, f\"name-{name}-{int(x_ / w)}-{int(y_ / h)}.png\")\n        elif cell_type==3:\n            folder=\"/kaggle/working/test_tiles/healthy/\"\n            p_img = os.path.join(folder, f\"name-{name}-{int(x_ / w)}-{int(y_ / h)}.png\")\n        \n        # print(tile.shape, tile.dtype, tile.min(), tile.max())\n        new_size = 224, 224\n        Image.fromarray(tile).resize(new_size, Image.LANCZOS).save(p_img)\n        #Image.fromarray(tile).save(p_img)\n\n        files.append(p_img)\n        # need to set counter check as some empty tiles could be skipped earlier\n        if len(files) >= max_samples:\n            break\n    return files","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:23:28.133294Z","iopub.execute_input":"2023-12-12T04:23:28.133778Z","iopub.status.idle":"2023-12-12T04:23:28.151304Z","shell.execute_reply.started":"2023-12-12T04:23:28.133741Z","shell.execute_reply":"2023-12-12T04:23:28.149822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def extract_prune_tiles(\n    path_img: str,label:str, folder: str, size: int = 2048, scale: float = 0.25,\n    drop_thr: float = 0.6,white_thr: int=0.5, max_samples: int = 12000\n) -> str:\n    print(f\"processing: {path_img}\")\n    name, _ = os.path.splitext(os.path.basename(path_img))\n    folder = os.path.join(folder, name)\n#     os.makedirs(folder, exist_ok=True)\n    os.makedirs(\"/kaggle/working/test_tiles/undefined\", exist_ok=True)\n    os.makedirs(\"/kaggle/working/test_tiles/tumourous\", exist_ok=True)\n    os.makedirs(\"/kaggle/working/test_tiles/necrosis\", exist_ok=True)\n    os.makedirs(\"/kaggle/working/test_tiles/healthy\", exist_ok=True)\n    tiles = extract_image_tiles(\n        path_img,label, folder, size=size, scale=scale,\n        drop_thr=drop_thr,white_thr=225 ,max_samples=max_samples)\n    \n    return tiles","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:24:17.000223Z","iopub.execute_input":"2023-12-12T04:24:17.000709Z","iopub.status.idle":"2023-12-12T04:24:17.009865Z","shell.execute_reply.started":"2023-12-12T04:24:17.000654Z","shell.execute_reply":"2023-12-12T04:24:17.008847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfull_df=pd.read_csv(\"/kaggle/input/cancerdatasetwithpath/cancerdf.csv\")\nfull_df=full_df[full_df[\"is_tma\"]==True]\nfull_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:15.375164Z","iopub.execute_input":"2023-12-12T04:09:15.37554Z","iopub.status.idle":"2023-12-12T04:09:15.411232Z","shell.execute_reply.started":"2023-12-12T04:09:15.375508Z","shell.execute_reply":"2023-12-12T04:09:15.410379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\n\ndef record(id):\n    folderpath='/kaggle/working/test_tiles'\n    folder = glob.glob(os.path.join(folderpath, \"*\"))\n    image_list=[]\n    for path in folder:\n        image_list= image_list+(glob.glob(os.path.join(path,\"*.png\")))\n        print(len(image_list))\n\n    random.shuffle(image_list)\n    path=f\"{id}xtwentyimages.tfrecords\"\n    with tf.io.TFRecordWriter(path) as writer:\n        for imagepath in image_list:\n\n            pattern = r'label-(\\d+)-\\d+-\\d+\\.png'\n\n            match = re.search(pattern, imagepath)\n            label = match.group(1)\n            label=int(label)\n         \n            image = Image.open(imagepath)\n\n            bytes_buffer = io.BytesIO()\n            image.convert(\"RGB\").save(bytes_buffer, \"JPEG\")\n            image_bytes = bytes_buffer.getvalue()\n\n            bytes_feature = tf.train.Feature(bytes_list=tf.train.BytesList(value=[image_bytes]))\n            class_feature = tf.train.Feature(int64_list=tf.train.Int64List(value=[label]))\n\n            example = tf.train.Example(\n              features=tf.train.Features(feature={\n                  \"image\": bytes_feature,\n                  \"class\": class_feature\n              })\n            )\n\n            writer.write(example.SerializeToString())\n\n            image.close()\n    for directory in folder:\n        try:\n            shutil.rmtree(directory)\n            print(f\"Directory '{directory}' removed successfully.\")\n        except OSError as e:\n            print(f\"Error removing directory '{directory}': {e}\")\n","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:09:15.412418Z","iopub.execute_input":"2023-12-12T04:09:15.412764Z","iopub.status.idle":"2023-12-12T04:09:15.424459Z","shell.execute_reply.started":"2023-12-12T04:09:15.412735Z","shell.execute_reply":"2023-12-12T04:09:15.423036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nimport json\nfor idx,row in supp_df.iterrows():\n        path=f\"/kaggle/input/UBC-OCEAN/train_images/{row['image_id']}.png\"\n#         path=row['Image_path']\n        label=row['label']\n       \n        folder_tiles = extract_prune_tiles(path,label, IMAGES_FOLDER, size=1024, scale=1,drop_thr=1,white_thr=222,max_samples=10000)\n      \n# record(\"test\")\n# print(f\"found tiles: {len(dataset)}\")\n\n# # quick view\n# fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(10, 10))\n# for i in range(9):\n#     img = dataset[i]\n#     axes[i // 3, i % 3].imshow(img)\n# fig.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:24:20.481997Z","iopub.execute_input":"2023-12-12T04:24:20.482407Z","iopub.status.idle":"2023-12-12T04:43:21.90424Z","shell.execute_reply.started":"2023-12-12T04:24:20.482372Z","shell.execute_reply":"2023-12-12T04:43:21.902681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# record(\"test\")","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:20.383866Z","iopub.execute_input":"2023-12-12T04:21:20.384632Z","iopub.status.idle":"2023-12-12T04:21:20.389637Z","shell.execute_reply.started":"2023-12-12T04:21:20.384587Z","shell.execute_reply":"2023-12-12T04:21:20.388325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# record(idx+previousbatch)","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:20.391203Z","iopub.execute_input":"2023-12-12T04:21:20.391649Z","iopub.status.idle":"2023-12-12T04:21:20.400042Z","shell.execute_reply.started":"2023-12-12T04:21:20.391604Z","shell.execute_reply":"2023-12-12T04:21:20.399008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# dataset = TilesFolderDataset(\"/kaggle/working/test_tiles/1952\")\n# print(f\"found tiles: {len(dataset)}\")\n\n# # quick view\n# fig, axes = plt.subplots(nrows=10, ncols=10, figsize=(10, 10))\n# axes=axes.flatten()\n# for i in range(100):\n#     ax=axes[i]\n#     img = dataset[i+2000]\n#     ax.imshow(img)\n#     ax.axis('off')\n# fig.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:20.401964Z","iopub.execute_input":"2023-12-12T04:21:20.402458Z","iopub.status.idle":"2023-12-12T04:21:20.411091Z","shell.execute_reply.started":"2023-12-12T04:21:20.402413Z","shell.execute_reply":"2023-12-12T04:21:20.409791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import shutil \n# shutil.rmtree('/kaggle/working/')","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:20.412561Z","iopub.execute_input":"2023-12-12T04:21:20.413235Z","iopub.status.idle":"2023-12-12T04:21:20.422041Z","shell.execute_reply.started":"2023-12-12T04:21:20.413183Z","shell.execute_reply":"2023-12-12T04:21:20.421006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nimg=glob.glob(\"/kaggle/working/test_tiles/36302/*.png\")\nprint(img)\nfig,axes=plt.subplots(2,2,figsize=(10,10))\naxes=axes.flatten()\nfor id,im in enumerate(img):\n    ax=axes[id]\n    image=plt.imread(im)\n    ax.imshow(image)\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:20.423787Z","iopub.execute_input":"2023-12-12T04:21:20.424466Z","iopub.status.idle":"2023-12-12T04:21:21.134914Z","shell.execute_reply.started":"2023-12-12T04:21:20.424413Z","shell.execute_reply":"2023-12-12T04:21:21.133764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# import os\n# import glob\n# import random\n# import re\n# import io\n# from PIL import Image\n# import tensorflow as tf\n\n# def record():\n#     folderpath = '/kaggle/working/test_tiles'\n#     folder = glob.glob(os.path.join(folderpath, \"*\"))\n#     image_list = []\n\n#     for path in folder:\n#         image_list = image_list + (glob.glob(os.path.join(path, \"*.png\")))\n#         print(len(image_list))\n\n#     random.shuffle(image_list)\n\n#     # Open the TFRecord file in append mode ('ab')\n#     with tf.io.TFRecordWriter(\"caltech_dataset.tfrecords\", options='ab') as writer:\n#         for imagepath in image_list:\n#             pattern = r'label-(\\d+)-\\d+-\\d+\\.png'\n#             match = re.search(pattern, imagepath)\n#             label = match.group(1)\n#             label = int(label)\n#             image = Image.open(imagepath)\n\n#             bytes_buffer = io.BytesIO()\n#             image.convert(\"RGB\").save(bytes_buffer, \"JPEG\")\n#             image_bytes = bytes_buffer.getvalue()\n\n#             bytes_feature = tf.train.Feature(bytes_list=tf.train.BytesList(value=[image_bytes]))\n#             class_feature = tf.train.Feature(int64_list=tf.train.Int64List(value=[label]))\n\n#             example = tf.train.Example(\n#                 features=tf.train.Features(feature={\n#                     \"image\": bytes_feature,\n#                     \"class\": class_feature\n#                 })\n#             )\n\n#             writer.write(example.SerializeToString())\n\n#             image.close()\n\n#     # Removing directories after processing\n#     for directory in folder:\n#         try:\n#             shutil.rmtree(directory)\n#             print(f\"Directory '{directory}' removed successfully.\")\n#         except OSError as e:\n#             print(f\"Error removing directory '{directory}': {e}\")\n","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:21.136373Z","iopub.execute_input":"2023-12-12T04:21:21.136756Z","iopub.status.idle":"2023-12-12T04:21:21.142771Z","shell.execute_reply.started":"2023-12-12T04:21:21.136722Z","shell.execute_reply":"2023-12-12T04:21:21.141694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## code to extract the images from tfr record\n","metadata":{}},{"cell_type":"code","source":"# image_feature_description = {\n#     \"image\": tf.io.FixedLenFeature([], tf.string), \n#     \"class\": tf.io.FixedLenFeature([], tf.int64), \n#     }\n# def _parse_data(unparsed_example):\n#     return tf.io.parse_single_example(unparsed_example, image_feature_description)\n\n# def _bytestring_to_pixels(parsed_example):\n#     byte_string = parsed_example['image']\n#     image = tf.io.decode_image(byte_string)\n# #     image = tf.reshape(image, [256, 256, 3])\n#     return image, parsed_example[\"class\"]\n# AUTOTUNE = tf.data.AUTOTUNE\n# def load_and_extract_images(filepath):\n#     dataset = tf.data.TFRecordDataset(filepath)\n#     dataset = dataset.map(_parse_data, num_parallel_calls=AUTOTUNE)\n#     dataset = dataset.map(_bytestring_to_pixels, num_parallel_calls=AUTOTUNE) # .cache()\n#     return dataset\n\n# caltech_dataset = load_and_extract_images(\"/kaggle/working/89xtwentyimages.tfrecords\")\n\n# train_dataset = caltech_dataset.take(90)\n\n# cropsize=256\n# def _train_data_preprocess_and_augment(image, label):\n# #     image = tf.cast(image, tf.float32)\n# #     image = tf.image.random_crop(image, size=[crop_size, crop_size, 3])\n    \n#     return image, label\n# train_preprocessed_augmented = train_dataset.map(_train_data_preprocess_and_augment)\n# fig,axes=plt.subplots(8,4,figsize=(10,10))\n# axes=axes.flatten()\n# for(images, label_batch) in train_preprocessed_augmented.batch(32):\n#     for i in range(32):\n#         ax=axes[i] \n#         ax.imshow(images[i])\n#         ax.set_title(f\"label-{label_batch[i]}\")\n\n#     plt.axis(\"off\")\n#     plt.show()\n#     break\n        \n    ","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:21.14429Z","iopub.execute_input":"2023-12-12T04:21:21.144765Z","iopub.status.idle":"2023-12-12T04:21:21.158673Z","shell.execute_reply.started":"2023-12-12T04:21:21.14472Z","shell.execute_reply":"2023-12-12T04:21:21.157808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# image=plt.imread(\"/kaggle/working/test_tiles/66/label-3-15-9.png\")\n# plt.imshow(image)","metadata":{"execution":{"iopub.status.busy":"2023-12-12T04:21:21.160551Z","iopub.execute_input":"2023-12-12T04:21:21.161414Z","iopub.status.idle":"2023-12-12T04:21:21.173181Z","shell.execute_reply.started":"2023-12-12T04:21:21.161375Z","shell.execute_reply":"2023-12-12T04:21:21.171859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}