# mnist

손글씨 흑백이미지(28 pixels by 28 pixels)를 10개의 카테고리(0 to 9)로 Classification하는 문제

###### http://yann.lecun.com/exdb/mnist/https://tensorflow.rstudio.com/tutorials/beginners/basic-ml/tutorial_save_and_restore/http://blog.daum.net/geoscience/1162
R

a set of 60,000 training images,
a set of 10,000 test images

classification problem 에서,
Class : 분류 카테고리 (10개의 class)
Samples: 데이터 points (x) 3D arrays
Label: 특정 sample에 연관된 class (y)1D array

```> mnist %>% str
List of 2
\$ train:List of 2
..\$ x: int [1:60000, 1:28, 1:28] 0 0 0 0 0 0 0 0 0 0 ...
..\$ y: int [1:60000(1d)] 5 0 4 1 9 2 1 3 1 4 ...
\$ test :List of 2
..\$ x: int [1:10000, 1:28, 1:28] 0 0 0 0 0 0 0 0 0 0 ...
..\$ y: int [1:10000(1d)] 7 2 1 0 4 1 4 9 5 9 ...```
R
R
```> train_imgData %>% str()
int [1:60000, 1:28, 1:28] 0 0 0 0 0 0 0 0 0 0 ...

> train_imgData %>% class
[1] "array"

> train_imgData %>% dim
[1] 60000    28    28```
```> train_labels  %>% str()
int [1:60000(1d)] 5 0 4 1 9 2 1 3 1 4 ...

> y_train %>% class
[1] "array"

> y_train %>% dim
[1] 60000```
```mat1_5 <- x_train[1,,]
mat2_0 <- x_train[2,,]
mat3_4 <- x_train[3,,]

> mat3_4 %>% max()
[1] 255
> mat3_4 %>% min()
[1] 0

mat3_4 %>% prmatrix(rowlab=rep("",28), collab=rep("",28))
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  67 232 39 0 0 0 0 0
# 0 0 0   0  62  81   0   0   0   0   0   0   0   0   0   0   0   0   0   0 120 180 39 0 0 0 0 0
# 0 0 0   0 126 163   0   0   0   0   0   0   0   0   0   0   0   0   0   2 153 210 40 0 0 0 0 0
# 0 0 0   0 220 163   0   0   0   0   0   0   0   0   0   0   0   0   0  27 254 162  0 0 0 0 0 0
# 0 0 0   0 222 163   0   0   0   0   0   0   0   0   0   0   0   0   0 183 254 125  0 0 0 0 0 0
# 0 0 0  46 245 163   0   0   0   0   0   0   0   0   0   0   0   0   0 198 254  56  0 0 0 0 0 0
# 0 0 0 120 254 163   0   0   0   0   0   0   0   0   0   0   0   0  23 231 254  29  0 0 0 0 0 0
# 0 0 0 159 254 120   0   0   0   0   0   0   0   0   0   0   0   0 163 254 216  16  0 0 0 0 0 0
# 0 0 0 159 254  67   0   0   0   0   0   0   0   0   0  14  86 178 248 254  91   0  0 0 0 0 0 0
# 0 0 0 159 254  85   0   0   0  47  49 116 144 150 241 243 234 179 241 252  40   0  0 0 0 0 0 0
# 0 0 0 150 253 237 207 207 207 253 254 250 240 198 143  91  28   5 233 250   0   0  0 0 0 0 0 0
# 0 0 0   0 119 177 177 177 177 177  98  56   0   0   0   0   0 102 254 220   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 169 254 137   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 169 254  57   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 169 254  57   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 169 255  94   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 169 254  96   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 169 254 153   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 169 255 153   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  96 254 153   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0
# 0 0 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  0 0 0 0 0 0```

`image` 는 주어진 matrix를 행이 x축, 열이 y축인 Table로 생각하기 때문에,
반시계방향으로 90도 회전되어 있어, 추가적인 작업이 필요하다.

R
R

Array

R

3D array에서 하나의 차원으로 고정하면, Matrix가 된다.
기본적으로 표시할때 3번째 차원부터 변경하면서 표시해 준다.
1번째 차원으로 고정하면, 나머지로 자연스럽게 Matrix를 만든다.

R

## Image flatten

다차원의 Array를 Matrix로 변경/ Flatten

R
R

## Model = (Network)

Layer = data-processing module = Filter for data
input 데이터가 Filter를 거치면 좀더 유용한 Data가 된다, representations을 추출해낸다.
이런 Filter를 거치는 과정, 즉 data를 변환하는 것이 learning이다

representation이란 data를 encoding해서 다른 방법으로 보는 것 (예를 들어, 이미지의 컬러를 RGB나 HSV로 encoding하는 것, 같은 데이터라고 encoding하는 방법에 따라 representation이 다르다)

R

## Compile

Model(network)이 training을 위한 준비가 되도록 하기 위해서는
3가지를 미리 정의해야 한다.

• A loss function—
network이 training 데이터에 대해 얼마나 잘 동작하고 있는지, 그리고 그를 통해 얼마나 모델이 올바른 방향으로 자신을 움직여 가고 있는지를 어떻게 측정될수 있을지 정한다.

How the network will be able to measure how good a job it’s doing on
its training data, and thus how it will be able to steer itself in the right direction.
• An optimizer—

The mechanism through which the network will update itself based on the
data it sees and its loss function.
• Metrics (to monitor during training and testing)—
Here we’ll only care about accuracy (the
fraction of the images that were correctly classified).
R

## example

###### https://gaussian37.github.io/dl-keras-number-of-cnn-param/
R
R
Categories: Keras

Blog Owner