CNN

Convolutional Neural Network

Convolutional Neural Network(CNN) 합성곱 신경망

0. 목차

1. Convolutional 알아보기
2. Simple Convolutional Neural Network(CNN)

1. Convolutional 알아보기

1.1 Convolution 연산

1. 이미지에서 Convolution이 어떻게 유용한가?

2. Gaussian 스무딩, 부드러운 이미지 만들어보기.

3. Sobel 미분필터, X축, Y축 편미분, 윤곽선 검출해보기

* 이미지 편미분 원리

이미지 편미분

* 최종적으로 얻는 그레이언트 벡터(x편미분, y편미분)

$\nabla f = ({ \frac{ \partial I(x,y) }{ \partial_x }},{ \frac{ \partial I(x,y) }{ \partial_y }})$

* 윤곽선(edge) 검출해보기

$ G = \sqrt{G^2_x + G^2_y}$

2. Simple Convolutional Neural Network(CNN)

책 150p

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import math
import tensorflow as tf

# 데이터 가져오기
fashion_mnist = tf.keras.datasets.fashion_mnist # 데이터와 연결
(train_X,train_Y), (test_X,test_Y) = fashion_mnist.load_data() # 데이터 불러오기

# 정규화
train_X = train_X/255.0
test_X = test_X/255.0

# reshape the image dimension to (#, 28, 28, 1) (,,,RGB)
train_X = train_X.reshape(-1, 28, 28, 1)
test_X = test_X.reshape(-1, 28, 28, 1)

# 모델 정의
model = tf.keras Sequential([
                             tf.keras.layers.Conv2D(input_shape=(28,28,1), kernel_size=(3,3), filters = 16),
                             tf.keras.layers.Conv2D(kernel_size=(3,3), filters = 32),
                             tf.keras.layers.Conv2D(kernel_size=(3,3), filters=64)
])

model = tf.keras Sequential 코드 해석

(28x28) =conv=> (16x26x26) =conv=> (32x24x24) =conv=> (64x22x22)
=> flattening = 64x22x22 => 128 (relu) => 10 class (softmax)

Comments