Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 9_예습과제_김정은 #139

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Week 9_예습과제_김정은.pdf
Binary file not shown.
104 changes: 104 additions & 0 deletions Week_9_복습과제_김정은.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "MAyG6GGTU_mC",
"outputId": "969cf618-39a3-4a19-8999-9f08f64cf9b1"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Net(\n",
" (conv1): Conv2d(1, 6, kernel_size=(5, 5), stride=(1, 1))\n",
" (conv2): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1))\n",
" (fc1): Linear(in_features=400, out_features=120, bias=True)\n",
" (fc2): Linear(in_features=120, out_features=84, bias=True)\n",
" (fc3): Linear(in_features=84, out_features=10, bias=True)\n",
")\n"
]
}
],
"source": [
"import torch\n",
"from torch.autograd import Variable\n",
"import torch.nn as nn\n",
"import torch.nn.functional as F\n",
"\n",
"### 다음은 간단한 Convolutional Neural Network 모델 구조를 나타낸 코드입니다. 6장을 참고하여 아래 코드를 완성해주세요! ###\n",
"\n",
"class Net(nn.Module):\n",
"\n",
" def __init__(self):\n",
" super(Net, self).__init__()\n",
"\n",
" # 흑백 이미지(1개 채널)이며, 출력 채널은 6개이고 커널 크기는 5x5\n",
" self.conv1 = nn.Conv2d(in_channels = 1, out_channels = 6, kernel_size = 5)\n",
"\n",
" # 입력은 ConvLayer의 출력, 출력 채널은 16개이고 커널 크기는 5x5\n",
" self.conv2 = nn.Conv2d(in_channels = 6, out_channels = 16, kernel_size = 5)\n",
"\n",
" # 입력 크기는 Conv2의 출력 크기를 flatten한 값, 출력 크기는 120\n",
" self.fc1 = nn.Linear(in_features = 16*5*5, out_features = 120)\n",
"\n",
" # 출력 크기 84\n",
" self.fc2 = nn.Linear(in_features = 120, out_features = 84)\n",
"\n",
" # 출력 크기는 클래스 수(10개)\n",
" self.fc3 = nn.Linear(in_features = 84, out_features = 10)\n",
"\n",
" def forward(self, x):\n",
" # (2, 2) 윈도우 크기로 맥스 풀링\n",
"\n",
" # Conv1 -> ReLU 활성화 -> MaxPooling\n",
" x = F.max_pool2d(F.relu(self.conv1(x)), kernel_size = 2)\n",
"\n",
" # Conv2 -> ReLU 활성화 -> MaxPooling\n",
" x = F.max_pool2d(F.relu(self.conv2(x)), kernel_size = 2)\n",
"\n",
" x = x.view(-1, self.num_flat_features(x))\n",
"\n",
" # FC1 -> ReLU 활성화\n",
" x = F.relu(self.fc1(x))\n",
"\n",
" # # FC2 -> ReLU 활성화\n",
" x = F.relu(self.fc2(x))\n",
"\n",
" x = self.fc3(x)\n",
" return x\n",
"\n",
"\n",
" def num_flat_features(self, x):\n",
" size = x.size()[1:] # 배치 차원을 제외한 모든 차원\n",
" num_features = 1\n",
" for s in size:\n",
" num_features *= s\n",
" return num_features\n",
"\n",
"\n",
"net = Net()\n",
"print(net)"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading