1. Deep Learning in Python
Deep Neural Network
김동민|Dongmin Kim
Linear Algebra & Python Overview
Dongmin Kim
dmk2436@gmail.com
2. Dongmin Kim, 2018
Review - Machine Learning
“… give computer systems the ability to "learn" with data,
without being explicitly programmed.” (Wikipedia)
3. Dongmin Kim, 2018
Review - Deep Learning
Machine learning that uses the feature representation during learning
- Computational
- Probabilistic Modeling
4. Dongmin Kim, 2018
행렬
행과 열로 표현한 데이터
a
𝑎
𝑏
𝑐
𝑑
𝑒
𝑎 𝑏
𝑐 𝑑
스칼라
(Scalar)
0차원
벡터
(Vector)
1차원
행렬
(Matrix)
2차원
텐서
(Tensor)
n차원(𝑛 ≥ 0)
5. Dongmin Kim, 2018
데이터의 차원
차원 예
0 1명의 키, 건물의 높이
1 여러명의 키, 시간에 따른 풍속
2 회색조 사진, 위도&경도에 따른 해발고도
3 컬러 사진, 회색조 영상, 3D 캐릭터 회색조 모델
4 컬러 영상, 3D 캐릭터 컬러 모델
11. Dongmin Kim, 2018
numpy를 이용하여 텐서 생성하기
numpy 모듈 np라는 이름으로 임포트하기
import numpy as np
n차원을 가지는 텐서 생성하기
a = np.ndarray([1, 2, 3]) #[1, 2, 3]이라는 모양을 가지는 3차원의 텐서
a의 차원
a.ndim
a의 모양
a.shape
12. Dongmin Kim, 2018
numpy를 이용하여 텐서 내의 데이터 접근
(컴퓨터는 0부터 숫자를 센다는 사실에 유의)
[3, 5]라는 모양을 가지는 텐서 a
(1, 2)지점의 데이터에 접근할 때: a[0, 1]
1행의 데이터 전체에 접근할 때: a[0, :]
1행의 데이터 중 3열부터 끝까지 접근할 때: a[0, 2:]
1행의 데이터 중 2열부터 4열까지 접근할 때: a[0, 1:4] #1이상 4미만
2열의 데이터 전체에 접근할 때: a[:, 1]
전체 데이터에 접근할 때: a or a[:, :]
13. Dongmin Kim, 2018
예제: numpy와 matplotlib를 이용하여 이미지
흑백으로 변환하기 - 1
RGB 사진을 회색조로 변환하는 공식: Grayscale = 0.2126 × R + 0.7152 × G + 0.0722 × B
matplotlib 내의 image, pyplot 모듈과 numpy를 불러오기
import matplotlib.image as mp_image
Import matplotlib.pyplot as mp_plot
Import numpy as np
이미지 파일 불러오기(png형식만 가능)
input = mp_image.imread(‘[파일 경로와 이름]’)
print(input.ndim) #3이 출력될 때 정상
print(input.shape) #[세로, 가로, 컬러채널] 컬러채널이 3일 때(RGB)와 4일 때(ARGB)*로
나뉨
A = Alpha Value(Transparentness, 투명도)
14. Dongmin Kim, 2018
예제: numpy와 matplotlib를 이용하여 이미지
흑백으로 변환하기 - 2
변환할 흑백 사진을 저장할 2차원 텐서 생성(원본 사진과 같은 가로, 세로)
output = np.ndarray([input.shape[0], input.shape[1]])
각 픽셀의 컬러채널에 대하여 가중치를 곱하여 흑백으로 변환
output = 0.2126 * input[:, :, 0] + 0.7152 * input[:, :, 1] + 0.0722 * input[:, :, 2] #RGB
output = 0.2126 * input[:, :, 1] + 0.7152 * input[:, :, 2] + 0.0722 * input[:, :, 3] #ARGB
변환한 이미지를 출력
mp_plot.imshow(output, cmap=‘gray’)
mp_plot.plot()
원본 이미지와 비교