풀링으로 매개변수 줄이기

Keras로 배우는 이미지 모델링

Ariel Rokem

Senior Data Scientist, University of Washington

model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_12 (Conv2D)           (None, 28, 28, 5)         50        
_________________________________________________________________
conv2d_13 (Conv2D)           (None, 28, 28, 15)        690       
_________________________________________________________________
flatten_6 (Flatten)          (None, 11760)             0         
_________________________________________________________________
dense_9 (Dense)              (None, 3)                 35283     
=================================================================
Total params: 36,023
Trainable params: 36,023
Non-trainable params: 0
_________________________________________________________________

Keras로 배우는 이미지 모델링

Keras로 배우는 이미지 모델링

Keras로 배우는 이미지 모델링

Keras로 배우는 이미지 모델링

Keras로 배우는 이미지 모델링

Keras로 배우는 이미지 모델링

Keras로 배우는 이미지 모델링

Keras로 배우는 이미지 모델링

최대 풀링 구현

result = np.zeros((im.shape[0]//2, im.shape[1]//2))

result[0, 0] = np.max(im[0:2, 0:2])
result[0, 1] = np.max(im[0:2, 2:4])
result[0, 2] = np.max(im[0:2, 4:6])

...

result[1, 0] = np.max(im[2:4, 0:2])

result[1, 1] = np.max(im[2:4, 2:4])

...

Keras로 배우는 이미지 모델링

최대 풀링 구현

for ii in range(result.shape[0]):
    for jj in range(result.shape[1]):
        result[ii, jj] = np.max(im[ii*2:ii*2+2, jj*2:jj*2+2])
Keras로 배우는 이미지 모델링

Keras에서 최대 풀링

from keras.models import Sequential
from keras.layers import Dense, Conv2D, Flatten, MaxPool2D

model = Sequential() model.add(Conv2D(5, kernel_size=3, activation='relu', input_shape=(img_rows, img_cols, 1)))
model.add(MaxPool2D(2))
model.add(Conv2D(15, kernel_size=3, activation='relu', input_shape=(img_rows, img_cols, 1)))
model.add(MaxPool2D(2))
model.add(Flatten()) model.add(Dense(3, activation='softmax'))
Keras로 배우는 이미지 모델링
model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_1 (Conv2D)            (None, 26, 26, 5)         50        
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 13, 13, 5)         0         
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 11, 11, 15)        690       
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 5, 5, 15)          0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 375)               0         
_________________________________________________________________
dense_1 (Dense)              (None, 3)                 1128      
=================================================================
Total params: 1,868
Trainable params: 1,868
Non-trainable params: 0
_________________________________________________________________
Keras로 배우는 이미지 모델링

연습해 봅시다!

Keras로 배우는 이미지 모델링

Preparing Video For Download...