{"id":36655,"date":"2024-11-01T09:50:21","date_gmt":"2024-11-01T09:50:21","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36655"},"modified":"2024-11-01T11:52:20","modified_gmt":"2024-11-01T11:52:20","slug":"deep-learning-pytorch-course-feature-map-visualization","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36655\/","title":{"rendered":"Deep Learning PyTorch Course, Feature Map Visualization"},"content":{"rendered":"<p><body><\/p>\n<p>\n        In deep learning, it is important to understand how models learn from data. In particular,<br \/>\n        feature maps are low-dimensional data generated in the intermediate layers of neural networks,<br \/>\n        which serve as important indicators of what features the model is extracting from the input data.<br \/>\n        In this article, we will explain in detail how to visualize feature maps using PyTorch,<br \/>\n        and we will understand the process through hands-on practice.\n    <\/p>\n<h2>1. What is a feature map?<\/h2>\n<p>\n        A feature map refers to the output that is mapped through various filters generated by a convolutional neural network (CNN).<br \/>\n        Each filter plays a role in detecting specific patterns or features in the input image, visually expressing<br \/>\n        what information the model is learning in this process.\n    <\/p>\n<h2>2. Why visualize feature maps?<\/h2>\n<p>\n        The reasons for visualizing feature maps are as follows:<\/p>\n<ul>\n<li>To understand the model&#8217;s decision-making and enhance interpretability.<\/li>\n<li>To determine how sensitive the model is to specific features.<\/li>\n<li>To provide insights for error analysis and model improvement.<\/li>\n<\/ul>\n<h2>3. Installing required libraries<\/h2>\n<p>\n        To visualize feature maps, PyTorch and a few additional libraries are needed.<br \/>\n        You can install the necessary libraries using the command below.<\/p>\n<pre><code>pip install torch torchvision matplotlib<\/code><\/pre>\n<\/p>\n<h2>4. Preparing the dataset<\/h2>\n<p>\n        We will use the MNIST dataset to process handwritten digit images. To do this,<br \/>\n        we will load the data using the <code>datasets<\/code> module from torchvision.\n    <\/p>\n<pre><code>\nimport torch\nimport torchvision.transforms as transforms\nfrom torchvision import datasets\nfrom torch.utils.data import DataLoader\n\n# Define transformations\ntransform = transforms.Compose([\n    transforms.ToTensor(),\n    transforms.Normalize((0.5,), (0.5,))\n])\n\n# Download MNIST dataset\nmnist_data = datasets.MNIST(root='.\/data', train=True, transform=transform, download=True)\ndata_loader = DataLoader(mnist_data, batch_size=64, shuffle=True)\n    <\/code><\/pre>\n<h2>5. Building a simple CNN model<\/h2>\n<p>\n        We will build a simple CNN model to classify images. The model consists of the following:<br \/>\n        Convolutional Layer -> ReLU -> Max Pooling -> Fully Connected Layer\n    <\/p>\n<pre><code>\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass SimpleCNN(nn.Module):\n    def __init__(self):\n        super(SimpleCNN, self).__init__()\n        self.conv1 = nn.Conv2d(1, 16, kernel_size=5)\n        self.pool = nn.MaxPool2d(2, 2)\n        self.conv2 = nn.Conv2d(16, 32, kernel_size=5)\n        self.fc1 = nn.Linear(32 * 4 * 4, 120)\n        self.fc2 = nn.Linear(120, 84)\n        self.fc3 = nn.Linear(84, 10)\n\n    def forward(self, x):\n        x = self.pool(F.relu(self.conv1(x)))\n        x = self.pool(F.relu(self.conv2(x)))\n        x = x.view(-1, 32 * 4 * 4)\n        x = F.relu(self.fc1(x))\n        x = F.relu(self.fc2(x))\n        x = self.fc3(x)\n        return x\n\nmodel = SimpleCNN()\n    <\/code><\/pre>\n<h2>6. Visualizing feature maps<\/h2>\n<p>\n        We can extract and visualize feature maps from a specific layer of the model. Here, we will visualize<br \/>\n        the feature maps of the first convolutional layer.\n    <\/p>\n<pre><code>\nimport matplotlib.pyplot as plt\n\n# Get a batch of virtual images\ndata_iter = iter(data_loader)\nimages, labels = next(data_iter)\n\n# Pass through the model and extract feature maps\nwith torch.no_grad():\n    feature_maps = model.conv1(images)\n\n# Visualize feature maps\ndef show_feature_maps(feature_maps):\n    feature_maps = feature_maps[0].detach().numpy()\n    num_feature_maps = feature_maps.shape[0]\n\n    plt.figure(figsize=(15, 15))\n    for i in range(num_feature_maps):\n        plt.subplot(8, 8, i + 1)\n        plt.imshow(feature_maps[i], cmap='gray')\n        plt.axis('off')\n    plt.show()\n\nshow_feature_maps(feature_maps)\n    <\/code><\/pre>\n<h2>7. Interpreting results<\/h2>\n<p>\n        Through the visualization of feature maps, we can see what features the model is extracting from each input image.<br \/>\n        Each feature map is the result of applying different filters, with specific patterns or shapes highlighted.<br \/>\n        This allows us to gain insights into the model&#8217;s learning process.\n    <\/p>\n<h2>8. Conclusion<\/h2>\n<p>\n        In this tutorial, we introduced how to implement a simple CNN model using PyTorch and how to visualize<br \/>\n        feature maps from the first convolutional layer. Visualizing feature maps is a useful tool for understanding<br \/>\n        the internal workings of the model and gaining insights into the patterns being generated.\n    <\/p>\n<p>\n        The fields of machine learning and deep learning continue to evolve, and these visualization techniques can<br \/>\n        help us explain and improve complex models.<br \/>\n        I encourage you to continue learning by tackling various topics similar to this one.\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In deep learning, it is important to understand how models learn from data. In particular, feature maps are low-dimensional data generated in the intermediate layers of neural networks, which serve as important indicators of what features the model is extracting from the input data. In this article, we will explain in detail how to visualize &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36655\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, Feature Map Visualization&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[149],"tags":[],"class_list":["post-36655","post","type-post","status-publish","format-standard","hentry","category-pytorch-study"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deep Learning PyTorch Course, Feature Map Visualization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/36655\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deep Learning PyTorch Course, Feature Map Visualization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In deep learning, it is important to understand how models learn from data. In particular, feature maps are low-dimensional data generated in the intermediate layers of neural networks, which serve as important indicators of what features the model is extracting from the input data. In this article, we will explain in detail how to visualize &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, Feature Map Visualization&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36655\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:50:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:20+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36655\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36655\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, Feature Map Visualization\",\"datePublished\":\"2024-11-01T09:50:21+00:00\",\"dateModified\":\"2024-11-01T11:52:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36655\/\"},\"wordCount\":415,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36655\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36655\/\",\"name\":\"Deep Learning PyTorch Course, Feature Map Visualization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:50:21+00:00\",\"dateModified\":\"2024-11-01T11:52:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36655\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36655\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36655\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, Feature Map Visualization\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deep Learning PyTorch Course, Feature Map Visualization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/36655\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, Feature Map Visualization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In deep learning, it is important to understand how models learn from data. In particular, feature maps are low-dimensional data generated in the intermediate layers of neural networks, which serve as important indicators of what features the model is extracting from the input data. In this article, we will explain in detail how to visualize &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, Feature Map Visualization\"","og_url":"https:\/\/atmokpo.com\/w\/36655\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:50:21+00:00","article_modified_time":"2024-11-01T11:52:20+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36655\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36655\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, Feature Map Visualization","datePublished":"2024-11-01T09:50:21+00:00","dateModified":"2024-11-01T11:52:20+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36655\/"},"wordCount":415,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36655\/","url":"https:\/\/atmokpo.com\/w\/36655\/","name":"Deep Learning PyTorch Course, Feature Map Visualization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:50:21+00:00","dateModified":"2024-11-01T11:52:20+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36655\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36655\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36655\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, Feature Map Visualization"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=36655"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36655\/revisions"}],"predecessor-version":[{"id":36656,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36655\/revisions\/36656"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}