{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":13836,"databundleVersionId":1718836,"sourceType":"competition"},{"sourceId":1715591,"sourceType":"datasetVersion","datasetId":1017454},{"sourceId":1715611,"sourceType":"datasetVersion","datasetId":1017466},{"sourceId":8868008,"sourceType":"datasetVersion","datasetId":5336924},{"sourceId":8877458,"sourceType":"datasetVersion","datasetId":5343497}],"dockerImageVersionId":30039,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# About this notebook  \n- Visualize ViT Attention Map\n- ViT github is [here](https://github.com/tczhangzhi/VisionTransformer-Pytorch).\n(I modified a little for attention map. please see this [issue](https://github.com/tczhangzhi/VisionTransformer-Pytorch/issues/1#issuecomment-739138519).)\n\n\nI want to show that Attention Map for cassava.\n- I just show a few sample in 2019 train dataset.\n\nYou can check my pretrained ViT weight in [here](https://www.kaggle.com/piantic/cassava-vit-b-16).\n\n### If this kernel is useful, feel free to upvote:)","metadata":{}},{"cell_type":"markdown","source":"# Vision Transformer (ViT) : Attention Map","metadata":{}},{"cell_type":"markdown","source":"This is the Attention Map example.\n- Reference is [here](https://github.com/jeonsworld/ViT-pytorch/blob/main/visualize_attention_map.ipynb).","metadata":{}},{"cell_type":"markdown","source":"<img src='https://user-images.githubusercontent.com/6073256/101206904-2a338f00-36b3-11eb-8920-f617abab1604.png'>","metadata":{}},{"cell_type":"markdown","source":"Next, we will see the attention map for cassava leaf!","metadata":{}},{"cell_type":"markdown","source":"# Import libraries","metadata":{}},{"cell_type":"code","source":"import sys\n\npackage_path = '../input/visiontransformerpytorch121/VisionTransformer-Pytorch'\nsys.path.append(package_path)\n\nimport os\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport torch\nimport torch.nn as nn\nimport torchvision.models as models\n\nimport cv2\nfrom PIL import Image\nfrom torchvision import transforms\n\nfrom vision_transformer_pytorch import VisionTransformer","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-07-06T08:16:58.009203Z","iopub.execute_input":"2024-07-06T08:16:58.009496Z","iopub.status.idle":"2024-07-06T08:16:58.015512Z","shell.execute_reply.started":"2024-07-06T08:16:58.009468Z","shell.execute_reply":"2024-07-06T08:16:58.014682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transform = transforms.Compose([\n    transforms.Resize((384, 384)),\n    transforms.ToTensor(),\n    transforms.Normalize(\n        mean=[0.485, 0.456, 0.406],\n        std=[0.229, 0.224, 0.225],\n    ),\n])","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:58.017023Z","iopub.execute_input":"2024-07-06T08:16:58.017304Z","iopub.status.idle":"2024-07-06T08:16:58.029026Z","shell.execute_reply.started":"2024-07-06T08:16:58.017276Z","shell.execute_reply":"2024-07-06T08:16:58.028261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Helper function","metadata":{}},{"cell_type":"code","source":"# ====================================================\n# Helper functions\n# ====================================================\ndef load_state(model_path):\n    state_dict = torch.load(model_path)['model']\n    state_dict = {k[7:] if k.startswith('module.') else k: state_dict[k] for k in state_dict.keys()}\n    state_dict = {k[6:] if k.startswith('model.') else k: state_dict[k] for k in state_dict.keys()}\n\n    return state_dict","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-07-06T08:16:58.030269Z","iopub.execute_input":"2024-07-06T08:16:58.030649Z","iopub.status.idle":"2024-07-06T08:16:58.037874Z","shell.execute_reply.started":"2024-07-06T08:16:58.030613Z","shell.execute_reply":"2024-07-06T08:16:58.037076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_attention_map(img, get_mask=False):\n    x = transform(img)\n    x.size()\n\n    logits, att_mat = model(x.unsqueeze(0))\n\n    att_mat = torch.stack(att_mat).squeeze(1)\n\n    # Average the attention weights across all heads.\n    att_mat = torch.mean(att_mat, dim=1)\n\n    # To account for residual connections, we add an identity matrix to the\n    # attention matrix and re-normalize the weights.\n    residual_att = torch.eye(att_mat.size(1))\n    aug_att_mat = att_mat + residual_att\n    aug_att_mat = aug_att_mat / aug_att_mat.sum(dim=-1).unsqueeze(-1)\n\n    # Recursively multiply the weight matrices\n    joint_attentions = torch.zeros(aug_att_mat.size())\n    joint_attentions[0] = aug_att_mat[0]\n\n    for n in range(1, aug_att_mat.size(0)):\n        joint_attentions[n] = torch.matmul(aug_att_mat[n], joint_attentions[n-1])\n\n    v = joint_attentions[-1]\n    grid_size = int(np.sqrt(aug_att_mat.size(-1)))\n    mask = v[0, 1:].reshape(grid_size, grid_size).detach().numpy()\n    if get_mask:\n        result = cv2.resize(mask / mask.max(), img.size)\n    else:        \n        mask = cv2.resize(mask / mask.max(), img.size)[..., np.newaxis]\n        result = (mask * img).astype(\"uint8\")\n    \n    return result\n\ndef plot_attention_map(original_img, att_map):\n    fig, (ax1,ax2) = plt.subplots(ncols=2, figsize=(16, 16))\n    ax1.set_title('Original')\n    ax2.set_title('Attention Map Last Layer')\n    _ = ax1.imshow(original_img)\n    _ = ax2.imshow(att_map)\n\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-07-06T08:16:58.039081Z","iopub.execute_input":"2024-07-06T08:16:58.039354Z","iopub.status.idle":"2024-07-06T08:16:58.055581Z","shell.execute_reply.started":"2024-07-06T08:16:58.039327Z","shell.execute_reply":"2024-07-06T08:16:58.054856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load ViT Model","metadata":{}},{"cell_type":"code","source":"model = VisionTransformer.from_name('ViT-B_16', num_classes=5)\nstate = load_state('../input/cassava-vit-b-16/ViT-B_16_fold0.pth')\n\n# \nmodel.load_state_dict(state)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:58.056664Z","iopub.execute_input":"2024-07-06T08:16:58.056945Z","iopub.status.idle":"2024-07-06T08:16:59.225502Z","shell.execute_reply.started":"2024-07-06T08:16:58.056903Z","shell.execute_reply":"2024-07-06T08:16:59.224550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualize Attention Map","metadata":{}},{"cell_type":"code","source":"label_map = pd.read_json('../input/cassava-leaf-disease-classification/label_num_to_disease_map.json', \n                         orient='index')\n\ndisplay(label_map)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.227016Z","iopub.execute_input":"2024-07-06T08:16:59.227398Z","iopub.status.idle":"2024-07-06T08:16:59.238953Z","shell.execute_reply.started":"2024-07-06T08:16:59.227359Z","shell.execute_reply":"2024-07-06T08:16:59.238207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## CBB - Class0","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img1 = Image.open(\"/kaggle/input/testimages/img1.jpg\")\nimg2 = Image.open(\"/kaggle/input/testimages/img2.jpg\")\n\nresult1 = get_attention_map(img1)\nresult2 = get_attention_map(img2)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:23:11.279412Z","iopub.execute_input":"2024-07-06T08:23:11.279775Z","iopub.status.idle":"2024-07-06T08:23:13.759644Z","shell.execute_reply.started":"2024-07-06T08:23:11.279746Z","shell.execute_reply":"2024-07-06T08:23:13.758833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_attention_map(img1,result1)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:23:16.934695Z","iopub.execute_input":"2024-07-06T08:23:16.935042Z","iopub.status.idle":"2024-07-06T08:23:17.508692Z","shell.execute_reply.started":"2024-07-06T08:23:16.935011Z","shell.execute_reply":"2024-07-06T08:23:17.507826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_attention_map(img2, result2)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:23:25.959361Z","iopub.execute_input":"2024-07-06T08:23:25.959753Z","iopub.status.idle":"2024-07-06T08:23:26.506482Z","shell.execute_reply.started":"2024-07-06T08:23:25.959720Z","shell.execute_reply":"2024-07-06T08:23:26.505536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Check mask for Attention Map","metadata":{}},{"cell_type":"code","source":"result1 = get_attention_map(img1, True)\nresult2 = get_attention_map(img2, True)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:05:25.273371Z","iopub.execute_input":"2024-07-06T09:05:25.273762Z","iopub.status.idle":"2024-07-06T09:05:27.279270Z","shell.execute_reply.started":"2024-07-06T09:05:25.273730Z","shell.execute_reply":"2024-07-06T09:05:27.278426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_attention_map(img1, result1)\n\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:23:52.725011Z","iopub.execute_input":"2024-07-06T08:23:52.725368Z","iopub.status.idle":"2024-07-06T08:23:53.278438Z","shell.execute_reply.started":"2024-07-06T08:23:52.725331Z","shell.execute_reply":"2024-07-06T08:23:53.277545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_attention_map(img2, result2)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:23:53.370907Z","iopub.execute_input":"2024-07-06T08:23:53.371273Z","iopub.status.idle":"2024-07-06T08:23:53.879192Z","shell.execute_reply.started":"2024-07-06T08:23:53.371242Z","shell.execute_reply":"2024-07-06T08:23:53.878231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\nfrom PIL import Image\nfrom scipy.fftpack import fft2, ifft2, fftshift, ifftshift\n\n# Load the image\n\n# Convert the image to grayscale and to a NumPy array\nimage = np.array(img1.convert('L'))\n\n# Display the image\nplt.imshow(image, cmap='gray')\nplt.title('Original Image')\nplt.show()\n\nshearlet_transform_dict = dict()\n\ndef create_shearlet_filter(size, scale, shear, angles):\n    nx, ny = size\n    X, Y = np.meshgrid(np.fft.fftfreq(nx), np.fft.fftfreq(ny), indexing='ij')\n\n    # Apply scaling\n    X = X * (2 ** scale)\n    Y = Y * (2 ** scale)\n\n    # Apply shear\n    X = X + shear * Y\n\n    # Create a Gaussian window (can be other windows too)\n    sigma = 0.1\n    window = np.exp(- (X**2 + Y**2) / (2 * sigma**2))\n\n    # Rotate angles to obtain the shearlet filter\n    angle_step = 2 * np.pi / angles\n    filters = []\n    for angle in range(angles):\n        theta = angle * angle_step\n        rotated_window = window * np.exp(1j * theta * (X + 1j * Y))\n        filters.append(rotated_window)\n\n    return filters\n\ndef shearlet_transform(image, scales, angles):\n    nx, ny = image.shape\n    coeffs = []\n\n    for scale in range(scales):\n        scale_coeffs = []\n        for angle in range(angles):\n            shear = np.tan(np.pi * angle / angles)\n\n            # Create shearlet filters in frequency domain\n            shearlet_filters = create_shearlet_filter(image.shape, scale, shear, angles)\n\n            # FFT of the image\n            image_fft = fft2(image)\n\n            # Apply filters in frequency domain\n            filtered_fft = []\n            for filt in shearlet_filters:\n                filtered_fft.append(image_fft * filt)\n\n            # Inverse FFT to get the spatial domain representation\n            filtered_images = []\n            for fft in filtered_fft:\n                filtered_image = ifft2(fft).real\n                filtered_images.append(filtered_image)\n\n            scale_coeffs.append(filtered_images)\n\n        coeffs.append(scale_coeffs)\n\n    return coeffs\n\ndef plot_coefficients(coefficients, scales, angles):\n    fig, axes = plt.subplots(scales, angles, figsize=(12, 8))\n    for i in range(scales):\n        for j in range(angles):\n            for k in range(len(coefficients[i][j])):\n                ax = axes[i, j] if len(coefficients[i][j]) > 1 else axes[j]\n                ax.imshow(np.abs(coefficients[i][j][k]), cmap='gray')\n                ax.axis('off')\n                ax.set_title(f'Scale {i+1}, Angle {j+1}')\n                key = f'Scale {i+1} Angle {j+1}'\n                shearlet_transform_dict[key] = np.abs(coefficients[i][j][k])  # Store the image in the dictionary\n    plt.tight_layout()\n    plt.show()\n\n# Define parameters\nscales = 4\nangles = 8\n\n# Apply shearlet transform\ncoefficients = shearlet_transform(image, scales, angles)\n\n# Plot the shearlet coefficients\nplot_coefficients(coefficients, scales, angles)\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:31:34.551679Z","iopub.execute_input":"2024-07-06T08:31:34.552022Z","iopub.status.idle":"2024-07-06T08:31:39.772277Z","shell.execute_reply.started":"2024-07-06T08:31:34.551993Z","shell.execute_reply":"2024-07-06T08:31:39.771496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Assuming shearlet_transform_dict is already populated with images and keys\n\n# Example key to visualize\nkey_to_visualize = 'Scale 2 Angle 3'  # Replace with the specific key you want to visualize\n\n# Retrieve the image from shearlet_transform_dict\nimage_to_visualize = shearlet_transform_dict[key_to_visualize]\n\n# Display the image using matplotlib\nplt.figure(figsize=(6, 6))\nplt.imshow(image_to_visualize, cmap='gray')\nplt.title(key_to_visualize)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:32:36.315379Z","iopub.execute_input":"2024-07-06T08:32:36.315754Z","iopub.status.idle":"2024-07-06T08:32:36.415769Z","shell.execute_reply.started":"2024-07-06T08:32:36.315722Z","shell.execute_reply":"2024-07-06T08:32:36.414942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shearlet_transform_dict\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:34:49.565152Z","iopub.execute_input":"2024-07-06T08:34:49.565578Z","iopub.status.idle":"2024-07-06T08:34:49.598561Z","shell.execute_reply.started":"2024-07-06T08:34:49.565544Z","shell.execute_reply":"2024-07-06T08:34:49.597552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result1","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:34:57.922240Z","iopub.execute_input":"2024-07-06T08:34:57.922617Z","iopub.status.idle":"2024-07-06T08:34:57.929608Z","shell.execute_reply.started":"2024-07-06T08:34:57.922583Z","shell.execute_reply":"2024-07-06T08:34:57.928446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef compute_mse_loop(shearlet_transform_dict, image2):\n    mse_values = {}\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert images to numpy arrays if necessary\n        image1 = np.array(image1)\n        image2 = np.array(image2)\n        \n        # Compute MSE between image1 and image2\n        mse = np.mean((image1 - image2) ** 2)\n        \n        # Store MSE value in dictionary\n        mse_values[key] = mse\n    \n    return mse_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute MSE values\nmse_dict = compute_mse_loop(shearlet_transform_dict, result1)\n\n# Print MSE values for each key in shearlet_transform_dict\nfor key, mse_value in mse_dict.items():\n    print(f\"MSE for '{key}': {mse_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:36:48.243013Z","iopub.execute_input":"2024-07-06T08:36:48.243364Z","iopub.status.idle":"2024-07-06T08:36:48.262714Z","shell.execute_reply.started":"2024-07-06T08:36:48.243333Z","shell.execute_reply":"2024-07-06T08:36:48.261710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef compute_cosine_similarity_loop(shearlet_transform_dict, image2):\n    cosine_similarity_values = {}\n    \n    # Convert image2 to numpy array if necessary\n    image2 = np.array(image2)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert image1 to numpy array if necessary\n        image1 = np.array(image1)\n        \n        # Compute dot product\n        dot_product = np.dot(image1.flatten(), image2.flatten())\n        \n        # Compute magnitudes\n        mag1 = np.linalg.norm(image1)\n        mag2 = np.linalg.norm(image2)\n        \n        # Avoid division by zero\n        if mag1 != 0 and mag2 != 0:\n            # Compute cosine similarity\n            cosine_similarity = dot_product / (mag1 * mag2)\n        else:\n            cosine_similarity = 0  # Handle zero vectors\n        \n        # Store cosine similarity value in dictionary\n        cosine_similarity_values[key] = cosine_similarity\n    \n    return cosine_similarity_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute Cosine Similarity values\ncosine_sim_dict = compute_cosine_similarity_loop(shearlet_transform_dict, result1)\n\n# Print Cosine Similarity values for each key in shearlet_transform_dict\nfor key, cosine_sim_value in cosine_sim_dict.items():\n    print(f\"Cosine Similarity for '{key}': {cosine_sim_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:39:46.153672Z","iopub.execute_input":"2024-07-06T08:39:46.154048Z","iopub.status.idle":"2024-07-06T08:39:46.178228Z","shell.execute_reply.started":"2024-07-06T08:39:46.154020Z","shell.execute_reply":"2024-07-06T08:39:46.177473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef compute_euclidean_distance_loop(shearlet_transform_dict, image2):\n    euclidean_distance_values = {}\n    \n    # Convert image2 to numpy array if necessary\n    image2 = np.array(image2)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert image1 to numpy array if necessary\n        image1 = np.array(image1)\n        \n        # Compute Euclidean distance\n        euclidean_distance = np.linalg.norm(image1.flatten() - image2.flatten())\n        \n        # Store Euclidean distance value in dictionary\n        euclidean_distance_values[key] = euclidean_distance\n    \n    return euclidean_distance_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute Euclidean Distance values\neuclidean_dist_dict = compute_euclidean_distance_loop(shearlet_transform_dict,result2)\n\n# Print Euclidean Distance values for each key in shearlet_transform_dict\nfor key, euclidean_dist_value in euclidean_dist_dict.items():\n    print(f\"Euclidean Distance for '{key}': {euclidean_dist_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:42:16.363765Z","iopub.execute_input":"2024-07-06T08:42:16.364214Z","iopub.status.idle":"2024-07-06T08:42:16.391750Z","shell.execute_reply.started":"2024-07-06T08:42:16.364160Z","shell.execute_reply":"2024-07-06T08:42:16.390886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nfrom skimage.metrics import structural_similarity as ssim\n\ndef compute_ssim_loop(shearlet_transform_dict, image2):\n    ssim_values = {}\n    \n    # Convert image2 to numpy array if necessary\n    image2 = np.array(image2)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert image1 to numpy array if necessary\n        image1 = np.array(image1)\n        \n        # Compute SSIM\n        ssim_score, _ = ssim(image1, image2, full=True)\n        \n        # Store SSIM value in dictionary\n        ssim_values[key] = ssim_score\n    \n    return ssim_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute SSIM values\nssim_dict = compute_ssim_loop(shearlet_transform_dict, result1)\n\n# Print SSIM values for each key in shearlet_transform_dict\nfor key, ssim_value in ssim_dict.items():\n    print(f\"SSIM for '{key}': {ssim_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:42:33.470246Z","iopub.execute_input":"2024-07-06T08:42:33.470639Z","iopub.status.idle":"2024-07-06T08:42:33.640964Z","shell.execute_reply.started":"2024-07-06T08:42:33.470602Z","shell.execute_reply":"2024-07-06T08:42:33.640123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef compute_psnr_loop(shearlet_transform_dict, image2):\n    psnr_values = {}\n    \n    # Convert image2 to numpy array if necessary\n    image2 = np.array(image2)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert image1 to numpy array if necessary\n        image1 = np.array(image1)\n        \n        # Compute MSE\n        mse = np.mean((image1 - image2) ** 2)\n        \n        # Calculate maximum possible pixel value\n        max_pixel = np.max(image1)\n        \n        # Compute PSNR\n        if mse == 0:\n            psnr = 100  # Perfect match, return a high value\n        else:\n            psnr = 20 * np.log10(max_pixel / np.sqrt(mse))\n        \n        # Store PSNR value in dictionary\n        psnr_values[key] = psnr\n    \n    return psnr_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute PSNR values\npsnr_dict = compute_psnr_loop(shearlet_transform_dict, result1)\n\n# Print PSNR values for each key in shearlet_transform_dict\nfor key, psnr_value in psnr_dict.items():\n    print(f\"PSNR for '{key}': {psnr_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:43:14.658870Z","iopub.execute_input":"2024-07-06T08:43:14.659250Z","iopub.status.idle":"2024-07-06T08:43:14.683501Z","shell.execute_reply.started":"2024-07-06T08:43:14.659213Z","shell.execute_reply":"2024-07-06T08:43:14.682282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef compute_ncc_loop(shearlet_transform_dict, image2):\n    ncc_values = {}\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert images to numpy arrays if necessary\n        image1 = np.array(image1)\n        image2 = np.array(image2)\n        \n        # Compute mean of image1 and image2\n        mean1 = np.mean(image1)\n        mean2 = np.mean(image2)\n        \n        # Compute normalized cross-correlation\n        numerator = np.sum((image1 - mean1) * (image2 - mean2))\n        denominator = np.sqrt(np.sum((image1 - mean1)**2) * np.sum((image2 - mean2)**2))\n        ncc = numerator / denominator\n        \n        # Store NCC value in dictionary\n        ncc_values[key] = ncc\n    \n    return ncc_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute NCC values\nncc_dict = compute_ncc_loop(shearlet_transform_dict, result1)\n\n# Print NCC values for each key in shearlet_transform_dict\nfor key, ncc_value in ncc_dict.items():\n    print(f\"NCC for '{key}': {ncc_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:43:46.808191Z","iopub.execute_input":"2024-07-06T08:43:46.808556Z","iopub.status.idle":"2024-07-06T08:43:46.841814Z","shell.execute_reply.started":"2024-07-06T08:43:46.808520Z","shell.execute_reply":"2024-07-06T08:43:46.841020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef compute_pearson_corr_coeff(shearlet_transform_dict, image2):\n    pearson_values = {}\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert images to numpy arrays if necessary\n        image1 = np.array(image1)\n        image2 = np.array(image2)\n        \n        # Flatten images\n        image1_flat = image1.flatten()\n        image2_flat = image2.flatten()\n        \n        # Compute Pearson correlation coefficient\n        pearson_coeff = np.corrcoef(image1_flat, image2_flat)[0, 1]\n        \n        # Store Pearson coefficient in dictionary\n        pearson_values[key] = pearson_coeff\n    \n    return pearson_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute Pearson correlation coefficients\npearson_dict = compute_pearson_corr_coeff(shearlet_transform_dict, result2)\n\n# Print Pearson correlation coefficients for each key in shearlet_transform_dict\nfor key, pearson_value in pearson_dict.items():\n    print(f\"Pearson correlation coefficient for '{key}': {pearson_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:44:07.927674Z","iopub.execute_input":"2024-07-06T08:44:07.927992Z","iopub.status.idle":"2024-07-06T08:44:07.968538Z","shell.execute_reply.started":"2024-07-06T08:44:07.927965Z","shell.execute_reply":"2024-07-06T08:44:07.967503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport cv2\n\ndef compute_scc(img1, img2):\n    \"\"\"\n    Compute the Spatial Correlation Coefficient (SCC) between two images.\n\n    Args:\n        img1 (ndarray): First image.\n        img2 (ndarray): Second image.\n\n    Returns:\n        float: SCC value.\n    \"\"\"\n    img1 = img1.astype(np.float64)\n    img2 = img2.astype(np.float64)\n    \n    # Normalize images to zero mean and unit variance\n    img1 = (img1 - np.mean(img1)) / np.std(img1)\n    img2 = (img2 - np.mean(img2)) / np.std(img2)\n    \n    # Compute the correlation coefficient\n    scc = np.mean(img1 * img2)\n    \n    return scc\n\ndef compute_scc_loop(shearlet_transform_dict, image2):\n    scc_values = {}\n    \n    # Ensure the images are in the correct format\n    image2 = (image2 * 255 / np.max(image2)).astype(np.uint8)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        image1 = (image1 * 255 / np.max(image1)).astype(np.uint8)\n        \n        # Convert images to grayscale if they are not already\n        if len(image1.shape) == 3:\n            image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)\n        if len(image2.shape) == 3:\n            image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)\n        \n        # Compute SCC\n        scc_value = compute_scc(image1, image2)\n        \n        # Store SCC value in dictionary\n        scc_values[key] = scc_value\n    \n    return scc_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute SCC values\nscc_dict = compute_scc_loop(shearlet_transform_dict, result1)\n\n# Print SCC values for each key in shearlet_transform_dict\nfor key, scc_value in scc_dict.items():\n    print(f\"SCC for '{key}': {scc_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:49:55.932216Z","iopub.execute_input":"2024-07-06T08:49:55.932607Z","iopub.status.idle":"2024-07-06T08:49:55.980278Z","shell.execute_reply.started":"2024-07-06T08:49:55.932570Z","shell.execute_reply":"2024-07-06T08:49:55.979449Z"},"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":"markdown","source":"### Check mask for Attention Map","metadata":{}},{"cell_type":"code","source":"result1 = get_attention_map(img1, True)\nresult2 = get_attention_map(img2, True)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.351386Z","iopub.status.idle":"2024-07-06T08:16:59.352104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_attention_map(img1, result1)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.353211Z","iopub.status.idle":"2024-07-06T08:16:59.353829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_attention_map(img2, result2)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.354962Z","iopub.status.idle":"2024-07-06T08:16:59.355589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<!-- Adding Shearlet Transform and testing on their dataset -->","metadata":{}},{"cell_type":"markdown","source":"SHEARLET TRANSFORM ON GIVEN DATASET\n","metadata":{}},{"cell_type":"code","source":"img3=Image.open(\"/kaggle/input/cassava-vit-b-16/train-cbb-114.jpg\")","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:02:24.049226Z","iopub.execute_input":"2024-07-06T09:02:24.049600Z","iopub.status.idle":"2024-07-06T09:02:24.098918Z","shell.execute_reply.started":"2024-07-06T09:02:24.049568Z","shell.execute_reply":"2024-07-06T09:02:24.098147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result3 = get_attention_map(img3, True)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:05:46.349385Z","iopub.execute_input":"2024-07-06T09:05:46.349742Z","iopub.status.idle":"2024-07-06T09:05:47.275924Z","shell.execute_reply.started":"2024-07-06T09:05:46.349712Z","shell.execute_reply":"2024-07-06T09:05:47.275055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_attention_map(img3, result3)","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:05:48.482510Z","iopub.execute_input":"2024-07-06T09:05:48.482834Z","iopub.status.idle":"2024-07-06T09:05:48.985415Z","shell.execute_reply.started":"2024-07-06T09:05:48.482806Z","shell.execute_reply":"2024-07-06T09:05:48.984527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\nfrom PIL import Image\nfrom scipy.fftpack import fft2, ifft2, fftshift, ifftshift\n\n# Load the image\n\n# Convert the image to grayscale and to a NumPy array\nimage = np.array(img3.convert('L'))\n\n# Display the image\nplt.imshow(image, cmap='gray')\nplt.title('Original Image')\nplt.show()\n\nshearlet_transform_dict = dict()\n\ndef create_shearlet_filter(size, scale, shear, angles):\n    nx, ny = size\n    X, Y = np.meshgrid(np.fft.fftfreq(nx), np.fft.fftfreq(ny), indexing='ij')\n\n    # Apply scaling\n    X = X * (2 ** scale)\n    Y = Y * (2 ** scale)\n\n    # Apply shear\n    X = X + shear * Y\n\n    # Create a Gaussian window (can be other windows too)\n    sigma = 0.1\n    window = np.exp(- (X**2 + Y**2) / (2 * sigma**2))\n\n    # Rotate angles to obtain the shearlet filter\n    angle_step = 2 * np.pi / angles\n    filters = []\n    for angle in range(angles):\n        theta = angle * angle_step\n        rotated_window = window * np.exp(1j * theta * (X + 1j * Y))\n        filters.append(rotated_window)\n\n    return filters\n\ndef shearlet_transform(image, scales, angles):\n    nx, ny = image.shape\n    coeffs = []\n\n    for scale in range(scales):\n        scale_coeffs = []\n        for angle in range(angles):\n            shear = np.tan(np.pi * angle / angles)\n\n            # Create shearlet filters in frequency domain\n            shearlet_filters = create_shearlet_filter(image.shape, scale, shear, angles)\n\n            # FFT of the image\n            image_fft = fft2(image)\n\n            # Apply filters in frequency domain\n            filtered_fft = []\n            for filt in shearlet_filters:\n                filtered_fft.append(image_fft * filt)\n\n            # Inverse FFT to get the spatial domain representation\n            filtered_images = []\n            for fft in filtered_fft:\n                filtered_image = ifft2(fft).real\n                filtered_images.append(filtered_image)\n\n            scale_coeffs.append(filtered_images)\n\n        coeffs.append(scale_coeffs)\n\n    return coeffs\n\ndef plot_coefficients(coefficients, scales, angles):\n    fig, axes = plt.subplots(scales, angles, figsize=(12, 8))\n    for i in range(scales):\n        for j in range(angles):\n            for k in range(len(coefficients[i][j])):\n                ax = axes[i, j] if len(coefficients[i][j]) > 1 else axes[j]\n                ax.imshow(np.abs(coefficients[i][j][k]), cmap='gray')\n                ax.axis('off')\n                ax.set_title(f'Scale {i+1}, Angle {j+1}')\n                key = f'Scale {i+1} Angle {j+1}'\n                shearlet_transform_dict[key] = np.abs(coefficients[i][j][k])  # Store the image in the dictionary\n    plt.tight_layout()\n    plt.show()\n\n# Define parameters\nscales = 4\nangles = 8\n\n# Apply shearlet transform\ncoefficients = shearlet_transform(image, scales, angles)\n\n# Plot the shearlet coefficients\nplot_coefficients(coefficients, scales, angles)\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:03:51.521445Z","iopub.execute_input":"2024-07-06T09:03:51.521797Z","iopub.status.idle":"2024-07-06T09:04:04.552450Z","shell.execute_reply.started":"2024-07-06T09:03:51.521761Z","shell.execute_reply":"2024-07-06T09:04:04.551696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef compute_mse_loop(shearlet_transform_dict, image2):\n    mse_values = {}\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert images to numpy arrays if necessary\n        image1 = np.array(image1)\n        image2 = np.array(image2)\n        \n        # Compute MSE between image1 and image2\n        mse = np.mean((image1 - image2) ** 2)\n        \n        # Store MSE value in dictionary\n        mse_values[key] = mse\n    \n    return mse_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute MSE values\nmse_dict = compute_mse_loop(shearlet_transform_dict, result3)\n\n# Print MSE values for each key in shearlet_transform_dict\nfor key, mse_value in mse_dict.items():\n    print(f\"MSE for '{key}': {mse_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:07:00.136852Z","iopub.execute_input":"2024-07-06T09:07:00.137214Z","iopub.status.idle":"2024-07-06T09:07:00.176033Z","shell.execute_reply.started":"2024-07-06T09:07:00.137178Z","shell.execute_reply":"2024-07-06T09:07:00.175236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n","metadata":{}},{"cell_type":"code","source":"import numpy as np\n\ndef compute_cosine_similarity_loop(shearlet_transform_dict, image2):\n    cosine_similarity_values = {}\n    \n    # Convert image2 to numpy array if necessary\n    image2 = np.array(image2)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert image1 to numpy array if necessary\n        image1 = np.array(image1)\n        \n        # Compute dot product\n        dot_product = np.dot(image1.flatten(), image2.flatten())\n        \n        # Compute magnitudes\n        mag1 = np.linalg.norm(image1)\n        mag2 = np.linalg.norm(image2)\n        \n        # Avoid division by zero\n        if mag1 != 0 and mag2 != 0:\n            # Compute cosine similarity\n            cosine_similarity = dot_product / (mag1 * mag2)\n        else:\n            cosine_similarity = 0  # Handle zero vectors\n        \n        # Store cosine similarity value in dictionary\n        cosine_similarity_values[key] = cosine_similarity\n    \n    return cosine_similarity_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute Cosine Similarity values\ncosine_sim_dict = compute_cosine_similarity_loop(shearlet_transform_dict, result3)\n\n# Print Cosine Similarity values for each key in shearlet_transform_dict\nfor key, cosine_sim_value in cosine_sim_dict.items():\n    print(f\"Cosine Similarity for '{key}': {cosine_sim_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:07:23.201956Z","iopub.execute_input":"2024-07-06T09:07:23.202301Z","iopub.status.idle":"2024-07-06T09:07:23.248912Z","shell.execute_reply.started":"2024-07-06T09:07:23.202271Z","shell.execute_reply":"2024-07-06T09:07:23.248010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport cv2\n\ndef compute_scc(img1, img2):\n    \"\"\"\n    Compute the Spatial Correlation Coefficient (SCC) between two images.\n\n    Args:\n        img1 (ndarray): First image.\n        img2 (ndarray): Second image.\n\n    Returns:\n        float: SCC value.\n    \"\"\"\n    img1 = img1.astype(np.float64)\n    img2 = img2.astype(np.float64)\n    \n    # Normalize images to zero mean and unit variance\n    img1 = (img1 - np.mean(img1)) / np.std(img1)\n    img2 = (img2 - np.mean(img2)) / np.std(img2)\n    \n    # Compute the correlation coefficient\n    scc = np.mean(img1 * img2)\n    \n    return scc\n\ndef compute_scc_loop(shearlet_transform_dict, image2):\n    scc_values = {}\n    \n    # Ensure the images are in the correct format\n    image2 = (image2 * 255 / np.max(image2)).astype(np.uint8)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        image1 = (image1 * 255 / np.max(image1)).astype(np.uint8)\n        \n        # Convert images to grayscale if they are not already\n        if len(image1.shape) == 3:\n            image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)\n        if len(image2.shape) == 3:\n            image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)\n        \n        # Compute SCC\n        scc_value = compute_scc(image1, image2)\n        \n        # Store SCC value in dictionary\n        scc_values[key] = scc_value\n    \n    return scc_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute SCC values\nscc_dict = compute_scc_loop(shearlet_transform_dict, result3)\n\n# Print SCC values for each key in shearlet_transform_dict\nfor key, scc_value in scc_dict.items():\n    print(f\"SCC for '{key}': {scc_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:07:42.819923Z","iopub.execute_input":"2024-07-06T09:07:42.820540Z","iopub.status.idle":"2024-07-06T09:07:42.952561Z","shell.execute_reply.started":"2024-07-06T09:07:42.820481Z","shell.execute_reply":"2024-07-06T09:07:42.951687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nfrom skimage.metrics import structural_similarity as ssim\n\ndef compute_ssim_loop(shearlet_transform_dict, image2):\n    ssim_values = {}\n    \n    # Convert image2 to numpy array if necessary\n    image2 = np.array(image2)\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert image1 to numpy array if necessary\n        image1 = np.array(image1)\n        \n        # Compute SSIM\n        ssim_score, _ = ssim(image1, image2, full=True)\n        \n        # Store SSIM value in dictionary\n        ssim_values[key] = ssim_score\n    \n    return ssim_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute SSIM values\nssim_dict = compute_ssim_loop(shearlet_transform_dict, result3)\n\n# Print SSIM values for each key in shearlet_transform_dict\nfor key, ssim_value in ssim_dict.items():\n    print(f\"SSIM for '{key}': {ssim_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:08:39.334157Z","iopub.execute_input":"2024-07-06T09:08:39.334541Z","iopub.status.idle":"2024-07-06T09:08:39.905143Z","shell.execute_reply.started":"2024-07-06T09:08:39.334504Z","shell.execute_reply":"2024-07-06T09:08:39.904278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"import numpy as np\n\ndef compute_pearson_corr_coeff(shearlet_transform_dict, image2):\n    pearson_values = {}\n    \n    for key, image1 in shearlet_transform_dict.items():\n        # Convert images to numpy arrays if necessary\n        image1 = np.array(image1)\n        image2 = np.array(image2)\n        \n        # Flatten images\n        image1_flat = image1.flatten()\n        image2_flat = image2.flatten()\n        \n        # Compute Pearson correlation coefficient\n        pearson_coeff = np.corrcoef(image1_flat, image2_flat)[0, 1]\n        \n        # Store Pearson coefficient in dictionary\n        pearson_values[key] = pearson_coeff\n    \n    return pearson_values\n\n# Example usage\n# Assuming shearlet_transform_dict is defined and contains your images\n# and image2 is the reference image you want to compare against\n# shearlet_transform_dict = {'key1': image1, 'key2': image2, ...}\n# image2 = some_image\n\n# Call the function to compute Pearson correlation coefficients\npearson_dict = compute_pearson_corr_coeff(shearlet_transform_dict, result3)\n\n# Print Pearson correlation coefficients for each key in shearlet_transform_dict\nfor key, pearson_value in pearson_dict.items():\n    print(f\"Pearson correlation coefficient for '{key}': {pearson_value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-07-06T09:12:31.661791Z","iopub.execute_input":"2024-07-06T09:12:31.662143Z","iopub.status.idle":"2024-07-06T09:12:31.758787Z","shell.execute_reply.started":"2024-07-06T09:12:31.662114Z","shell.execute_reply":"2024-07-06T09:12:31.757888Z"},"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":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.370038Z","iopub.status.idle":"2024-07-06T08:16:59.370501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Check mask for Attention Map","metadata":{}},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.371668Z","iopub.status.idle":"2024-07-06T08:16:59.372134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.372997Z","iopub.status.idle":"2024-07-06T08:16:59.373408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.374289Z","iopub.status.idle":"2024-07-06T08:16:59.374772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Healthy - Class4","metadata":{}},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.375674Z","iopub.status.idle":"2024-07-06T08:16:59.376066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.376954Z","iopub.status.idle":"2024-07-06T08:16:59.377359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.378471Z","iopub.status.idle":"2024-07-06T08:16:59.378913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Check mask for Attention Map","metadata":{}},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.379909Z","iopub.status.idle":"2024-07-06T08:16:59.380354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.381633Z","iopub.status.idle":"2024-07-06T08:16:59.382139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.383004Z","iopub.status.idle":"2024-07-06T08:16:59.383501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"\n","metadata":{}},{"cell_type":"code","source":"\n","metadata":{"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:52:07.420168Z","iopub.execute_input":"2024-07-06T08:52:07.420539Z","iopub.status.idle":"2024-07-06T08:52:07.450484Z","shell.execute_reply.started":"2024-07-06T08:52:07.420507Z","shell.execute_reply":"2024-07-06T08:52:07.449481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.387339Z","iopub.status.idle":"2024-07-06T08:16:59.387810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-07-06T08:16:59.388747Z","iopub.status.idle":"2024-07-06T08:16:59.389185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"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":"","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":"","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":[]}]}