{"id":36681,"date":"2024-11-01T09:50:33","date_gmt":"2024-11-01T09:50:33","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36681"},"modified":"2024-11-01T11:52:14","modified_gmt":"2024-11-01T11:52:14","slug":"deep-learning-pytorch-course-training-process-monitoring","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36681\/","title":{"rendered":"Deep Learning PyTorch Course, Training Process Monitoring"},"content":{"rendered":"<p><body><\/p>\n<p>Monitoring the performance of the model during the training process of deep learning is very important. It helps to adjust hyperparameters appropriately, prevent model overfitting, and improve generalization performance. In this article, we will explain how to monitor the training process using the PyTorch framework.<\/p>\n<h2>1. Importance of Monitoring the Training Process<\/h2>\n<p>When training a deep learning model, simply checking the model&#8217;s accuracy is not enough. By monitoring the loss and accuracy on the training and validation datasets:<\/p>\n<ul>\n<li>Early detection of when the model may overfit or underlearn<\/li>\n<li>Identification of the need for hyperparameter tuning<\/li>\n<li>Evaluation of the potential for performance improvement of the model<\/li>\n<\/ul>\n<p>For these reasons, visualizing and monitoring the training process is essential.<\/p>\n<h2>2. Installing PyTorch<\/h2>\n<p>First, you need to have PyTorch installed. You can install it using the following command:<\/p>\n<pre><code>pip install torch torchvision<\/code><\/pre>\n<h2>3. Preparing the Dataset<\/h2>\n<p>Here, we will demonstrate how to monitor the training process using a simple example of classifying digits with the MNIST dataset. You can load the MNIST dataset through PyTorch&#8217;s torchvision package.<\/p>\n<pre><code>import torch\nimport torchvision\nimport torchvision.transforms as transforms\n\n# Data preprocessing\ntransform = transforms.Compose([\n    transforms.ToTensor(),\n    transforms.Normalize((0.5,), (0.5,))\n])\n\n# Training dataset\ntrainset = torchvision.datasets.MNIST(root='.\/data', train=True, download=True, transform=transform)\ntrainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)\n\n# Validation dataset\ntestset = torchvision.datasets.MNIST(root='.\/data', train=False, download=True, transform=transform)\ntestloader = torch.utils.data.DataLoader(testset, batch_size=64, shuffle=False)\n<\/code><\/pre>\n<h2>4. Defining the Model<\/h2>\n<p>Next, we will define a neural network model. We will use a simple multilayer perceptron (MLP) structure.<\/p>\n<pre><code>import torch.nn as nn\nimport torch.nn.functional as F\n\nclass Net(nn.Module):\n    def __init__(self):\n        super(Net, self).__init__()\n        self.fc1 = nn.Linear(28 * 28, 128)\n        self.fc2 = nn.Linear(128, 64)\n        self.fc3 = nn.Linear(64, 10)\n\n    def forward(self, x):\n        x = x.view(-1, 28 * 28)  # Flatten\n        x = F.relu(self.fc1(x))  # First layer\n        x = F.relu(self.fc2(x))  # Second layer\n        x = self.fc3(x)          # Output layer\n        return x\n\n# Create model instance\nmodel = Net()\n<\/code><\/pre>\n<h2>5. Loss Function and Optimization Algorithm<\/h2>\n<p>Set the loss function and optimization algorithm. Typically, cross-entropy loss and Adam optimization are used.<\/p>\n<pre><code>import torch.optim as optim\n\ncriterion = nn.CrossEntropyLoss()\noptimizer = optim.Adam(model.parameters(), lr=0.001)\n<\/code><\/pre>\n<h2>6. Setting Up the Training Process<\/h2>\n<p>Set up the training process and prepare to monitor it. We will save and visualize the loss values and accuracy at each epoch.<\/p>\n<pre><code>import matplotlib.pyplot as plt\n\nnum_epochs = 10\ntrain_losses = []\ntest_losses = []\ntrain_accuracies = []\ntest_accuracies = []\n\n# Training function\ndef train():\n    model.train()  # Switch model to training mode\n    running_loss = 0.0\n    correct = 0\n    total = 0\n    \n    for inputs, labels in trainloader:\n        optimizer.zero_grad()  # Reset gradients\n        outputs = model(inputs)  # Predictions\n        loss = criterion(outputs, labels)  # Calculate loss\n        loss.backward()  # Backpropagation\n        optimizer.step()  # Update parameters\n        \n        running_loss += loss.item()\n        _, predicted = torch.max(outputs.data, 1)\n        total += labels.size(0)\n        correct += (predicted == labels).sum().item()\n    \n    # Save training loss and accuracy\n    train_losses.append(running_loss \/ len(trainloader))\n    train_accuracies.append(correct \/ total)\n\n# Validation function\ndef test():\n    model.eval()  # Switch model to evaluation mode\n    running_loss = 0.0\n    correct = 0\n    total = 0\n\n    with torch.no_grad():  # Disable gradient calculation\n        for inputs, labels in testloader:\n            outputs = model(inputs)  # Predictions\n            loss = criterion(outputs, labels)  # Calculate loss\n            \n            running_loss += loss.item()\n            _, predicted = torch.max(outputs.data, 1)\n            total += labels.size(0)\n            correct += (predicted == labels).sum().item()\n    \n    # Save validation loss and accuracy\n    test_losses.append(running_loss \/ len(testloader))\n    test_accuracies.append(correct \/ total)\n<\/code><\/pre>\n<h2>7. Training Loop<\/h2>\n<p>Run the training loop to train the model and record the training and validation loss and accuracy at each epoch.<\/p>\n<pre><code>for epoch in range(num_epochs):\n    train()  # Call training function\n    test()   # Call validation function\n\n    print(f'Epoch [{epoch+1}\/{num_epochs}], '\n          f'Train Loss: {train_losses[-1]:.4f}, Train Accuracy: {train_accuracies[-1]:.4f}, '\n          f'Test Loss: {test_losses[-1]:.4f}, Test Accuracy: {test_accuracies[-1]:.4f}')\n<\/code><\/pre>\n<h2>8. Visualizing Results<\/h2>\n<p>We will use the Matplotlib library to visualize the training process by plotting the loss and accuracy.<\/p>\n<pre><code>plt.figure(figsize=(12, 5))\n\n# Visualizing Loss\nplt.subplot(1, 2, 1)\nplt.plot(train_losses, label='Train Loss')\nplt.plot(test_losses, label='Test Loss')\nplt.title('Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend()\n\n# Visualizing Accuracy\nplt.subplot(1, 2, 2)\nplt.plot(train_accuracies, label='Train Accuracy')\nplt.plot(test_accuracies, label='Test Accuracy')\nplt.title('Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend()\n\nplt.tight_layout()\nplt.show()\n<\/code><\/pre>\n<h2>9. Conclusion<\/h2>\n<p>In this course, we covered how to monitor the training process of deep learning models using PyTorch. Various visualization techniques and metrics can provide insights to improve the model&#8217;s performance.<\/p>\n<p>As such, monitoring and visualizing the training process play a crucial role in optimizing the model&#8217;s performance, so it is advisable to always keep this in mind and apply the content.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Monitoring the performance of the model during the training process of deep learning is very important. It helps to adjust hyperparameters appropriately, prevent model overfitting, and improve generalization performance. In this article, we will explain how to monitor the training process using the PyTorch framework. 1. Importance of Monitoring the Training Process When training a &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36681\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, Training Process Monitoring&#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-36681","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, Training Process Monitoring - \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\/36681\/\" \/>\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, Training Process Monitoring - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Monitoring the performance of the model during the training process of deep learning is very important. It helps to adjust hyperparameters appropriately, prevent model overfitting, and improve generalization performance. In this article, we will explain how to monitor the training process using the PyTorch framework. 1. Importance of Monitoring the Training Process When training a &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, Training Process Monitoring&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36681\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:50:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:14+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\/36681\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36681\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, Training Process Monitoring\",\"datePublished\":\"2024-11-01T09:50:33+00:00\",\"dateModified\":\"2024-11-01T11:52:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36681\/\"},\"wordCount\":348,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36681\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36681\/\",\"name\":\"Deep Learning PyTorch Course, Training Process Monitoring - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:50:33+00:00\",\"dateModified\":\"2024-11-01T11:52:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36681\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36681\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36681\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, Training Process Monitoring\"}]},{\"@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, Training Process Monitoring - \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\/36681\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, Training Process Monitoring - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Monitoring the performance of the model during the training process of deep learning is very important. It helps to adjust hyperparameters appropriately, prevent model overfitting, and improve generalization performance. In this article, we will explain how to monitor the training process using the PyTorch framework. 1. Importance of Monitoring the Training Process When training a &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, Training Process Monitoring\"","og_url":"https:\/\/atmokpo.com\/w\/36681\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:50:33+00:00","article_modified_time":"2024-11-01T11:52:14+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\/36681\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36681\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, Training Process Monitoring","datePublished":"2024-11-01T09:50:33+00:00","dateModified":"2024-11-01T11:52:14+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36681\/"},"wordCount":348,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36681\/","url":"https:\/\/atmokpo.com\/w\/36681\/","name":"Deep Learning PyTorch Course, Training Process Monitoring - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:50:33+00:00","dateModified":"2024-11-01T11:52:14+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36681\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36681\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36681\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, Training Process Monitoring"}]},{"@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\/36681","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=36681"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36681\/revisions"}],"predecessor-version":[{"id":36682,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36681\/revisions\/36682"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}