SlideShare a Scribd company logo
1 of 17
Deep Learning in Python
Deep Neural Network
김동민|Dongmin Kim
Linear Algebra & Python Overview
Dongmin Kim
dmk2436@gmail.com
Dongmin Kim, 2018
Review - Machine Learning
 “… give computer systems the ability to "learn" with data,
without being explicitly programmed.” (Wikipedia)
Dongmin Kim, 2018
Review - Deep Learning
 Machine learning that uses the feature representation during learning
- Computational
- Probabilistic Modeling
Dongmin Kim, 2018
행렬
 행과 열로 표현한 데이터
a
𝑎
𝑏
𝑐
𝑑
𝑒
𝑎 𝑏
𝑐 𝑑
스칼라
(Scalar)
0차원
벡터
(Vector)
1차원
행렬
(Matrix)
2차원
텐서
(Tensor)
n차원(𝑛 ≥ 0)
Dongmin Kim, 2018
데이터의 차원
차원 예
0 1명의 키, 건물의 높이
1 여러명의 키, 시간에 따른 풍속
2 회색조 사진, 위도&경도에 따른 해발고도
3 컬러 사진, 회색조 영상, 3D 캐릭터 회색조 모델
4 컬러 영상, 3D 캐릭터 컬러 모델
Dongmin Kim, 2018
행렬 연산 1 - Transpose
 (𝐴 𝑇
)𝑖,𝑗 = 𝐴𝑗,𝑖
 (𝐴 𝑇
) 𝑇
= 𝐴
Dongmin Kim, 2018
행렬 연산 2 – 덧셈
 행렬 + 행렬
 𝐶 = 𝐴 + 𝐵 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 + 𝐵𝑖,𝑗
 행렬 + 벡터
 𝐶 = 𝐴 + 𝑏 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 + 𝑏𝑗
 행렬 + 스칼라
 𝐶 = 𝐴 + 𝑏 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 + 𝑏
Dongmin Kim, 2018
행렬 연산 3 – 곱셈(1)
 Product Operation: 𝐶 = 𝐴𝐵 ⟺ 𝐶𝑖,𝑗 = 𝑘 𝐴𝑖,𝑘 𝐵 𝑘,𝑗
 전제조건: A의 행수 = B의 열수
 A가 m*p, B가 p*n일 때, C는 m*n
 Hadamard Product Operation(element-wise)
 𝐶 = 𝐴 ⊚ 𝐵 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 𝐵𝑖,𝑗
 전제조건: A와 B는 모양(행수과 열수)이 같다.
Dongmin Kim, 2018
행렬 연산 3 – 곱셈(2)
 분배법칙 성립: 𝐴 𝐵 + 𝐶 = 𝐴𝐵 + 𝐵𝐶
 결합법칙 성립: 𝐴 𝐵𝐶 = 𝐴𝐵 𝐶
 교환법칙 불성립: 𝐴𝐵 = 𝐵𝐴가 항상 성립하는 것은 아님
Dongmin Kim, 2018
라이브러리 설치하기
 pip 업그레이드: python –m pip install –upgrade pip
 numpy 설치: pip3 install numpy
 matplotlib 설치: pip3 install matplotlib
 TensorFlow 설치: pip3 install –-upgrade tensorflow
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
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[:, :]
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, 투명도)
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()
 원본 이미지와 비교
Dongmin Kim, 2018
Python Overview
Dongmin Kim, 2018
Review - Matrix
 행과 열로 표현한 데이터
a
𝑎
𝑏
𝑐
𝑑
𝑒
𝑎 𝑏
𝑐 𝑑
스칼라
(Scalar)
0차원
벡터
(Vector)
1차원
행렬
(Matrix)
2차원
텐서
(Tensor)
n차원(𝑛 ≥ 0)
Dongmin Kim, 2018

More Related Content

What's hot

Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07Seok-joon Yun
 
2021 1학기 정기 세미나 6주차
2021 1학기 정기 세미나 6주차2021 1학기 정기 세미나 6주차
2021 1학기 정기 세미나 6주차Moonki Choi
 
K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링Edward Yoon
 
Transliteration English to Korean
Transliteration English to KoreanTransliteration English to Korean
Transliteration English to KoreanHyunwoo Kim
 
[Algorithm] Big O Notation
[Algorithm] Big O Notation[Algorithm] Big O Notation
[Algorithm] Big O NotationBill Kim
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap SortBill Kim
 
Graph neural network #2-2 (heterogeneous graph transformer)
Graph neural network #2-2 (heterogeneous graph transformer)Graph neural network #2-2 (heterogeneous graph transformer)
Graph neural network #2-2 (heterogeneous graph transformer)seungwoo kim
 
MNIST for ML beginners
MNIST for ML beginnersMNIST for ML beginners
MNIST for ML beginners홍배 김
 
Lecture 4: Neural Networks I
Lecture 4: Neural Networks ILecture 4: Neural Networks I
Lecture 4: Neural Networks ISang Jun Lee
 
Learning to remember rare events
Learning to remember rare eventsLearning to remember rare events
Learning to remember rare events홍배 김
 
계산 종이접기 입문(2)
계산 종이접기 입문(2)계산 종이접기 입문(2)
계산 종이접기 입문(2)SeungYong Yoon
 
Lecture 3: Unsupervised Learning
Lecture 3: Unsupervised LearningLecture 3: Unsupervised Learning
Lecture 3: Unsupervised LearningSang Jun Lee
 
GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산
GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산
GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산Taeung Ra
 
Dynamic Programming : Step by Step
Dynamic Programming : Step by StepDynamic Programming : Step by Step
Dynamic Programming : Step by Step인서 박
 
Recurrent Neural Net의 이론과 설명
Recurrent Neural Net의 이론과 설명Recurrent Neural Net의 이론과 설명
Recurrent Neural Net의 이론과 설명홍배 김
 

What's hot (18)

Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07
 
2021 1학기 정기 세미나 6주차
2021 1학기 정기 세미나 6주차2021 1학기 정기 세미나 6주차
2021 1학기 정기 세미나 6주차
 
K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링
 
Transliteration English to Korean
Transliteration English to KoreanTransliteration English to Korean
Transliteration English to Korean
 
[Algorithm] Big O Notation
[Algorithm] Big O Notation[Algorithm] Big O Notation
[Algorithm] Big O Notation
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap Sort
 
Graph neural network #2-2 (heterogeneous graph transformer)
Graph neural network #2-2 (heterogeneous graph transformer)Graph neural network #2-2 (heterogeneous graph transformer)
Graph neural network #2-2 (heterogeneous graph transformer)
 
AUTOML
AUTOMLAUTOML
AUTOML
 
MNIST for ML beginners
MNIST for ML beginnersMNIST for ML beginners
MNIST for ML beginners
 
Lecture 4: Neural Networks I
Lecture 4: Neural Networks ILecture 4: Neural Networks I
Lecture 4: Neural Networks I
 
Learning to remember rare events
Learning to remember rare eventsLearning to remember rare events
Learning to remember rare events
 
계산 종이접기 입문(2)
계산 종이접기 입문(2)계산 종이접기 입문(2)
계산 종이접기 입문(2)
 
Lecture 3: Unsupervised Learning
Lecture 3: Unsupervised LearningLecture 3: Unsupervised Learning
Lecture 3: Unsupervised Learning
 
DP 중급 2
DP 중급 2DP 중급 2
DP 중급 2
 
GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산
GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산
GPG 1.2 템플릿 메타프로그래밍을 이용한 빠른 수학 연산
 
Dynamic Programming : Step by Step
Dynamic Programming : Step by StepDynamic Programming : Step by Step
Dynamic Programming : Step by Step
 
Recurrent Neural Net의 이론과 설명
Recurrent Neural Net의 이론과 설명Recurrent Neural Net의 이론과 설명
Recurrent Neural Net의 이론과 설명
 
01. dp hard
01. dp hard01. dp hard
01. dp hard
 

Similar to iT Cafe - Linear Algebra & Python Overview

iT Cafe - Deep Learning
iT Cafe - Deep LearningiT Cafe - Deep Learning
iT Cafe - Deep LearningDongmin Kim
 
Introduction to SAC(Soft Actor-Critic)
Introduction to SAC(Soft Actor-Critic)Introduction to SAC(Soft Actor-Critic)
Introduction to SAC(Soft Actor-Critic)Suhyun Cho
 
인공지능 맛보기
인공지능 맛보기인공지능 맛보기
인공지능 맛보기Park JoongSoo
 
Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기
Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기
Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기Ki-Hwan Kim
 
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)HYUNJEONG KIM
 
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)Jaimie Kwon (권재명)
 
Introduction toDQN
Introduction toDQNIntroduction toDQN
Introduction toDQNCurt Park
 
Machine learning bysogood
Machine learning bysogoodMachine learning bysogood
Machine learning bysogoodS.Good Kim
 

Similar to iT Cafe - Linear Algebra & Python Overview (9)

iT Cafe - Deep Learning
iT Cafe - Deep LearningiT Cafe - Deep Learning
iT Cafe - Deep Learning
 
Introduction to SAC(Soft Actor-Critic)
Introduction to SAC(Soft Actor-Critic)Introduction to SAC(Soft Actor-Critic)
Introduction to SAC(Soft Actor-Critic)
 
인공지능 맛보기
인공지능 맛보기인공지능 맛보기
인공지능 맛보기
 
Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기
Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기
Python의 계산성능 향상을 위해 Fortran, C, CUDA-C, OpenCL-C 코드들과 연동하기
 
자료구조01
자료구조01자료구조01
자료구조01
 
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
 
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
 
Introduction toDQN
Introduction toDQNIntroduction toDQN
Introduction toDQN
 
Machine learning bysogood
Machine learning bysogoodMachine learning bysogood
Machine learning bysogood
 

iT Cafe - Linear Algebra & Python Overview

  • 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 캐릭터 컬러 모델
  • 6. Dongmin Kim, 2018 행렬 연산 1 - Transpose  (𝐴 𝑇 )𝑖,𝑗 = 𝐴𝑗,𝑖  (𝐴 𝑇 ) 𝑇 = 𝐴
  • 7. Dongmin Kim, 2018 행렬 연산 2 – 덧셈  행렬 + 행렬  𝐶 = 𝐴 + 𝐵 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 + 𝐵𝑖,𝑗  행렬 + 벡터  𝐶 = 𝐴 + 𝑏 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 + 𝑏𝑗  행렬 + 스칼라  𝐶 = 𝐴 + 𝑏 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 + 𝑏
  • 8. Dongmin Kim, 2018 행렬 연산 3 – 곱셈(1)  Product Operation: 𝐶 = 𝐴𝐵 ⟺ 𝐶𝑖,𝑗 = 𝑘 𝐴𝑖,𝑘 𝐵 𝑘,𝑗  전제조건: A의 행수 = B의 열수  A가 m*p, B가 p*n일 때, C는 m*n  Hadamard Product Operation(element-wise)  𝐶 = 𝐴 ⊚ 𝐵 ⟺ 𝐶𝑖,𝑗 = 𝐴𝑖,𝑗 𝐵𝑖,𝑗  전제조건: A와 B는 모양(행수과 열수)이 같다.
  • 9. Dongmin Kim, 2018 행렬 연산 3 – 곱셈(2)  분배법칙 성립: 𝐴 𝐵 + 𝐶 = 𝐴𝐵 + 𝐵𝐶  결합법칙 성립: 𝐴 𝐵𝐶 = 𝐴𝐵 𝐶  교환법칙 불성립: 𝐴𝐵 = 𝐵𝐴가 항상 성립하는 것은 아님
  • 10. Dongmin Kim, 2018 라이브러리 설치하기  pip 업그레이드: python –m pip install –upgrade pip  numpy 설치: pip3 install numpy  matplotlib 설치: pip3 install matplotlib  TensorFlow 설치: pip3 install –-upgrade tensorflow
  • 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()  원본 이미지와 비교
  • 16. Dongmin Kim, 2018 Review - Matrix  행과 열로 표현한 데이터 a 𝑎 𝑏 𝑐 𝑑 𝑒 𝑎 𝑏 𝑐 𝑑 스칼라 (Scalar) 0차원 벡터 (Vector) 1차원 행렬 (Matrix) 2차원 텐서 (Tensor) n차원(𝑛 ≥ 0)