{"id":36645,"date":"2024-11-01T09:50:16","date_gmt":"2024-11-01T09:50:16","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36645"},"modified":"2024-11-01T11:52:23","modified_gmt":"2024-11-01T11:52:23","slug":"deep-learning-pytorch-course-what-is-colab","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36645\/","title":{"rendered":"Deep Learning PyTorch Course, What is Colab"},"content":{"rendered":"<p>In this lecture, we will take a detailed look at Google Colab, a tool that is essential for learning deep learning. Using Colab along with one of the deep learning libraries, <em>PyTorch<\/em>, allows for easy training and experimentation of machine learning and deep learning models. In this text, we will present an overview of Colab&#8217;s features, benefits, and an example of building a simple deep learning model with PyTorch in Python.<\/p>\n<h2>1. What is Google Colab?<\/h2>\n<p><strong>Google Colaboratory<\/strong>, commonly referred to as <strong>Colab<\/strong>, is a free Jupyter notebook environment that supports machine learning, data analysis, and education using Python. Colab is integrated with Google Drive, enabling users to easily store and share their data.<\/p>\n<h3>1.1 Key Features<\/h3>\n<ul>\n<li><strong>Support for GPU and TPU:<\/strong> Free NVIDIA GPU and TPU are provided to speed up the training of complex deep learning models.<\/li>\n<li><strong>Google Drive Integration:<\/strong> Users can easily manage and share their data and results.<\/li>\n<li><strong>Data Visualization Tools:<\/strong> Supports various visualization libraries such as Matplotlib and Seaborn for smooth data analysis.<\/li>\n<li><strong>Easy Library Installation:<\/strong> You can easily install libraries like TensorFlow and PyTorch as needed.<\/li>\n<\/ul>\n<h3>1.2 Benefits of Colab<\/h3>\n<p>There are various benefits to using Colab. First, users can perform complex tasks without consuming local computer resources as they work in a cloud environment. This is particularly advantageous for large-scale deep learning projects that require GPU. Furthermore, it allows users to visually confirm the results along with the code execution, making it useful for research and educational purposes.<\/p>\n<h2>2. What is PyTorch?<\/h2>\n<p><strong>PyTorch<\/strong> is an open-source machine learning library primarily used for deep learning, implemented in Python and C++. PyTorch has the property of dynamic computational graphs, making it particularly suitable for research and prototyping. Additionally, it is highly compatible with Python, making the process of writing and debugging code easier.<\/p>\n<h3>2.1 Installation Method<\/h3>\n<p>PyTorch can be easily used in Colab. You can install the essential libraries related to PyTorch by running the cell below.<\/p>\n<pre><code>!pip install torch torchvision<\/code><\/pre>\n<h2>3. A Simple Deep Learning Model Using PyTorch<\/h2>\n<p>Now, let&#8217;s implement a simple neural network model using PyTorch in Google Colab. In this example, we will create a digit recognizer using the MNIST dataset.<\/p>\n<h3>3.1 Preparing the Dataset<\/h3>\n<p>First, we prepare the MNIST dataset. MNIST consists of digit images of 28&#215;28 pixels and is commonly used as a benchmark dataset to evaluate the performance of deep learning models.<\/p>\n<pre><code>import torch\nimport torchvision\nimport torchvision.transforms as transforms\n\n# Define data transformations\ntransform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))])\n\n# Download training set and test set\ntrainset = torchvision.datasets.MNIST(root='.\/data', train=True, download=True, transform=transform)\ntrainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)\n\ntestset = torchvision.datasets.MNIST(root='.\/data', train=False, download=True, transform=transform)\ntestloader = torch.utils.data.DataLoader(testset, batch_size=64, shuffle=False)<\/code><\/pre>\n<h3>3.2 Designing the Neural Network<\/h3>\n<p>We will define the neural network architecture as follows. Here we will use a simple model consisting of an input layer, two hidden layers, and an output layer.<\/p>\n<pre><code>import torch.nn as nn\nimport torch.optim as optim\n\nclass SimpleNN(nn.Module):\n    def __init__(self):\n        super(SimpleNN, self).__init__()\n        self.fc1 = nn.Linear(28 * 28, 128)  # Input layer (784 nodes) -> First hidden layer (128 nodes)\n        self.fc2 = nn.Linear(128, 64)        # First hidden layer -> Second hidden layer (64 nodes)\n        self.fc3 = nn.Linear(64, 10)         # Second hidden layer -> Output layer (10 nodes)\n\n    def forward(self, x):\n        x = x.view(-1, 28 * 28)  # Convert each image to a 1D vector\n        x = torch.relu(self.fc1(x))  # First hidden layer\n        x = torch.relu(self.fc2(x))  # Second hidden layer\n        x = self.fc3(x)  # Output layer\n        return x\n\nmodel = SimpleNN()<\/code><\/pre>\n<h3>3.3 Defining the Loss Function and Optimization Algorithm<\/h3>\n<p>We will use <em>CrossEntropyLoss<\/em> as the loss function and <em>Adam Optimizer<\/em> to train the model.<\/p>\n<pre><code>criterion = nn.CrossEntropyLoss()\noptimizer = optim.Adam(model.parameters(), lr=0.001)<\/code><\/pre>\n<h3>3.4 Training the Model<\/h3>\n<p>The next step is the process of training the model. We will update the model weights and reduce the loss over several epochs.<\/p>\n<pre><code>for epoch in range(5):  # Train for 5 epochs\n    running_loss = 0.0\n    for inputs, labels in trainloader:\n        optimizer.zero_grad()  # Reset gradients\n        outputs = model(inputs)  # Generate outputs by putting inputs into the model\n        loss = criterion(outputs, labels)  # Calculate loss\n        loss.backward()  # Backpropagation\n        optimizer.step()  # Optimization\n        running_loss += loss.item()  # Accumulate loss\n        \n    print(f'Epoch {epoch + 1}, Loss: {running_loss \/ len(trainloader)}')  # Output average loss<\/code><\/pre>\n<h3>3.5 Evaluating the Model<\/h3>\n<p>Finally, we will evaluate the model&#8217;s performance using the test set. We will calculate the accuracy while passing through the prepared test dataset.<\/p>\n<pre><code>correct = 0\ntotal = 0\nwith torch.no_grad():\n    for inputs, labels in testloader:\n        outputs = model(inputs)\n        _, predicted = torch.max(outputs.data, 1)  # Select the class with the highest probability\n        total += labels.size(0)\n        correct += (predicted == labels).sum().item()\n\nprint(f'Accuracy: {100 * correct \/ total}%')  # Output accuracy<\/code><\/pre>\n<h2>4. Conclusion<\/h2>\n<p>In this post, we explored the features and benefits of Google Colab, as well as how to build a simple deep learning model using PyTorch. Google Colab offers many advantages to data scientists and researchers, enabling them to perform deep learning in a highly useful environment alongside PyTorch. We will return with a variety of advanced topics in the future!<\/p>\n<footer>\n<p>Welcome to the world of deep learning. We hope you continue to learn new technologies and methods as you move forward!<\/p>\n<\/footer>\n","protected":false},"excerpt":{"rendered":"<p>In this lecture, we will take a detailed look at Google Colab, a tool that is essential for learning deep learning. Using Colab along with one of the deep learning libraries, PyTorch, allows for easy training and experimentation of machine learning and deep learning models. In this text, we will present an overview of Colab&#8217;s &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36645\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, What is Colab&#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-36645","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, What is Colab - \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\/36645\/\" \/>\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, What is Colab - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this lecture, we will take a detailed look at Google Colab, a tool that is essential for learning deep learning. Using Colab along with one of the deep learning libraries, PyTorch, allows for easy training and experimentation of machine learning and deep learning models. In this text, we will present an overview of Colab&#8217;s &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, What is Colab&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36645\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:50:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:23+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\/36645\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36645\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, What is Colab\",\"datePublished\":\"2024-11-01T09:50:16+00:00\",\"dateModified\":\"2024-11-01T11:52:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36645\/\"},\"wordCount\":581,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36645\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36645\/\",\"name\":\"Deep Learning PyTorch Course, What is Colab - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:50:16+00:00\",\"dateModified\":\"2024-11-01T11:52:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36645\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36645\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36645\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, What is Colab\"}]},{\"@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, What is Colab - \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\/36645\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, What is Colab - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this lecture, we will take a detailed look at Google Colab, a tool that is essential for learning deep learning. Using Colab along with one of the deep learning libraries, PyTorch, allows for easy training and experimentation of machine learning and deep learning models. In this text, we will present an overview of Colab&#8217;s &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, What is Colab\"","og_url":"https:\/\/atmokpo.com\/w\/36645\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:50:16+00:00","article_modified_time":"2024-11-01T11:52:23+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\/36645\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36645\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, What is Colab","datePublished":"2024-11-01T09:50:16+00:00","dateModified":"2024-11-01T11:52:23+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36645\/"},"wordCount":581,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36645\/","url":"https:\/\/atmokpo.com\/w\/36645\/","name":"Deep Learning PyTorch Course, What is Colab - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:50:16+00:00","dateModified":"2024-11-01T11:52:23+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36645\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36645\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36645\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, What is Colab"}]},{"@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\/36645","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=36645"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36645\/revisions"}],"predecessor-version":[{"id":36646,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36645\/revisions\/36646"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}