Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

AI study/๋”ฅ๋Ÿฌ๋‹ ํ”„๋ ˆ์ž„์›Œํฌ

[keras] Conv2D, MaxPool2D ํŒŒ๋ผ๋ฏธํ„ฐ ์‚ดํŽด๋ณด๊ธฐ

๊ฐ์ž ๐Ÿฅ” 2021. 4. 20. 12:19
๋ฐ˜์‘ํ˜•

์‹œ์ž‘ํ•˜๋ฉฐ

์–ธ์ œ๋‚˜ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋‚˜๋ฅผ ๊ดด๋กญํžŒ๋‹ค. ์‚ญ์ œ๋˜์–ด ์‚ฌ์šฉํ•˜๋Š”๊ฒฝ์šฐ๋„ ์žˆ๊ณ  ๋””ํดํŠธ๊ฐ’์ด ๋ญ”์ง€ ๋ชจ๋ฅด๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๊ณ ...
๊ทธ๋ž˜์„œ ๋‚˜์ค‘์„ ์œ„ํ•ด ์ •๋ฆฌํ•ด๋ณด์•˜๋‹ค. tensorflow ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ–ˆ๋‹ค.

 

1. Conv2D

tf.keras.layers.Conv2D(filters, kernel_size, strides=(1,1), input_shape=(28,28,3))
  • ์ฒซ๋ฒˆ์งธ layer ๊ฐ€ Conv2D ์ธ ๊ฒฝ์šฐ๋Š” "input_shape"๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์–ด์•ผ ํ•จ
    • (์ด๋ฏธ์ง€์˜ ๋†’์ด, ์ด๋ฏธ์ง€์˜ ๋„ˆ๋น„, ์ปฌ๋Ÿฌ์ฑ„๋„) ํ˜•ํƒœ์˜ tensor๋กœ ์ž…๋ ฅ์„ ๋ฐ›์Œ
    • ์ปฌ๋Ÿฌ์ฑ„๋„
      • color ์ธ ๊ฒฝ์šฐ (R, G, B) ์„ธ ๊ฐœ์˜ ์ฑ„๋„์„ ๊ฐ€์ง€๊ธฐ์— 3
      • greyscale (ํ‘๋ฐฑ)์ธ ๊ฒฝ์šฐ ํ•œ ๊ฐœ์˜ ์ฑ„๋„์„ ๊ฐ€์ง€๊ธฐ์— 1
tf.keras.layers.Conv2D(
    filters, kernel_size, strides=(1, 1), padding='valid',
    data_format=None, dilation_rate=(1, 1), groups=1, activation=None,
    use_bias=True, kernel_initializer='glorot_uniform',
    bias_initializer='zeros', kernel_regularizer=None,
    bias_regularizer=None, activity_regularizer=None, kernel_constraint=None,
    bias_constraint=None, **kwargs
)

Conv2D์˜ ํŒŒ๋ผ๋ฏธํ„ฐ ์ข…๋ฅ˜๋“ค ์‚ดํŽด๋ณด๊ธฐ

 

 

2. MaxPool2D

tf.keras.layers.MaxPool2D(
    pool_size=(2, 2), strides=None, padding='valid', data_format=None,
    **kwargs
)
  • ์ถœ๋ ฅ ๊ฒฐ๊ณผ ํ˜•ํƒœ : output = (input_shape - pool_size + 1) / strides)
  • pool_size
    • ์ •์ˆ˜ ํ˜น์€ ๋‘ ์ •์ˆ˜๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, pooling ์ฐฝ ํฌ๊ธฐ๋ฅผ ์˜๋ฏธ
    • Max Pooling ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ 2x2 ์ฐฝ๋ฌธ์„ ์„ ํƒํ–ˆ์„ ๊ฒฝ์šฐ ํ•ด๋‹น ์ฐฝ ๋‚ด์˜ ์ตœ๋Œ€ ๊ฐ’์„ ๊ฐ€์ ธ์˜ด
  • strides
    • ์ •์ˆ˜ ํ˜น์€ ๋‘ ์ •์ˆ˜๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ํ’€๋ง(pooling)์ฐฝ์˜ ์ด๋™๊ฑฐ๋ฆฌ๋ฅผ ์ง€์ •
    • strides ๊ฐ€ None ์ด๋ฉด pool_size ์™€ ๋™์ผํ•˜๊ฒŒ ์„ค์ •๋จ
  • padding
    • 'valid' ํ˜น์€ 'same' ๊ฐ’์„ ๋„ฃ์„ ์ˆ˜ ์žˆ์Œ
      • valid : ํŒจ๋”ฉ์ด ์—†์Œ์„ ์˜๋ฏธ
      • smae : ์ถœ๋ ฅ๊ณผ ์ž…๋ ฅ์ด ๋™์ผํ•œ ๋†’์ด, ํญ, ์น˜์ˆ˜๋ฅผ ๊ฐ€์ง€๋„๋ก ์ž…๋ ฅ์˜ ์™ผ,์˜ค,์œ„,์•„๋ž˜์ชฝ์œผ๋กœ ๊ณ ๋ฅด๊ฒŒ ํŒจ๋”ฉ ํ•ด์คŒ
  • data_format
    • ๋””ํดํŠธ๊ฐ’ : channels_last  ํ˜น์€ channels_first ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Œ
      • channels_last : input์˜ ํ˜•ํƒœ (batch, height, width, channels)
      • channels_first : input์˜ ํ˜•ํƒœ (batch, channels, hegith, width)
    • ๊ธฐ๋ณธ๊ฐ’์€ keras ๊ตฌ์„ฑ ํŒŒ์ผ์— ์žˆ๋Š” image_data_format ๊ฐ’์œผ๋กœ ์„ค์ •๋จ
    • ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ฉด (None) channels_last ๊ฐ’์œผ๋กœ ์„ค์ •๋จ

www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D

 

tf.keras.layers.Conv2D  |  TensorFlow Core v2.4.1

2D convolution layer (e.g. spatial convolution over images).

www.tensorflow.org

www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPool2D

 

tf.keras.layers.MaxPool2D  |  TensorFlow Core v2.4.1

Max pooling operation for 2D spatial data.

www.tensorflow.org

 

๋ฐ˜์‘ํ˜•