{"id":36419,"date":"2024-11-01T09:48:20","date_gmt":"2024-11-01T09:48:20","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36419"},"modified":"2024-11-01T11:53:16","modified_gmt":"2024-11-01T11:53:16","slug":"deep-learning-pytorch-course-alexnet","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36419\/","title":{"rendered":"Deep Learning PyTorch Course, AlexNet"},"content":{"rendered":"<p><body><\/p>\n<p>Deep learning has emerged as one of the most notable technologies in the field of artificial intelligence (AI) in recent years. In particular, various deep learning-based models have demonstrated outstanding performance in the field of computer vision. Among them, AlexNet was an innovative model that led to the popularization of deep learning by achieving remarkable results in the 2012 ImageNet competition. It is a very deep neural network structure consisting of multiple convolutional layers and pooling layers.<\/p>\n<h2>1. Introduction to AlexNet Structure<\/h2>\n<p>AlexNet consists of the following key components:<\/p>\n<ul>\n<li><strong>Input Layer:<\/strong> Color image of size 224&#215;224<\/li>\n<li><strong>Layer 1: Convolutional Layer:<\/strong> Uses 96 filters, filter size 11&#215;11, stride 4<\/li>\n<li><strong>Layer 2: Max Pooling Layer:<\/strong> 3&#215;3 max pooling, stride 2<\/li>\n<li><strong>Layer 3: Convolutional Layer:<\/strong> Uses 256 filters, filter size 5&#215;5<\/li>\n<li><strong>Layer 4: Max Pooling Layer:<\/strong> 3&#215;3 max pooling, stride 2<\/li>\n<li><strong>Layer 5: Convolutional Layer:<\/strong> Uses 384 filters, filter size 3&#215;3<\/li>\n<li><strong>Layer 6: Convolutional Layer:<\/strong> Uses 384 filters, filter size 3&#215;3<\/li>\n<li><strong>Layer 7: Convolutional Layer:<\/strong> Uses 256 filters, filter size 3&#215;3<\/li>\n<li><strong>Layer 8: Max Pooling Layer:<\/strong> 3&#215;3 max pooling, stride 2<\/li>\n<li><strong>Layer 9: Fully Connected Layer:<\/strong> 4096 neurons<\/li>\n<li><strong>Layer 10: Fully Connected Layer:<\/strong> 4096 neurons<\/li>\n<li><strong>Layer 11: Output Layer:<\/strong> Softmax output for 1000 classes<\/li>\n<\/ul>\n<h2>2. How AlexNet Works<\/h2>\n<p>The basic idea of AlexNet is to extract features from images and use them to classify the images. In the initial stages, it learns high-level features of the image, and in subsequent stages, it combines them to learn more complex concepts. Each Convolutional Layer generates feature maps from the input image through filters, and the Max Pooling Layer downsamples these features to reduce the computational load.<\/p>\n<h2>3. Implementing AlexNet with PyTorch<\/h2>\n<p>Now, let&#8217;s implement the AlexNet model using PyTorch. PyTorch is a very useful framework for implementing deep learning models, providing a flexible and intuitive API.<\/p>\n<h3>3.1 Importing Packages<\/h3>\n<p>Import the packages needed to use PyTorch.<\/p>\n<pre><code>python\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torchvision import datasets, transforms\nfrom torch.utils.data import DataLoader\n    <\/code><\/pre>\n<h3>3.2 Defining the AlexNet Model<\/h3>\n<p>Now, we will define the AlexNet architecture. Each layer is implemented as a class that inherits from nn.Module.<\/p>\n<pre><code>python\nclass AlexNet(nn.Module):\n    def __init__(self, num_classes=1000):\n        super(AlexNet, self).__init__()\n        self.features = nn.Sequential(\n            nn.Conv2d(3, 96, kernel_size=11, stride=4, padding=0),\n            nn.ReLU(inplace=True),\n            nn.MaxPool2d(kernel_size=3, stride=2),\n            nn.Conv2d(96, 256, kernel_size=5, padding=2),\n            nn.ReLU(inplace=True),\n            nn.MaxPool2d(kernel_size=3, stride=2),\n            nn.Conv2d(256, 384, kernel_size=3, padding=1),\n            nn.ReLU(inplace=True),\n            nn.Conv2d(384, 384, kernel_size=3, padding=1),\n            nn.ReLU(inplace=True),\n            nn.Conv2d(384, 256, kernel_size=3, padding=1),\n            nn.ReLU(inplace=True),\n            nn.MaxPool2d(kernel_size=3, stride=2),\n        )\n        self.classifier = nn.Sequential(\n            nn.Dropout(),\n            nn.Linear(256 * 6 * 6, 4096),\n            nn.ReLU(inplace=True),\n            nn.Dropout(),\n            nn.Linear(4096, 4096),\n            nn.ReLU(inplace=True),\n            nn.Linear(4096, num_classes),\n        )\n\n    def forward(self, x):\n        x = self.features(x)\n        x = torch.flatten(x, 1)\n        x = self.classifier(x)\n        return x\n    <\/code><\/pre>\n<h3>3.3 Preparing the Dataset<\/h3>\n<p>Prepare the dataset for model training. Datasets such as CIFAR-10 or ImageNet can be used. Here, we will take CIFAR-10 as an example.<\/p>\n<pre><code>python\ntransform = transforms.Compose([\n    transforms.Resize((224, 224)),\n    transforms.ToTensor(),\n    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))\n])\n\ntrain_dataset = datasets.CIFAR10(root='.\/data', train=True, download=True, transform=transform)\ntrain_loader = DataLoader(dataset=train_dataset, batch_size=32, shuffle=True)\n    <\/code><\/pre>\n<h3>3.4 Training the Model<\/h3>\n<p>Define the loss function and optimizer for model training and proceed with the training process.<\/p>\n<pre><code>python\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\nmodel = AlexNet(num_classes=10).to(device)\ncriterion = nn.CrossEntropyLoss()\noptimizer = optim.Adam(model.parameters(), lr=0.001)\n\nfor epoch in range(10):  # Training for 10 epochs\n    model.train()\n    for images, labels in train_loader:\n        images, labels = images.to(device), labels.to(device)\n        \n        optimizer.zero_grad()\n        outputs = model(images)\n        loss = criterion(outputs, labels)\n        loss.backward()\n        optimizer.step()\n        \n    print(f'Epoch [{epoch+1}\/10], Loss: {loss.item():.4f}')\n    <\/code><\/pre>\n<h2>4. Conclusion<\/h2>\n<p>AlexNet is a simple model, but it played a very important role in the advancement of deep learning. It demonstrated that deep learning could achieve in-depth learning through datasets and became the foundation for many advanced models developed thereafter. Through this tutorial, we explored the structure of AlexNet and a simple implementation example using PyTorch. The path of deep learning is long, but if we understand the basic concepts well and move forward, we will be able to understand more complex models easily.<\/p>\n<h2>5. References<\/h2>\n<ul>\n<li>AlexNet paper: <a href=\"https:\/\/www.cs.toronto.edu\/~kriz\/imagenet\/2012\/DeepLearningDataSets.pdf\">ImageNet Classification with Deep Convolutional Neural Networks<\/a><\/li>\n<li>PyTorch Documentation: <a href=\"https:\/\/pytorch.org\/docs\/stable\/index.html\">PyTorch Documentation<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deep learning has emerged as one of the most notable technologies in the field of artificial intelligence (AI) in recent years. In particular, various deep learning-based models have demonstrated outstanding performance in the field of computer vision. Among them, AlexNet was an innovative model that led to the popularization of deep learning by achieving remarkable &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36419\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, AlexNet&#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-36419","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, AlexNet - \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\/36419\/\" \/>\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, AlexNet - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Deep learning has emerged as one of the most notable technologies in the field of artificial intelligence (AI) in recent years. In particular, various deep learning-based models have demonstrated outstanding performance in the field of computer vision. Among them, AlexNet was an innovative model that led to the popularization of deep learning by achieving remarkable &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, AlexNet&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36419\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:48:20+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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36419\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36419\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, AlexNet\",\"datePublished\":\"2024-11-01T09:48:20+00:00\",\"dateModified\":\"2024-11-01T11:53:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36419\/\"},\"wordCount\":454,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36419\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36419\/\",\"name\":\"Deep Learning PyTorch Course, AlexNet - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:48:20+00:00\",\"dateModified\":\"2024-11-01T11:53:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36419\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36419\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36419\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, AlexNet\"}]},{\"@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, AlexNet - \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\/36419\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, AlexNet - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Deep learning has emerged as one of the most notable technologies in the field of artificial intelligence (AI) in recent years. In particular, various deep learning-based models have demonstrated outstanding performance in the field of computer vision. Among them, AlexNet was an innovative model that led to the popularization of deep learning by achieving remarkable &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, AlexNet\"","og_url":"https:\/\/atmokpo.com\/w\/36419\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:48:20+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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36419\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36419\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, AlexNet","datePublished":"2024-11-01T09:48:20+00:00","dateModified":"2024-11-01T11:53:16+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36419\/"},"wordCount":454,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36419\/","url":"https:\/\/atmokpo.com\/w\/36419\/","name":"Deep Learning PyTorch Course, AlexNet - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:48:20+00:00","dateModified":"2024-11-01T11:53:16+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36419\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36419\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36419\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, AlexNet"}]},{"@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\/36419","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=36419"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36419\/revisions"}],"predecessor-version":[{"id":36420,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36419\/revisions\/36420"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}