{"id":36417,"date":"2024-11-01T09:48:19","date_gmt":"2024-11-01T09:48:19","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36417"},"modified":"2024-11-01T11:53:16","modified_gmt":"2024-11-01T11:53:16","slug":"deep-learning-pytorch-course-1d-2d-3d-convolution","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36417\/","title":{"rendered":"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution"},"content":{"rendered":"<p><body><\/p>\n<p>\n        Convolutional Neural Networks (CNNs) demonstrate excellent performance in learning patterns from images, time-series data, etc., which is attributed to their method of processing data through convolution operations. CNNs are primarily used for processing 2D image data, but in certain tasks, processing of 1D or 3D data is also required. In this article, we will explore 1D, 2D, and 3D convolutions in detail, including how to implement them using PyTorch.\n    <\/p>\n<h2>1D Convolution<\/h2>\n<p>\n        1D convolution is mainly used for processing time-series or sequential data. Examples include audio signals, stock price data, and sensor data, which correspond to 1D data. In 1D convolution, the filter moves along one dimension of the input data to perform operations.\n    <\/p>\n<h3>1D Convolution Example<\/h3>\n<p>\n    Here is an example to implement 1D convolution using PyTorch.\n    <\/p>\n<pre><code>\nimport torch\nimport torch.nn as nn\n\n# Define 1D convolution layer\nclass Simple1DConv(nn.Module):\n    def __init__(self):\n        super(Simple1DConv, self).__init__()\n        self.conv1 = nn.Conv1d(in_channels=1, out_channels=1, kernel_size=3)\n    \n    def forward(self, x):\n        return self.conv1(x)\n\n# Example input data (1 x 1 x 5) shape\ninput_data = torch.tensor([[[1.0, 2.0, 3.0, 4.0, 5.0]]])  # Batch size 1, Channel 1\nmodel = Simple1DConv()\noutput = model(input_data)\nprint(output)\n    <\/code><\/pre>\n<p>\n       In the code above, the Simple1DConv class has a 1D convolution layer, and the input data is in the form of (batch size, number of channels, length). The output size after the convolution operation is calculated as follows:<br \/>\n       <br \/>\n<strong>Output length = (Input length &#8211; Kernel size) + 1<\/strong><br \/>\n<br \/>\n       Here, the input length is 5 and the kernel size is 3, so the output length becomes 3.\n    <\/p>\n<h2>2D Convolution<\/h2>\n<p>\n        2D convolution is applied to 2-dimensional data such as images. The filter moves across the two dimensions of the input image to perform operations, which is useful for extracting features from images.\n    <\/p>\n<h3>2D Convolution Example<\/h3>\n<p>\n        A simple example to implement 2D convolution using PyTorch.\n    <\/p>\n<pre><code>\nimport torch\nimport torch.nn as nn\n\n# Define 2D convolution layer\nclass Simple2DConv(nn.Module):\n    def __init__(self):\n        super(Simple2DConv, self).__init__()\n        self.conv2d = nn.Conv2d(in_channels=1, out_channels=1, kernel_size=3)\n    \n    def forward(self, x):\n        return self.conv2d(x)\n\n# Example input data (Batch size 1, Channel 1, Height 5, Width 5)\ninput_data = torch.tensor([[[[1.0, 2.0, 3.0, 4.0, 5.0],\n                              [6.0, 7.0, 8.0, 9.0, 10.0],\n                              [11.0, 12.0, 13.0, 14.0, 15.0],\n                              [16.0, 17.0, 18.0, 19.0, 20.0],\n                              [21.0, 22.0, 23.0, 24.0, 25.0]]]])  # Batch size 1, Channel 1\nmodel = Simple2DConv()\noutput = model(input_data)\nprint(output)\n    <\/code><\/pre>\n<p>\n        In the code above, the Simple2DConv class defines a 2D convolution layer. The input data is in the shape of (batch size, number of channels, height, width), and the output size is calculated as follows:<br \/>\n        <br \/>\n<strong>Output height = (Input height &#8211; Kernel height) + 1<\/strong><br \/>\n<br \/>\n<strong>Output width = (Input width &#8211; Kernel width) + 1<\/strong><br \/>\n<br \/>\n        Since both the input height and width are 5 and the kernel size is 3, the output will have the shape (1, 1, 3, 3).\n    <\/p>\n<h2>3D Convolution<\/h2>\n<p>\n        3D convolution is applied to 3-dimensional data such as video data or volumetric data. It is useful for analyzing 3D structures such as data that changes over time or medical images.\n    <\/p>\n<h3>3D Convolution Example<\/h3>\n<p>\n        Here is an example of implementing 3D convolution using PyTorch.\n    <\/p>\n<pre><code>\nimport torch\nimport torch.nn as nn\n\n# Define 3D convolution layer\nclass Simple3DConv(nn.Module):\n    def __init__(self):\n        super(Simple3DConv, self).__init__()\n        self.conv3d = nn.Conv3d(in_channels=1, out_channels=1, kernel_size=3)\n    \n    def forward(self, x):\n        return self.conv3d(x)\n\n# Example input data (Batch size 1, Channel 1, Depth 5, Height 5, Width 5)\ninput_data = torch.tensor([[[[[1.0, 2.0, 3.0, 4.0, 5.0],\n                               [6.0, 7.0, 8.0, 9.0, 10.0],\n                               [11.0, 12.0, 13.0, 14.0, 15.0],\n                               [16.0, 17.0, 18.0, 19.0, 20.0],\n                               [21.0, 22.0, 23.0, 24.0, 25.0]],\n                             \n                              [[1.0, 2.0, 3.0, 4.0, 5.0],\n                               [6.0, 7.0, 8.0, 9.0, 10.0],\n                               [11.0, 12.0, 13.0, 14.0, 15.0],\n                               [16.0, 17.0, 18.0, 19.0, 20.0],\n                               [21.0, 22.0, 23.0, 24.0, 25.0]],\n                              \n                              [[1.0, 2.0, 3.0, 4.0, 5.0],\n                               [6.0, 7.0, 8.0, 9.0, 10.0],\n                               [11.0, 12.0, 13.0, 14.0, 15.0],\n                               [16.0, 17.0, 18.0, 19.0, 20.0],\n                               [21.0, 22.0, 23.0, 24.0, 25.0]]]]])  # Batch size 1, Channel 1\nmodel = Simple3DConv()\noutput = model(input_data)\nprint(output)\n    <\/code><\/pre>\n<p>\n        The above code defines the Simple3DConv class, which contains a 3D convolution layer. The input data has the shape (batch size, number of channels, depth, height, width). The output size is calculated as follows:<br \/>\n        <br \/>\n<strong>Output depth = (Input depth &#8211; Kernel depth) + 1<\/strong><br \/>\n<br \/>\n<strong>Output height = (Input height &#8211; Kernel height) + 1<\/strong><br \/>\n<br \/>\n<strong>Output width = (Input width &#8211; Kernel width) + 1<\/strong>\n<\/p>\n<h2>Conclusion<\/h2>\n<p>\n        In this tutorial, we explored how to implement 1D, 2D, and 3D convolutions using PyTorch. By utilizing appropriate convolution layers according to different types of data, effective models can be designed. To build deeper models, multiple convolution layers can be stacked, or various activation functions and optimization techniques can be applied. Future exercises will cover how to design advanced model architectures using these techniques.\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Convolutional Neural Networks (CNNs) demonstrate excellent performance in learning patterns from images, time-series data, etc., which is attributed to their method of processing data through convolution operations. CNNs are primarily used for processing 2D image data, but in certain tasks, processing of 1D or 3D data is also required. In this article, we will explore &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36417\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, 1D, 2D, 3D Convolution&#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-36417","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, 1D, 2D, 3D Convolution - \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\/36417\/\" \/>\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, 1D, 2D, 3D Convolution - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Convolutional Neural Networks (CNNs) demonstrate excellent performance in learning patterns from images, time-series data, etc., which is attributed to their method of processing data through convolution operations. CNNs are primarily used for processing 2D image data, but in certain tasks, processing of 1D or 3D data is also required. In this article, we will explore &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, 1D, 2D, 3D Convolution&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36417\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:48:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:53:16+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\/36417\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36417\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution\",\"datePublished\":\"2024-11-01T09:48:19+00:00\",\"dateModified\":\"2024-11-01T11:53:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36417\/\"},\"wordCount\":477,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36417\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36417\/\",\"name\":\"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:48:19+00:00\",\"dateModified\":\"2024-11-01T11:53:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36417\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36417\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36417\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution\"}]},{\"@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, 1D, 2D, 3D Convolution - \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\/36417\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Convolutional Neural Networks (CNNs) demonstrate excellent performance in learning patterns from images, time-series data, etc., which is attributed to their method of processing data through convolution operations. CNNs are primarily used for processing 2D image data, but in certain tasks, processing of 1D or 3D data is also required. In this article, we will explore &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution\"","og_url":"https:\/\/atmokpo.com\/w\/36417\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:48:19+00:00","article_modified_time":"2024-11-01T11:53:16+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\/36417\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36417\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution","datePublished":"2024-11-01T09:48:19+00:00","dateModified":"2024-11-01T11:53:16+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36417\/"},"wordCount":477,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36417\/","url":"https:\/\/atmokpo.com\/w\/36417\/","name":"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:48:19+00:00","dateModified":"2024-11-01T11:53:16+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36417\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36417\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36417\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, 1D, 2D, 3D Convolution"}]},{"@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\/36417","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=36417"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36417\/revisions"}],"predecessor-version":[{"id":36418,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36417\/revisions\/36418"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}