{"id":36539,"date":"2024-11-01T09:49:23","date_gmt":"2024-11-01T09:49:23","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36539"},"modified":"2024-11-01T11:52:47","modified_gmt":"2024-11-01T11:52:47","slug":"deep-learning-pytorch-course-deep-learning-structure","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36539\/","title":{"rendered":"Deep Learning PyTorch Course, Deep Learning Structure"},"content":{"rendered":"<p><body><\/p>\n<p>Deep learning is a field of artificial intelligence (AI) that involves creating machines that learn from data through artificial neural networks to perform prediction and classification tasks. The advancements in deep learning over the past few years have brought about revolutionary changes and achievements in the field of artificial intelligence. In this course, we will explore the fundamental structure of deep learning in detail using PyTorch.<\/p>\n<h2>1. Basic Concepts of Deep Learning<\/h2>\n<p>In deep learning, data is received as input, processed through multiple layers, and generates the final output. During this process, artificial neural networks (ANN) are used. Neural networks are composed of multiple connected units called nodes (or neurons), and each neuron receives input, multiplies it by weights, adds a bias, and applies a nonlinear activation function.<\/p>\n<h3>1.1 Basic Structure of Neural Networks<\/h3>\n<p>The basic structure of a neural network consists of an input layer, hidden layers, and an output layer. Each layer is connected to the neurons of the next layer; the input layer accepts data, and the output layer provides results.<\/p>\n<pre><code>class SimpleNN(nn.Module):\n    def __init__(self):\n        super(SimpleNN, self).__init__()\n        self.fc1 = nn.Linear(2, 3)  # 2 inputs, 3 outputs\n        self.fc2 = nn.Linear(3, 1)  # 3 inputs, 1 output\n\n    def forward(self, x):\n        x = F.relu(self.fc1(x))\n        x = self.fc2(x)\n        return x\n<\/code><\/pre>\n<h2>2. Introduction to PyTorch<\/h2>\n<p>PyTorch is a popular deep learning framework developed by Facebook AI Research, which offers easy-to-use and flexible features. Using PyTorch allows for simple GPU acceleration with tensor operations and supports dynamic computation graphs.<\/p>\n<h3>2.1 Basic Tensor<\/h3>\n<p>In deep learning, a tensor is the fundamental structure for representing data. A 1D tensor can be thought of as a vector, a 2D tensor as a matrix, and a 3D tensor as a multidimensional array.<\/p>\n<pre><code>import torch\n\n    # 1D tensor\n    tensor_1d = torch.tensor([1, 2, 3])\n\n    # 2D tensor\n    tensor_2d = torch.tensor([[1, 2], [3, 4]])\n\n    # 3D tensor\n    tensor_3d = torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])\n<\/code><\/pre>\n<h2>3. Building a Deep Learning Model<\/h2>\n<p>Now, let&#8217;s build a simple deep learning model. We will create a basic neural network model using various APIs provided by PyTorch.<\/p>\n<h3>3.1 Data Preprocessing<\/h3>\n<p>Data preprocessing plays an important role in deep learning. It is necessary to prepare the dataset and transform it into a suitable format for training.<\/p>\n<pre><code>from sklearn.datasets import make_moons\n    from sklearn.model_selection import train_test_split\n    from sklearn.preprocessing import StandardScaler\n\n    X, y = make_moons(n_samples=1000, noise=0.2, random_state=42)\n    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n    # Data standardization\n    scaler = StandardScaler()\n    X_train = scaler.fit_transform(X_train)\n    X_test = scaler.transform(X_test)\n<\/code><\/pre>\n<h3>3.2 Model Definition<\/h3>\n<p>As mentioned earlier, the model is defined by inheriting from nn.Module. This time, let&#8217;s use the sigmoid activation function instead of Relu.<\/p>\n<pre><code>import torch.nn as nn\n    import torch.nn.functional as F\n\n    class SimpleNN(nn.Module):\n        def __init__(self):\n            super(SimpleNN, self).__init__()\n            self.fc1 = nn.Linear(2, 3)\n            self.fc2 = nn.Linear(3, 1)\n\n        def forward(self, x):\n            x = F.sigmoid(self.fc1(x))\n            x = self.fc2(x)\n            return x\n<\/code><\/pre>\n<h3>3.3 Model Training<\/h3>\n<p>To train the model, we need to define the loss function and optimization algorithm. We can use binary cross-entropy (BCE) as the loss function and Adam for optimization.<\/p>\n<pre><code>import torch.optim as optim\n\n    model = SimpleNN()\n    criterion = nn.BCEWithLogitsLoss()\n    optimizer = optim.Adam(model.parameters(), lr=0.001)\n\n    X_train_tensor = torch.tensor(X_train, dtype=torch.float32)\n    y_train_tensor = torch.tensor(y_train, dtype=torch.float32).view(-1, 1)\n\n    for epoch in range(1000):\n        model.train()\n        optimizer.zero_grad()\n        outputs = model(X_train_tensor)\n        loss = criterion(outputs, y_train_tensor)\n        loss.backward()\n        optimizer.step()\n\n        if (epoch + 1) % 100 == 0:\n            print(f'Epoch [{epoch + 1}\/1000], Loss: {loss.item():.4f}')\n<\/code><\/pre>\n<h3>3.4 Model Evaluation<\/h3>\n<p>After the model training is complete, we evaluate the model&#8217;s performance using the test data. Here, we measure accuracy.<\/p>\n<pre><code>model.eval()\n    with torch.no_grad():\n        X_test_tensor = torch.tensor(X_test, dtype=torch.float32)\n        y_pred = model(X_test_tensor)\n        y_pred = (y_pred > 0).float()\n        accuracy = (y_pred.view(-1) == torch.tensor(y_test, dtype=torch.float32)).float().mean()\n        print(f'Accuracy: {accuracy:.4f}')\n<\/code><\/pre>\n<h2>4. Conclusion<\/h2>\n<p>In this lecture, we examined the basic concepts of deep learning and the process of building a simple neural network model using PyTorch. Deep learning can be applied to various fields, and more complex models require deeper structures and diverse techniques. In the next lecture, we will learn about more complex deep learning architectures such as CNNs (Convolutional Neural Networks) and RNNs (Recurrent Neural Networks).<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deep learning is a field of artificial intelligence (AI) that involves creating machines that learn from data through artificial neural networks to perform prediction and classification tasks. The advancements in deep learning over the past few years have brought about revolutionary changes and achievements in the field of artificial intelligence. In this course, we will &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36539\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, Deep Learning Structure&#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-36539","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, Deep Learning Structure - \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\/36539\/\" \/>\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, Deep Learning Structure - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Deep learning is a field of artificial intelligence (AI) that involves creating machines that learn from data through artificial neural networks to perform prediction and classification tasks. The advancements in deep learning over the past few years have brought about revolutionary changes and achievements in the field of artificial intelligence. In this course, we will &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, Deep Learning Structure&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36539\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:49:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:47+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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36539\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36539\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, Deep Learning Structure\",\"datePublished\":\"2024-11-01T09:49:23+00:00\",\"dateModified\":\"2024-11-01T11:52:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36539\/\"},\"wordCount\":452,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36539\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36539\/\",\"name\":\"Deep Learning PyTorch Course, Deep Learning Structure - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:49:23+00:00\",\"dateModified\":\"2024-11-01T11:52:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36539\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36539\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36539\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, Deep Learning Structure\"}]},{\"@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, Deep Learning Structure - \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\/36539\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, Deep Learning Structure - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Deep learning is a field of artificial intelligence (AI) that involves creating machines that learn from data through artificial neural networks to perform prediction and classification tasks. The advancements in deep learning over the past few years have brought about revolutionary changes and achievements in the field of artificial intelligence. In this course, we will &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, Deep Learning Structure\"","og_url":"https:\/\/atmokpo.com\/w\/36539\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:49:23+00:00","article_modified_time":"2024-11-01T11:52:47+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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36539\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36539\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, Deep Learning Structure","datePublished":"2024-11-01T09:49:23+00:00","dateModified":"2024-11-01T11:52:47+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36539\/"},"wordCount":452,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36539\/","url":"https:\/\/atmokpo.com\/w\/36539\/","name":"Deep Learning PyTorch Course, Deep Learning Structure - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:49:23+00:00","dateModified":"2024-11-01T11:52:47+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36539\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36539\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36539\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, Deep Learning Structure"}]},{"@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\/36539","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=36539"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36539\/revisions"}],"predecessor-version":[{"id":36540,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36539\/revisions\/36540"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}