[ํ์ดํ ์น] ํ์ดํ ์น๋ก CNN ๋ชจ๋ธ์ ๊ตฌํํด๋ณด์! (GoogleNetํธ)
์๋ณธ ๊ฒ์๊ธ: https://velog.io/@euisuk-chung/ํ์ดํ ์น-ํ์ดํ ์น๋ก-CNN-๋ชจ๋ธ์-๊ตฌํํด๋ณด์-GoogleNetํธ
์๋
ํ์ธ์! ์ง๋๋ฒ ํฌ์คํธ์ธ VGGNet ์ดํ๋ก ์ค๋์ GoogleNet
๊ด๋ จ ํฌ์คํธ์
๋๋ค. ๋ค์ ํฌ์คํธ๋ ResNet
์ผ๋ก ์ฐพ์๋ต๋๋ก ํ๊ฒ ์ต๋๋ค.
์ง๋๋ฒ์๋ ์๊ฐ๋๋ ธ๋ค์ํผ ์ปดํจํฐ ๋น์ ๋ํ ์ค์ ILSVRC (Imagenet Large Scale Visual Recognition Challenges)
์ด๋ผ๋ ๋ํ๊ฐ ์๋๋ฐ, ๋ณธ ๋ํ๋ ๊ฑฐ๋ ์ด๋ฏธ์ง๋ฅผ 1000๊ฐ์ ์๋ธ์ด๋ฏธ์ง๋ก ๋ถ๋ฅํ๋ ๊ฒ์ ๋ชฉ์ ์ผ๋ก ํฉ๋๋ค. ์๋ ๊ทธ๋ฆผ์ CNN๊ตฌ์กฐ์ ๋์คํ๋ฅผ ์ด๋์๋ ์ด์ฐฝ๊ธฐ ๋ชจ๋ธ๋ค๋ก AlexNet (2012) - VGGNet (2014) - GoogleNet (2014) - ResNet (2015) ์์ผ๋ก ๊ณ๋ณด๋ฅผ ์ด์ด๋๊ฐ์ต๋๋ค.
Source : https://icml.cc/2016/tutorials/
์์ ๊ทธ๋ฆผ์์ layers๋ CNN layer์ ๊ฐ์(๊น์ด)๋ฅผ ์๋ฏธํ๋ฉฐ ์ง๊ด์ ์ธ ์ดํด๋ฅผ ์ํด์ ์๋์ฒ๋ผ ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ณด์์ต๋๋ค.
GoogleNet ๊ฐ์
์๊ฐ
GoogleNet์ด ์๊ฐ๋ ๋ ผ๋ฌธ์ ์ ๋ชฉ์ Going Deeper with Convolutions๋ก, ๋ค์ ๋งํฌ์์ ํ์ธํด๋ณด์ค ์ ์์ต๋๋ค. ๋งํฌ
์ผ๋ฐ์ ์ผ๋ก ๋ชจ๋ธ์ depth์ width๊ฐ ์ปค์ง๋ฉด parameter๊ฐ ๋ง์์ง๊ฒ ๋๊ณ , ํ๋ผ๋ฏธํฐ ์๊ฐ ๋ง๊ฒ๋๋ฉด ๋ชจ๋ธ์ด Overfitting๋ ์ ์์ต๋๋ค. GoogleNet์ ์ต๋ํ ํ๋ผ๋ฏธํฐ๋ฅผ ์ค์ด๋ฉด์ ๋คํธ์ํฌ๋ฅผ ๊น๊ฒ ๋์์ธํ๊ณ ์ ํ์์ต๋๋ค. ๋ชจ๋ธ์ ๋ ์ด์ด๊ฐ ๊น๋๋ผ๋ ์ฐ๊ฒฐ์ด sparseํ๋ค๋ฉด ํ๋ผ๋ฏธํฐ ์๊ฐ ์ค์ด๋ค๊ฒ ๋ฉ๋๋ค. ์ด๋ Overfitting ์ ๋ฐฉ์งํ๋ ํจ๊ณผ๊ฐ ์์ผ๋ฉด์, ์ฐ์ฐ ์์ฒด๋ Denseํ๊ฒ ์ฒ๋ฆฌํ๋ ๊ฒ์ ๋ชฉํ๋ก ํฉ๋๋ค.
GoogleNet์ ์ธ์ ์ (inception) ๋ชจ๋์ด๋ผ๋ ๋ธ๋ก์ ๊ฐ์ง๊ณ ์์ด์ ์ธ์ ์ ๋คํธ์ํฌ๋ผ๊ณ ๋ ๋ถ๋ฆฝ๋๋ค. ์๋ ๊ทธ๋ฆผ์ GoogleNet์ ๊ตฌ์กฐ๋ ์ ๋๋ค. ์ด์ ๋ชจ๋ธ๋ค๊ณผ ๋น๊ตํ์ฌ ํจ์ฌ ๋ณต์กํ ๊ตฌ์กฐ๋ก ๋์ด ์๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
Source : https://arxiv.org/abs/1409.4842
Inception Module
์์ ๊ตฌ์กฐ๋๋ฅผ ์ดํด๋ณด๋ฉด ๋ญ๊ฐ ์ฌ๋ฌ๊ฐ๋๋ก ๊ฐ๋ผ์ก๋ค๊ฐ ๋ชจ์ด๋ ํํ๋ฅผ ํ๊ณ ์๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค. ์ด๋ ํ ๋ชจ๋(๋ธ๋ก)์ ์ธ์ ์ (Inception) ๋ชจ๋์ด๋ผ๊ณ ํ๋ฉฐ ์ด๋ ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ต๋๋ค.
์ธ์ ์ ๋ชจ๋์ Feature๋ฅผ ํจ์จ์ ์ผ๋ก ์ถ์ถํ๊ธฐ ์ํด 1x1, 3x3, 5x5 convolution ์ฐ์ฐ์ ๊ฐ๊ฐ ์ํํ๊ฒ ๋ฉ๋๋ค. ๊ฐ์ฅ ๋จผ์ ์ข์ธก์ ์๋ (a) Naive Inception์ ๋ํ์ฌ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
(a) Naive Inception
Naive Inception์ ์ด์ ๋จ๊ณ์ Activation Map์ ๋ํ์ฌ 1x1, 3x3, 5x5ํฉ์ฑ๊ณฑ ์ฐ์ฐ์ ์ํํ ๋ค ๊ฐ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ concatenateํด์ฃผ์ด ๋ค์ ๋จ๊ณ๋ก ๋์ด๊ฐ๋๋ค. ์ด๋ ์์๋ธ์ ํจ๊ณผ๋ฅผ ๊ฐ๊ณ ์์ด ๋ชจ๋ธ์ด ๋ค์ํ ๊ด์ ์ผ๋ก ํ์ต์ ํ ์ ์๋๋ก ํ๋ ํจ๊ณผ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. ์๊ฐํ๋ฅผ ํตํด ์ด๋ค ์์ผ๋ก ๊ฐ๊ฐ Naive Inception๋ชจ๋์ convolution์ฐ์ฐ์ด ์ํ๋๊ณ ํฉ์ณ์ง๋์ง ์๋ ๋์ํํด๋ณด์์ต๋๋ค.
์ด๋ ๊ทธ๋ฆผ์ ํตํด ํ์ธํ ์ ์๋ ํน์ง๋ค์ด ๋ช๊ฐ์ง ์กด์ฌํฉ๋๋ค.
- 1x1 convolution์ ๋ณ๋์ padding์ด ์์ต๋๋ค.
- 3x3 convolution, 5x5 convolution, 3x3 Pooling ํ concatenate ํ๊ธฐ ์ํด ํฌ๊ธฐ๊ฐ ๊ฐ์์ง๋๋ก ์ ๋นํ padding์ ์ํํด์ค๋๋ค.
- ๋ฟ๋ง ์๋๋ผ pooling layer์ ๊ฒฝ์ฐ๋ channel์๊ฐ ๋ฐ๋์ง ์๊ธฐ ๋๋ฌธ์ ์ธต์ด ๊น์ด์ง์๋ก ๊ธฐํ๊ธ์์ ์ผ๋ก channel์๊ฐ ๋ง์์ง๋ ๊ตฌ์กฐ๊ฐ ๋๊ฒ๋ฉ๋๋ค.
(b) Reduced Dimension Inception
1x1 Convolution
์ด๋ฅผ ์ํด (b) Inception Module wit dimension reduction์ด ์ ์๋๊ฒ ๋๋๋ฐ์. ์ด๋ 1x1 Convolution์ ์ด์ฉํ์ฌ dimension reduction์ ํด์ค์ผ๋ก์จ computational load๋ฅผ ์ค์ฌ์ฃผ๊ฒ ๋ฉ๋๋ค. 1x1 Convolution์ ์ง๊ด์ ์ผ๋ก 1x1 ํฌ๊ธฐ๋ฅผ ๊ฐ์ง๋ Convolution Filter๋ฅผ ์ฌ์ฉํ Convolution Layer์ ๋๋ค.
์ ๊ทธ๋ฆผ์์ ๋ณด์ค ์ ์๋ฏ์ด input์ 1x1 Convolution์ ์ํํ๊ฒ ๋๋ฉด feature map์ ํฌ๊ธฐ๊ฐ ๋์ผํ๊ฒ ์ ์ง๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค. ์ ๊ทธ๋ฆผ์ ๊ฒฝ์ฐ (6x6)
์ด (6x6)
์ผ๋ก ๊ทธ๋๋ก ๋ณด์กด๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค. ์ด๋ ์ด๋ฌํ 1x1 convolution ํํฐ๋ฅผ ๋ช๊ฐ ์ฌ์ฉํ๋๊ฐ์ ๋ฐ๋ผ ouput์ ์ถ๋ ฅ ์ฑ๋์ ๊ฐ์๋ฅผ ์กฐ์ ํด์ค ์ ์๊ฒ๋ฉ๋๋ค.
GoogleNet์ ์ด๋ฌํ 1x1 Convolution์ ํน์ง์ ์ด๋ ค sparseํ ์ฐ์ฐ์ denseํ๋๋ก ๋ฐ๊ฟ์ฃผ์์ต๋๋ค. ์๋ ๊ทธ๋ฆผ์ ์ดํด๋ณด์์ฃ .
๊ธฐ์กด์ (a)์์ 5x5 Convolution์ด ์ข์ธก๊ณผ ๊ฐ์ด 112.9M๊ฐ์ ํ๋ผ๋ฏธํฐ๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ฉด, (b)์์์ฒ๋ผ 1x1 Convolution์ ํตํด ์ฑ๋ ์๋ฅผ ์ค์ฌ์ฃผ์ด Bottleneck์ญํ ์ ์ํํ๊ณ , ์ด๋ฅผ ๋ค์ 5x5 Convolution์ ํต๊ณผ์์ผ ๊ฐ์ output์ธ 14x14x48
์ ๋ฐํํด์ค์๋ ๋ถ๊ตฌํ๊ณ 5.3M๊ฐ์ ํ๋ผ๋ฏธํฐ๋ฅผ ๊ฐ๊ฒํ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
Global Average Pooling(GAP)
๋ํ, CNN ๋ชจ๋ธ๋ค์ ์๊ฐํด๋ณด๋ฉด ๋ง์ง๋ง์ softmax ์ฐ์ฐ์ ์ทจํ๊ธฐ ์ ์ ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ๋์ถ๋ feature map์ flatten์ ํตํด ์ญ ํด์ ๊ต์ฅํ ๊ธด ํ๋์ ๋ฒกํฐ๋ก ๋ง๋ ๋ค์, ๊ทธ ๋ฒกํฐ๋ฅผ Fully Connected Layer์ ๋ฃ๋ ๋ฐฉ์์ผ๋ก ํ๋ํ๋ ๋งคํํด์ ํด๋์ค๋ฅผ ๋ถ๋ฅํ์ต๋๋ค.
ํ์ง๋ง, ์ด๋ฌํ ๊ณผ์ ์ ๊ธฐ์กด featuremap์ ๊ณต๊ฐ์ ์ ๋ณด๋ ๋ง์ด ์์ด๋ฒ๋ฆฌ๋๋ฐ๋ค๊ฐ, ๊ต์ฅํ ๋ง์ ํ๋ผ๋ฏธํฐ๊ฐ ํ์ํ๊ฒ ๋๊ณ , VGGNet์ ๊ฒฝ์ฐ ์ด ๋ถ๋ถ์ด ์ ์ฒด ๊ณ์ฐ๋์ 85%๋ฅผ ์ฐจ์งํ๊ฒ ๋ฉ๋๋ค. ์ด๋ฅผ ๊ทน๋ณตํ๊ธฐ ์ํด ์ ์๋ ๋ฐฉ๋ฒ์ด ๋ฐ๋ก GAP(Global Average Pooling)๋ก, ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ต๋๋ค.
์ ๊ทธ๋ฆผ์์ 7x7 feature map์ด 1024๊ฐ์ด๋ฏ๋ก ๋ถ๋ฅํ ํด๋์ค ์๊ฐ 1024๊ฐ๋ผ๊ณ ๊ฐ์ ํ๋๋ก ํ๊ฒ ์ต๋๋ค. GAP๋ ๊ฐ feature map ์์ ์๋ ํน์ง๊ฐ๋ค์ ํ๊ท ์ ๊ตฌํด์ ๊ฐ๊ฐ์ ์ถ๋ ฅ ๋
ธ๋์ ๋ฐ๋ก ์
๋ ฅํ๋ ๋ฐฉ์์
๋๋ค. ํ๋ผ๋ฏธํฐ ๊ด์ ์์ ํด์ํด์ ๋ณด๋ฉด ์์ Fully Connected ๊ทธ๋ฆผ์ ๊ฒฝ์ฐ, (7x7x1024)x1024 = 51.3M
๊ฐ์ Weight๋ฅผ ๊ฐ์ง๊ณ ์๊ณ , GAP์ ๊ฒฝ์ฐ ๋ฐ๋ก ํ๊ท ์ ์ทจํ๊ฒ ๋๋ฏ๋ก Weight์ ๊ฐ์๊ฐ 0
๊ฐ๊ฐ ๋ฉ๋๋ค.
Auxiliary Classifier
๋ฐฉ๊ธ๊น์ง ์ํด์ 1x1 Conv๊ณผ GAP๋ฅผ ์ดํด๋ณด์ จ๋๋ฐ์. GoogleNet์ ๋ค๋ฅธ ํน์ง์ผ๋ก๋ ๋ฐ๋ก Auxiliary Classifier๊ฐ ์กด์ฌํ๋ค๋ ์ ์ ๋๋ค.
์ผ๋ฐ์ ์ผ๋ก Neural Network์ ๋ชจ๋ธ์ด ์ ์ ๊น์ด์ง์๋ก ๊ธฐ์ธ๊ธฐ๊ฐ ์์ค๋๋ vanishing gradient์ ๋ฌธ์ ๊ฐ ์๊ธฐ๊ฒ๋ฉ๋๋ค. ๊ทธ๋์ GoogleNet์์๋ ๊ธฐ์กด์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๊ณผ ๊ฐ์ด Neural Network์ ๋งจ ๋ง์ง๋ง layer์ softmax๋ฅผ ๋ฑ ํ๋๋ง ๋์ง ์๊ณ , Auxiliary classifier๋ผ๋ ์ถ๊ฐ์ ์ธ classifier๋ฅผ ์ ์ํ์ฌ ์ค๊ฐ์์๋ Backpropagation์ด ์งํ๋ ์ ์๋๋ก ํ์์ต๋๋ค.
์ด๋, Backpropagation์, weight๊ฐ์ ํฐ ์ํฅ์ ์ฃผ๋ ๊ฒ์ ๋ง๊ธฐ ์ํด Auxiliary Classifier์ 0.3์ ๊ณฑํ์ฌ training์ ์ํํฉ๋๋ค. Auxiliary Classifier๋ ํ์ต ์ ๋ฐ์ํ๋ ๋ฌธ์ ์ธ vanishing gradient๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์ฌ์ฉํ๋ ๊ธฐ๋ฒ์ด๋ฏ๋ก ๊ฒ์ฆ ์ํ ์ ์ด๋ฅผ ์ ๊ฑฐํ๊ณ ์ ์ผ ๋ง์ง๋ง layer์ softmax๋ง์ ์ฌ์ฉํ๊ฒ ๋ฉ๋๋ค.
์ฝ๋ ์ค์ต
์ธ์ ์ ๋ชจ๋์ ์ ์ํ๊ธฐ ์ํด ์๋ ํจ์๋ค์ ๋ฏธ๋ฆฌ ์ ์ํด๋์์ต๋๋ค.
- 1x1 Convolution
- 1x1 Convolution -> 3x3 Convolution
- 1x1 Convolution -> 5x5 Convolution
- 3x3 MaxPooling -> 1x1 Convolution
Define Convolution Blocks
- 1x1 Convolution
1
2
3
4
5
6
def conv_1(in_dim,out_dim):
model = nn.Sequential(
nn.Conv2d(in_dim,out_dim,1,1),
nn.ReLU(),
)
return model
- 1x1 Convolution -> 3x3 Convolution
1
2
3
4
5
6
7
8
def conv_1_3(in_dim,mid_dim,out_dim):
model = nn.Sequential(
nn.Conv2d(in_dim,mid_dim,1,1),
nn.ReLU(),
nn.Conv2d(mid_dim,out_dim,3,1,1),
nn.ReLU()
)
return model
- 1x1 Convolution -> 5x5 Convolution
1
2
3
4
5
6
7
8
def conv_1_5(in_dim,mid_dim,out_dim):
model = nn.Sequential(
nn.Conv2d(in_dim,mid_dim,1,1),
nn.ReLU(),
nn.Conv2d(mid_dim,out_dim,5,1,2),
nn.ReLU()
)
return model
- 3x3 MaxPooling -> 1x1 Convolution
1
2
3
4
5
6
7
def max_3_1(in_dim,out_dim):
model = nn.Sequential(
nn.MaxPool2d(kernel_size=3,stride=1,padding=1),
nn.Conv2d(in_dim,out_dim,1,1),
nn.ReLU(),
)
return model
Define Inception Module
Inception ๋ชจ๋์ ์ด์ ๋จ๊ณ์์ ์ ์ํ ํจ์๋ค์ ํ์ฉํด์ concatํด์ฃผ๋ ๋จ๊ณ์ ๋๋ค.
- 1x1 Convolution
- 1x1 Convolution -> 3x3 Convolution
- 1x1 Convolution -> 5x5 Convolution
- 3x3 MaxPooling -> 1x1 Convolution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class inception_module(nn.Module):
def __init__(self,in_dim,out_dim_1,mid_dim_3,out_dim_3,mid_dim_5,out_dim_5,pool_dim):
super(inception_module,self).__init__()
# 1x1 Convolution
self.conv_1 = conv_1(in_dim,out_dim_1)
# 1x1 Convolution -> 3x3 Convolution
self.conv_1_3 = conv_1_3(in_dim,mid_dim_3,out_dim_3)
# 1x1 Convolution -> 5x5 Convolution
self.conv_1_5 = conv_1_5(in_dim,mid_dim_5,out_dim_5)
# 3x3 MaxPooling -> 1x1 Convolution
self.max_3_1 = max_3_1(in_dim,pool_dim)
def forward(self,x):
out_1 = self.conv_1(x)
out_2 = self.conv_1_3(x)
out_3 = self.conv_1_5(x)
out_4 = self.max_3_1(x)
# concat
output = torch.cat([out_1,out_2,out_3,out_4],1)
return output
Define GoogleNet
GoogleNet์ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌ์ฑ์ด ๋์ด ์์ต๋๋ค.
์์ ํ์์ ๋์จ ๊ฐ๋ค์ ์ ๋ ฅํ์ฌ ๊ฐ๊ฐ์ dimension์ ์ ์ํด์ฃผ๋ฉด ์๋์ ๊ฐ์ต๋๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class GoogLeNet(nn.Module):
def __init__(self, base_dim, num_classes=2):
super(GoogLeNet, self).__init__()
self.num_classes=num_classes
self.layer_1 = nn.Sequential(
nn.Conv2d(3,base_dim,7,2,3),
nn.MaxPool2d(3,2,1),
nn.Conv2d(base_dim,base_dim*3,3,1,1),
nn.MaxPool2d(3,2,1),
)
self.layer_2 = nn.Sequential(
inception_module(base_dim*3,64,96,128,16,32,32),
inception_module(base_dim*4,128,128,192,32,96,64),
nn.MaxPool2d(3,2,1),
)
self.layer_3 = nn.Sequential(
inception_module(480,192,96,208,16,48,64),
inception_module(512,160,112,224,24,64,64),
inception_module(512,128,128,256,24,64,64),
inception_module(512,112,144,288,32,64,64),
inception_module(528,256,160,320,32,128,128),
nn.MaxPool2d(3,2,1),
)
self.layer_4 = nn.Sequential(
inception_module(832,256,160,320,32,128,128),
inception_module(832,384,192,384,48,128,128),
nn.AvgPool2d(7,1),
)
self.layer_5 = nn.Dropout2d(0.4)
self.fc_layer = nn.Linear(1024,self.num_classes)
def forward(self, x):
out = self.layer_1(x)
out = self.layer_2(out)
out = self.layer_3(out)
out = self.layer_4(out)
out = self.layer_5(out)
out = out.view(batch_size,-1)
out = self.fc_layer(out)
return out
CIFAR10 Implementation
์ด์ VGGNet๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ์ด๋ฅผ CIFAR10๋ฐ์ดํฐ์ ์ ์ฉํด๋ณด์์ต๋๋ค. TRAIN
๊ณผ INFERENCE
ํจ์๋ ์ด์ ํฌ์คํธ์ ๋์ผํฉ๋๋ค. (์ด์ ํฌ์คํธ)
1
2
3
batch_size = 100
learning_rate = 0.0002
num_epoch = 100
TRAIN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
loss_arr = []
for i in trange(num_epoch):
for j,[image,label] in enumerate(train_loader):
x = image.to(device)
y_= label.to(device)
optimizer.zero_grad()
output = model.forward(x)
loss = loss_func(output,y_)
loss.backward()
optimizer.step()
if i % 10 ==0:
print(loss)
loss_arr.append(loss.cpu().detach().numpy())
loss ์๊ฐํ
1
2
plt.plot(loss_arr)
plt.show()
TEST
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# ๋ง์ ๊ฐ์, ์ ์ฒด ๊ฐ์๋ฅผ ์ ์ฅํ ๋ณ์๋ฅผ ์ง์ ํฉ๋๋ค.
correct = 0
total = 0
model.eval()
# ์ธํผ๋ฐ์ค ๋ชจ๋๋ฅผ ์ํด no_grad ํด์ค๋๋ค.
with torch.no_grad():
# ํ
์คํธ๋ก๋์์ ์ด๋ฏธ์ง์ ์ ๋ต์ ๋ถ๋ฌ์ต๋๋ค.
for image,label in test_loader:
# ๋ ๋ฐ์ดํฐ ๋ชจ๋ ์ฅ์น์ ์ฌ๋ฆฝ๋๋ค.
x = image.to(device)
y= label.to(device)
# ๋ชจ๋ธ์ ๋ฐ์ดํฐ๋ฅผ ๋ฃ๊ณ ๊ฒฐ๊ณผ๊ฐ์ ์ป์ต๋๋ค.
output = model.forward(x)
_,output_index = torch.max(output,1)
# ์ ์ฒด ๊ฐ์ += ๋ผ๋ฒจ์ ๊ฐ์
total += label.size(0)
correct += (output_index == y).sum().float()
# ์ ํ๋ ๋์ถ
print("Accuracy of Test Data: {}%".format(100*correct/total))
Accuracy of Test Data: 71.98999786376953%
๊ธด ๊ธ ์ฝ์ด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค ^~^