diff --git "a/notebooks/grad_cam.ipynb" "b/notebooks/grad_cam.ipynb" new file mode 100644--- /dev/null +++ "b/notebooks/grad_cam.ipynb" @@ -0,0 +1,318 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Generating train split: 107 examples [00:00, 6293.96 examples/s]\n" + ] + } + ], + "source": [ + "from datasets import load_dataset\n", + "\n", + "dataset = load_dataset(\"imagefolder\", data_dir=\"../data/test/pal\", split=\"train\")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Map: 0%| | 0/107 [00:00" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "for cam in grayscale_cams:\n", + " rgb_img = np.array(resized_no_alfa[index][\"image\"]) / 255.0 # (height, width, channel) の順である必要がある。ex. 224, 224, 3\n", + " visualization = show_cam_on_image(rgb_img, cam, use_rgb=True)\n", + " plt.imshow(visualization, vmin=0, vmax=255, interpolation='none')\n", + " plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pokemon-palworld-v2", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}