1 of 61

Human pose estimation 101

with Tensorflow

Jaewook Kang, Ph.D.

jwkang10@gmail.com�Oct. 2018

1

© 2017-2018

Jaewook Kang

All Rights Reserved

누구나 TensorFlow!

J. Kang Ph.D.

2 of 61

소 개

    • GIST EEC Ph.D. (2015)
    • 연구팀 리더 (~2018 5)
    • MoTLab Director (2018.1~)
    • Jeju DL Camp (2018,6-7)

(2018, 10-~)

    • 좋아하는 것:
      • 통계적 신호처리 / Compressed sensing
      • C++ Native Audio DSP 라이브러리 구현
      • Mobile Machine learning
      • Pose Estimation / Computer Vision
      • Tensorflow / Cloud TPU
      • 수영 덕력 6년

2

Jaewook Kang (강재욱)

누구나 TensorFlow!

J. Kang Ph.D.

3 of 61

Human Pose Estimation

  • Human Pose Estimation을 한마디로 요약하면?
    • 인물 카메라 입력으로부터 신체구조를 찾는 것

3

누구나 TensorFlow!

J. Kang Ph.D.

4 of 61

Human Pose Estimation

  • Human Pose Estimation을 한마디로 요약하면?
    • 인물 카메라 입력으로부터 신체구조를 찾는 것

4

3D Human Pose Estimation in the Wild by Adversarial Learning, CVPR2018

Wei Yang, Wanli OuyangXiaolong WangJimmy RenHongsheng LiXiaogang Wang

누구나 TensorFlow!

J. Kang Ph.D.

5 of 61

Human Pose Estimation

5

누구나 TensorFlow!

J. Kang Ph.D.

6 of 61

  • 오늘은 pose estimation의 가장 기본이 되는

2D single pose estimation

  • 졸라맨 에스티멘이션 만 다룹니다!

6

누구나 TensorFlow!

J. Kang Ph.D.

7 of 61

Human Pose Estimation

  • Pose estimation =

Localization + Classification

7

누구나 TensorFlow!

J. Kang Ph.D.

8 of 61

Human Pose Estimation

  • Pose estimation =

Localization + Classification

8

(x,y)=(0.34,0.92)

(x,y)=(0.34,0.92)

(x,y)=(0.34,0.92)

(x,y)=(0.34,0.92)

누구나 TensorFlow!

J. Kang Ph.D.

9 of 61

Human Pose Estimation

  • Pose estimation =

Localization + Classification

9

Head

Neck

Rshoulder

Lshoulder

누구나 TensorFlow!

J. Kang Ph.D.

10 of 61

Human Pose Estimation

  • Pose estimation
    • Localization: 입력 image로부터 신체부위 (keypoint)의 위치를 찾는 일
    • Classification: 찾은 신체 부위를 종류를 구분하는 일

10

Pose coordinate

Prediction

  • head=(0.1, 0.3)
  • neck=(0.2, 0.6)
  • RShoulder=(0.3, 0.1)
  • LShoulder=(0.1, 0.9)

누구나 TensorFlow!

J. Kang Ph.D.

11 of 61

DeepPose (Alexander’14)

  • 존 방법: Localization → classification
    • Localization는 잘 하는거 같은데…

11

누구나 TensorFlow!

J. Kang Ph.D.

12 of 61

DeepPose (Alexander’14)

  • 장님이 코끼리 만지는 것 처럼...

12

누구나 TensorFlow!

J. Kang Ph.D.

13 of 61

DeepPose (Alexander’14)

  • 기존 방법: Localization → classification
    • 신체의 일부가 가려져 있거나 보이지 않으면....

13

누구나 TensorFlow!

J. Kang Ph.D.

14 of 61

DeepPose (Alexander’14)

  • 기존 방법: Localization → classification
    • 신체의 일부가 가려져 있거나 보이지 않으면…
    • Classification을 잘 못함ㅠ
      • 이게 팔인가~ 다리인가~

14

누구나 TensorFlow!

J. Kang Ph.D.

15 of 61

DeepPose (Alexander’14)

  • 기존 방법: Localization → classification
    • 신체의 일부가 가려져 있거나 보이지 않으면…
    • Classification을 잘 못함ㅠ
      • 이게 팔인가~ 다리인가~
      • 사람의 신체구조에 대한 이해 부족

15

누구나 TensorFlow!

J. Kang Ph.D.

16 of 61

DeepPose (Alexander’14)

  • 핵심: Holistic reasoning + Coordinate Regression
    • 딥러닝을 이용하여 나무와 숲을 동시에 보자!
      • Localization + classification을 동시에 수행

Toshev, A., Szegedy, C., “Deeppose: Human pose estimation via deep neural networks,” CVPR 2014

16

누구나 TensorFlow!

J. Kang Ph.D.

17 of 61

DeepPose (Alexander’14)

  • 핵심: Holistic reasoning + Coordinate Regression
    • 딥러닝을 이용하여 나무와 숲을 동시에 보자!
      • Localization + classification을 동시에 수행

    • Global 신체 구조를 이해하는 모델!
      • 머리는 목위에 있다!
      • 안보이는 body parts도 찾을 수 있게!
      • Classification 정확도 개선!

17

누구나 TensorFlow!

J. Kang Ph.D.

18 of 61

DeepPose (Alexander’14)

  • 핵심: Holistic reasoning + Coordinate Regression
    • 목표: 입력 image X 를 2D 좌표 벡터 Y로 Regression(회귀) 하는 함수를 학습하는 것

18

누구나 TensorFlow!

J. Kang Ph.D.

19 of 61

DeepPose (Alexander’14)

  • 핵심: Holistic reasoning + Coordinate Regression
    • 목표: 입력 image X 를 2D 좌표 벡터 Y로 Regression(회귀) 하는 함수를 학습하는 것

19

: 회귀 함수

: 전처리 함수

: 후처리 함수

누구나 TensorFlow!

J. Kang Ph.D.

20 of 61

DeepPose (Alexander’14)

  • 핵심: Holistic reasoning + Coordinate Regression
    • 목표: 입력 image X 를 2D 좌표 벡터 Y로 Regression(회귀) 하는 함수를 학습하는 것

20

AlexNet

X

Input image

Coordinate prediction

Head = (0.1,0.3)

Neck = (0.2,0.6)

Rshoulder = (0.8,0.1)

….

Y

True coordinate

(y0,y1,....,yk)

L2 loss

Train

.

.

.

.

전처리

후처리

누구나 TensorFlow!

J. Kang Ph.D.

21 of 61

DeepPose (Alexander’14)

  • Localization 정확성이 부족해ㅠ

Special thank to 피카소! :-)

누구나 TensorFlow!

J. Kang Ph.D.

22 of 61

DeepPose (Alexander’14)

  • 개선: Pose displacement regression
    • Regressors의 직렬연결로 반복 개선

누구나 TensorFlow!

J. Kang Ph.D.

23 of 61

DeepPose (Alexander’14)

  • 개선: Pose displacement regression

.

*

1st regression

(y0,y1)^S=0

2nd regression

(y0,y1)^S=1

누구나 TensorFlow!

J. Kang Ph.D.

24 of 61

DeepPose (Alexander’14)

  • 개선: Pose displacement regression
    • Regressors의 직렬연결로 반복 개선
      • 각 body parts를 독립적으로 bounding box를 치고
      • 이전 prediction 와 True값의 차이(displacement)를 예측하여 개선

AlexNet

X with i-th box

from prev stage

Displacement

prediction

L2 loss

Train

Displacement

from prev stage

.

Single stage regressor

전처리

후처리

누구나 TensorFlow!

J. Kang Ph.D.

25 of 61

DeepPose (Alexander’14)

  • 개선: Pose displacement regression
    • Regressors의 직렬연결로 반복 개선
      • 각 body parts를 독립적으로 bounding box를 치고
      • 이전 prediction 와 True값의 차이(displacement)예측하여 개선

X

Input image

True coordinate

Y=(y0,y1,....,yk)

1st stage

regressor

.

S-th stage

regressor

Coordinate

prediction

Head = (0.1,0.3)

Neck = (0.2,0.6)

Rshoulder = (0.8,0.1)

….

.

.

X

Input image

Displacement

누구나 TensorFlow!

J. Kang Ph.D.

26 of 61

Convolutional Heatmap Regressor

  • Coordinate regression의 한계
    • 좌표값만 출력하기 때문에 모델 prediction Y가 포함하는 표현력 (정보)가 적음

    • 직렬연결 + 반복 coordinate prediction을 해도 충분한 location의 정확도 개선이 어려움
      • 이용할 수 있는 정보가 애당초 적으니깐!

26

누구나 TensorFlow!

J. Kang Ph.D.

27 of 61

Convolutional Heatmap Regressor

  • 핵심: Use heatmap regression
    • Heatmap: 2D Pixelwise likelihood map for part locations
    • heatmap셀단위로 part localization의 confidence값을 제공
      • part localization의 full 정보를 제공하는 것임

27

누구나 TensorFlow!

J. Kang Ph.D.

28 of 61

Convolutional Heatmap Regressor

  • 핵심: Use heatmap regression
    • 모델의 출력 값으로 heatmap을 사용
    • 좌표값을 뽑아내기 위한 argmax()를 사용

28

Model

X

Input image

Heatmap prediction

Y

True coordinate

(y0,y1,....,yk)

Some loss fn

Train

Heatmap

generator

.

.

.

True

Heatmap

.

누구나 TensorFlow!

J. Kang Ph.D.

29 of 61

Convolutional Heatmap Regressor

29

누구나 TensorFlow!

J. Kang Ph.D.

30 of 61

Multiscale Understanding

  • 문제: 다양한 크기의 사람 객체를 처리해야!

30

누구나 TensorFlow!

J. Kang Ph.D.

31 of 61

Multiscale Understanding

  • 문제: 다양한 크기의 사람 객체를 처리해야!

    • 다양한 크기의 receptive field를 가지도록 해야!

31

누구나 TensorFlow!

J. Kang Ph.D.

32 of 61

Multiscale Understanding

  • 문제: 다양한 크기의 사람 객체를 처리해야!

32

누구나 TensorFlow!

J. Kang Ph.D.

33 of 61

Multiscale Understanding

  • 문제: 다양한 크기의 사람 객체를 처리해야!
  • 해결방향1: Convolutional Pose Machine (Wei CVPR16)
    • Multi-stage feature learning을 하여 effective receptive field를 점차 키워나간다.
    • conv filter size를 다양하게 사용

33

누구나 TensorFlow!

J. Kang Ph.D.

34 of 61

Multiscale Understanding

  • 문제: 다양한 크기의 사람 객체를 처리해야!
  • 해결방향2: Stacked Hourglass (Newell, ECCV 16)
    • Multi-stage encoder-and-decoder 구조
    • Single channel pipeline
      • skip connection + max pooling + 같은 크기의 conv filter

34

누구나 TensorFlow!

J. Kang Ph.D.

35 of 61

Multiscale Understanding

  • 문제: 다양한 크기의 사람 객체를 처리해야!
  • 해결방향2: Stacked Hourglass (Newell, ECCV 16)
    • 체 구조 이해를 위한 Hourglass stacking!
    • Iterative heatmap update in a feedward manner

35

누구나 TensorFlow!

J. Kang Ph.D.

36 of 61

Beyond

  • 이후 연구 발전
    • TBU

36

누구나 TensorFlow!

J. Kang Ph.D.

37 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기

37

Single hourglass model

누구나 TensorFlow!

J. Kang Ph.D.

38 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기
    • Single hourglass module을 구현해보자!
      • dataloader.py
      • eval.py
      • model_builder.py
      • trainer.py
      • model_config.py
      • train_config.py

38

누구나 TensorFlow!

J. Kang Ph.D.

39 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기
    • Single hourglass module을 구현해보자!
      • dataloader.py (제공)
      • eval.py (baseline 코드제공)
      • model_builder.py (부분 제공)
      • trainer.py (baseline 코드제공)
      • model_config.py (baseline 코드제공)
      • train_config.py (baseline 코드제공)

39

누구나 TensorFlow!

J. Kang Ph.D.

40 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기
    • git 계정 생성: www.github.com

40

누구나 TensorFlow!

J. Kang Ph.D.

41 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기
    • fork tf-tiny-pose-estimation repo

41

누구나 TensorFlow!

J. Kang Ph.D.

42 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기
    • git clone your repo

42

[git fork는 웹에서 ]

$ git init

$ git branch -r

origin/HEAD -> origin/master

origin/develop

origin/features/fb_proj_baselines

origin/master

$ git checkout -t origin/features/fb_proj_baselines

누구나 TensorFlow!

J. Kang Ph.D.

43 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기
    • Single hourglass module을 구현해보자!
    • 배운것을 써먹자
    • https://goo.gl/5m93cg

43

누구나 TensorFlow!

J. Kang Ph.D.

44 of 61

Proj: Tiny Pose Est in Tensorflow

  • model_builder.py / model_config.py
    • model_config.py에서 파라미터값을 로드해서 입출력 shape를 결정
    • tf.slim API를 이용한 코딩

44

누구나 TensorFlow!

J. Kang Ph.D.

45 of 61

Proj: Tiny Pose Est in Tensorflow

  • model_builder.py / model_config.py
    • Depthwise separable conv module:

45

Layer

Type

Kernel size

Stride

Activation

D4

batchnorm

-

-

-

D3

Conv

1x1

1

relu

D2

batchnorm

-

-

-

D1

Conv

3x3

1

None

In

Input

-

-

-

누구나 TensorFlow!

J. Kang Ph.D.

46 of 61

Proj: Tiny Pose Est in Tensorflow

  • model_builder.py / model_config.py
    • Downsample module:

46

Layer

Type

OutputMaps

Output Size

Filter size

Stride

Activation

DS2

max pool

32

N/2 x N/2

3x3

2

None

DS1

Depthwise

Separable

Conv

32

NxN

-

-

-

In

Input

32

NxN

-

-

-

누구나 TensorFlow!

J. Kang Ph.D.

47 of 61

Proj: Tiny Pose Est in Tensorflow

  • model_builder.py / model_config.py
    • Upsample module:

47

Layer

Type

OutputMaps

Output Size

US2

Depthwise

separable

conv

32

NxN

US1

resize_bilinear

32

NxN

In

Input

32

N/2 x N/2

누구나 TensorFlow!

J. Kang Ph.D.

48 of 61

Proj: Tiny Pose Est in Tensorflow

  • model_builder.py / model_config.py
    • Reception module:

48

Layer

Type

OutputMaps

Output Size

Filter size

Stride

Activation

R4

maxpool

32

64x64

3x3

2

-

R3

Depthwise separable

conv

32

128x128

-

-

-

R2

batchnorm

32

128x128

-

-

-

R1

Conv

32

128x128

7x7

2

relu

In

Input

3

256x256

-

-

-

누구나 TensorFlow!

J. Kang Ph.D.

49 of 61

Proj: Tiny Pose Est in Tensorflow

  • model_builder.py / model_config.py
    • Hourglass module:

49

Layer

Type

OutputMaps

Output Size

filter size

Activation

HU10

upsample

32

64x64

HC9

conv → add skip connection from HD1 out

32

32x32

1x1

relu

HU8

upsample

32

32x32

HC7

conv → add skip connection from HD2 out

32

16x16

1x1

relu

HU6

upsample

32

16x16

HC5

conv → add skip connection from HD3 out

32

8x8

1x1

relu

HB4

Depthwise separable conv

32

8x8

HD3

downsample

32

8x8

HD2

downsample

32

16x16

HD1

downsample

32

32x32

In

Input

32

64x64

누구나 TensorFlow!

J. Kang Ph.D.

50 of 61

Proj: Tiny Pose Est in Tensorflow

  • model_builder.py / model_config.py
    • output module:

50

Layer

Type

OutputMaps

Output Size

Filter size

Stride

Activation

out

conv + dropout

14

64x64

1x1

1

None

In

Input

32

64x64

-

-

-

누구나 TensorFlow!

J. Kang Ph.D.

51 of 61

Proj: Tiny Pose Est in Tensorflow

  • 체 모델 구성도

51

누구나 TensorFlow!

J. Kang Ph.D.

52 of 61

Proj: Tiny Pose Est in Tensorflow

52

HD1

HD2

HD3

HB4

HU6

HC5

HC7

HU8

HU10

HC9

누구나 TensorFlow!

J. Kang Ph.D.

53 of 61

Tiny Pose Est in Tensorflow

  • trainer.py / train_config.py
    • tf.device 를 이용한 GPU사용 설정
    • tf.data.Iterator를 이용한 data feeding
    • train_config.py를 통한 훈련파라미터 설정
    • tensorboard 사용설정

53

누구나 TensorFlow!

J. Kang Ph.D.

54 of 61

Proj: Tiny Pose Est in Tensorflow

  • trainer.py / train_config.py
    • tf.device 를 이용한 GPU사용 설정
    • training set만 사용해서 훈련만 수행
    • tf.data.Iterator를 이용한 data feeding
    • train_config.py를 통한 훈련파라미터 설정
    • ckpt 저장
    • tensorboard 사용설정

54

누구나 TensorFlow!

J. Kang Ph.D.

55 of 61

Proj: Tiny Pose Est in Tensorflow

  • eval.py
    • batch_size = 1
    • validation set사용
    • ckpt로 부터 그래프 로드
    • loss함수 optimizer함수 제거
    • 평가 메트릭으로 성능 측정

55

누구나 TensorFlow!

J. Kang Ph.D.

56 of 61

Awesome Pose estimation Repo

  • paper 정리 repo (cbsudux ‘s repo)

56

누구나 TensorFlow!

J. Kang Ph.D.

57 of 61

Proj: Tiny Pose Est in Tensorflow

  • 프로젝트: 간단한 pose estimation 모델 구현하기
    • git clone your repo

57

AWS 실행방법

$ git clone <your git http>

$ git init

$ git branch -r

$ git checkout -t origin/features/fb_proj_baselines

$ cd tf-tiny-pose-estimation

$ cd tfmodules

$ python trainer.py

$ tensorboard --logdir ./export

------------------------------

Local

$ git commit -m “first comment”

$ git add .

$ git push

AWS

$ git pull

$ python trainer.py

winscp

누구나 TensorFlow!

J. Kang Ph.D.

58 of 61

Note

  1. master branch 버그 픽스 (필수)
  2. git checkout master
  3. git reset --hard HEAD
  4. git pull
  5. ai_challenge.zip full dataset download (필수)
    1. ./dataset에서 replace
    2. train_config에서 self.train_data_size로 조절
  6. pycocotool WIN 버전 깔기
  7. tensorboard --logdir ./export
  8. 각자 하고싶은 수준 정하기

58

누구나 TensorFlow!

J. Kang Ph.D.

59 of 61

Update 10/15

  • checkpoint저장 코드 추가
  • train / valid err 동시 측정 코드 추가
  • running device 확인 코드 추가

  • tensorboard로 heatmap 확인 가능하게 추가
  • model
    • inverted bottleneck 적용
    • hourglass in-out을 skip connection으로 연결
  • github star 추가 필수

59

누구나 TensorFlow!

J. Kang Ph.D.

60 of 61

Update 10/16

  • skip connection 수정
  • data_loader.py 버그 수정
    • dataset.apply(~)로 하고 다시 dataset에 대입을 안함
  • weight regularizer 추가

60

누구나 TensorFlow!

J. Kang Ph.D.

61 of 61

모두연 MoT랩 소개

  • Keywords:
    • Thin CNN Model
    • Model Pruning
    • Tensorflow + lite
    • Embedded Sys. (IoT)
    • Android Mobile/Things

61

누구나 TensorFlow!

J. Kang Ph.D.