{"id":36659,"date":"2024-11-01T09:50:22","date_gmt":"2024-11-01T09:50:22","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36659"},"modified":"2024-11-01T11:52:19","modified_gmt":"2024-11-01T11:52:19","slug":"deep-learning-pytorch-course-overview-of-pytorch","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36659\/","title":{"rendered":"Deep Learning PyTorch Course, Overview of PyTorch"},"content":{"rendered":"<p><body><\/p>\n<p>Deep learning is a field of machine learning that uses artificial neural networks to process and learn from data. In recent years, much of machine learning has evolved into deep learning technologies, demonstrating their potential in various fields such as data analysis, image recognition, and natural language processing.<\/p>\n<h2>1. What is PyTorch?<\/h2>\n<p>PyTorch is an open-source machine learning library developed by the Facebook AI Research (FAIR). PyTorch has gained popularity among researchers and developers for developing deep learning models due to its natural and intuitive approach. This is mainly due to the following reasons:<\/p>\n<ul>\n<li><strong>Flexibility:<\/strong> PyTorch uses a dynamic computation graph, allowing for free modification of the model structure. This enables flexible model design.<\/li>\n<li><strong>User-friendly:<\/strong> With its intuitive API design, it provides a familiar environment for Python users.<\/li>\n<li><strong>GPU support:<\/strong> It can process large datasets using GPUs and operates at high speed.<\/li>\n<\/ul>\n<h2>2. Key Features of PyTorch<\/h2>\n<p>Some key features of PyTorch include:<\/p>\n<h3>2.1. Dynamic Graphs<\/h3>\n<p>PyTorch uses a dynamic computation graph in a &#8220;Define-by-Run&#8221; manner. This graph is constructed at runtime, making debugging easier during model development.<\/p>\n<h3>2.2. Tensors<\/h3>\n<p>The basic data structure in PyTorch is the tensor. A tensor is a multi-dimensional array that is very similar to a NumPy array but can perform operations using GPUs. Tensors are crucial for storing data of various sizes and shapes.<\/p>\n<h3>2.3. Autograd<\/h3>\n<p>PyTorch provides an Autograd feature that automatically calculates the derivatives of all operations. This simplifies model training through backpropagation.<\/p>\n<h2>3. Installing PyTorch<\/h2>\n<p>Installing PyTorch is very straightforward. You can install it using the following command:<\/p>\n<pre class=\"example\"><code>pip install torch torchvision torchaudio<\/code><\/pre>\n<p>This command installs PyTorch, torchvision, and torchaudio. The torchvision library is useful for image processing, while torchaudio is used to handle audio data.<\/p>\n<h2>4. Basic Usage of PyTorch<\/h2>\n<p>Let&#8217;s take a look at basic tensor operations in PyTorch. The following example shows how to create tensors and perform basic operations:<\/p>\n<pre class=\"example\"><code>\nimport torch\n\n# Create tensors\ntensor_a = torch.tensor([[1, 2], [3, 4]])\ntensor_b = torch.tensor([[5, 6], [7, 8]])\n\n# Tensor addition\nresult_add = tensor_a + tensor_b\n\n# Tensor multiplication\nresult_mul = torch.matmul(tensor_a, tensor_b)\n\nprint(\"Tensor A:\\n\", tensor_a)\nprint(\"Tensor B:\\n\", tensor_b)\nprint(\"Addition Result:\\n\", result_add)\nprint(\"Multiplication Result:\\n\", result_mul)\n    <\/code><\/pre>\n<h3>4.1. Creating Tensors<\/h3>\n<p>The code above shows how to create two 2&#215;2 tensors. It performs basic addition and multiplication using the previously created tensors.<\/p>\n<h3>4.2. Tensor Operations<\/h3>\n<p>Operations between tensors are very intuitive and support most linear algebra operations. Running the code above produces the following results:<\/p>\n<pre class=\"example\"><code>\nTensor A:\n tensor([[1, 2],\n        [3, 4]])\nTensor B:\n tensor([[5, 6],\n        [7, 8]])\nAddition Result:\n tensor([[ 6,  8],\n        [10, 12]])\nMultiplication Result:\n tensor([[19, 22],\n        [43, 50]])\n    <\/code><\/pre>\n<h2>5. Building a PyTorch Model<\/h2>\n<p>The process of building a deep learning model with PyTorch proceeds through the following steps:<\/p>\n<ol>\n<li>Data preparation<\/li>\n<li>Model definition<\/li>\n<li>Loss function and optimizer definition<\/li>\n<li>Training loop<\/li>\n<li>Validation and testing<\/li>\n<\/ol>\n<h3>5.1. Data Preparation<\/h3>\n<p>First, we start with data preparation. Below is the code to load the MNIST dataset:<\/p>\n<pre class=\"example\"><code>\nfrom torchvision import datasets, transforms\n\n# Define data transformations\ntransform = transforms.Compose([\n    transforms.ToTensor(),\n    transforms.Normalize((0.5,), (0.5,))\n])\n\n# Download the MNIST dataset\ntrain_data = datasets.MNIST(root='data', train=True, download=True, transform=transform)\ntest_data = datasets.MNIST(root='data', train=False, download=True, transform=transform)\n    <\/code><\/pre>\n<h3>5.2. Model Definition<\/h3>\n<p>Defining a neural network model is done by inheriting from the nn.Module class. Below is an example of defining a simple fully connected neural network:<\/p>\n<pre class=\"example\"><code>\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass SimpleNN(nn.Module):\n    def __init__(self):\n        super(SimpleNN, self).__init__()\n        self.fc1 = nn.Linear(28 * 28, 128)\n        self.fc2 = nn.Linear(128, 10)\n\n    def forward(self, x):\n        x = x.view(-1, 28 * 28)  # Flatten the input\n        x = F.relu(self.fc1(x))\n        x = self.fc2(x)\n        return x\n    <\/code><\/pre>\n<h3>5.3. Loss Function and Optimizer Definition<\/h3>\n<p>The loss function and optimizer are essential elements for model training:<\/p>\n<pre class=\"example\"><code>\nimport torch.optim as optim\n\nmodel = SimpleNN()\ncriterion = nn.CrossEntropyLoss()\noptimizer = optim.Adam(model.parameters(), lr=0.001)\n    <\/code><\/pre>\n<h3>5.4. Training Loop<\/h3>\n<p>The training loop for the model can be defined as follows:<\/p>\n<pre class=\"example\"><code>\nfrom torch.utils.data import DataLoader\n\ntrain_loader = DataLoader(train_data, batch_size=64, shuffle=True)\n\n# Training loop\nfor epoch in range(5):  # 5 epochs\n    for data, target in train_loader:\n        optimizer.zero_grad()  # Zero the gradient\n        output = model(data)   # Model prediction\n        loss = criterion(output, target)  # Calculate loss\n        loss.backward()        # Backpropagation\n        optimizer.step()       # Update parameters\n    print(f'Epoch {epoch+1}, Loss: {loss.item()}')\n    <\/code><\/pre>\n<h3>5.5. Validation and Testing<\/h3>\n<p>After training, the model can be evaluated with the test data to check its performance:<\/p>\n<pre class=\"example\"><code>\ntest_loader = DataLoader(test_data, batch_size=64, shuffle=False)\n\ncorrect = 0\ntotal = 0\n\nwith torch.no_grad():\n    for data, target in test_loader:\n        output = model(data)\n        _, predicted = torch.max(output.data, 1)\n        total += target.size(0)\n        correct += (predicted == target).sum().item()\n\nprint(f'Accuracy: {100 * correct \/ total}%')\n    <\/code><\/pre>\n<h2>6. Conclusion<\/h2>\n<p>In this article, we explained an overview of PyTorch and its basic usage. PyTorch is a very useful tool for deep learning research and development, and its flexibility and powerful features have made it popular among many researchers and engineers. In the next lecture, we will cover various advanced topics and practical applications using PyTorch. Stay tuned!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deep learning is a field of machine learning that uses artificial neural networks to process and learn from data. In recent years, much of machine learning has evolved into deep learning technologies, demonstrating their potential in various fields such as data analysis, image recognition, and natural language processing. 1. What is PyTorch? PyTorch is an &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36659\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, Overview of PyTorch&#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-36659","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, Overview of PyTorch - \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\/36659\/\" \/>\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, Overview of PyTorch - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Deep learning is a field of machine learning that uses artificial neural networks to process and learn from data. In recent years, much of machine learning has evolved into deep learning technologies, demonstrating their potential in various fields such as data analysis, image recognition, and natural language processing. 1. What is PyTorch? PyTorch is an &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, Overview of PyTorch&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36659\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:50:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:19+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\/36659\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36659\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, Overview of PyTorch\",\"datePublished\":\"2024-11-01T09:50:22+00:00\",\"dateModified\":\"2024-11-01T11:52:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36659\/\"},\"wordCount\":536,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36659\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36659\/\",\"name\":\"Deep Learning PyTorch Course, Overview of PyTorch - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:50:22+00:00\",\"dateModified\":\"2024-11-01T11:52:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36659\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36659\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36659\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, Overview of PyTorch\"}]},{\"@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, Overview of PyTorch - \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\/36659\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, Overview of PyTorch - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Deep learning is a field of machine learning that uses artificial neural networks to process and learn from data. In recent years, much of machine learning has evolved into deep learning technologies, demonstrating their potential in various fields such as data analysis, image recognition, and natural language processing. 1. What is PyTorch? PyTorch is an &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, Overview of PyTorch\"","og_url":"https:\/\/atmokpo.com\/w\/36659\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:50:22+00:00","article_modified_time":"2024-11-01T11:52:19+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\/36659\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36659\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, Overview of PyTorch","datePublished":"2024-11-01T09:50:22+00:00","dateModified":"2024-11-01T11:52:19+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36659\/"},"wordCount":536,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36659\/","url":"https:\/\/atmokpo.com\/w\/36659\/","name":"Deep Learning PyTorch Course, Overview of PyTorch - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:50:22+00:00","dateModified":"2024-11-01T11:52:19+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36659\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36659\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36659\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, Overview of PyTorch"}]},{"@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\/36659","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=36659"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36659\/revisions"}],"predecessor-version":[{"id":36660,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36659\/revisions\/36660"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}