Posenet.py 보고서 #53
KimMin-Gwan
started this conversation in
Show and tell
Replies: 1 comment
-
함수별로 분해해서 다시 수정 및 설명하겠습니다. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Posenet 개요
Posenet은 Google Creative Lab에서 개발한 실시간 인간 자세 추정 기능이다. Tensorflow.js에서 동작하며 브라우저에서 동작하도록 설계되어있다. 우리는 이 Posenet을 로컬에서 사용가능하게 Python으로 구현 한 것을 사용했다.
python으로 Posenet을 구현하는 것은 Tensorflow.js에서 사용하는 것과는 차이가 있다. 특히 사람의 위치를 추정하는 방식을 스스로 지원하는 Posenet.js와는 다르게 Posenet.py는 사물 인식 모듈인 Mobile_net_v1을 사용한다.
사람의 위치를 특정한 후에는 Tensoflow.js에서 사용된 학습 모듈을 불러와 부위별 좌표와 예측값을 제공한다.
converter 모듈
config.py
Posenet.js에서 사용된 딥러닝 레이어가 저장된 config.yaml을 읽어오는 부분이다.
tfjs2python.py
과거에 posenet을 python으로 옮기는 과정을 진행했던 rwightman님이 작업한 내용들입니다.
전체적인 구성은 tensorflow_1의 레이어 구성방식을 따르고 있으며, config.yaml에서 받아온 레이어를 그대로 활용하여 사용합니다.
posenet.js 에서 사용된 weights 값을 그대로 활용하여 동작하고 있으며, mobilenet을 통해 구체적인 2d레이어를 구상합니다.
wget
tfjs2python.py을 이용하여 posenet의 기존 학습 값을 읽어오는 부분들 입니다.
_models라는 학습 모델을 하나 생성해주며 이 코드는 posenet을 처음 실행할 때 한번만 실행됩니다.
Posenet 패키지
argument.py
기존에 rwightman님이 사용한 코드에는 argparse를 이용해서 모델 특성이나 카메라 인풋의 크기를 조절 했다.
우리가 사용하는 시스템에 모델 특성과 카메라 인풋의 크기 조절이 유동적일 필요는 없으니 상수로 고정시켰다.
constants.py
부위별 좌표를 알아내는 posenet 모델의 특성상 부위의 이름이 문자열 형태로 있어야하고, 부위를 각각 선으로 연결하여 뼈대를 만들기 때문에 부위들 간의 인과 관계를 묶어서 저장한다.
decode_multi.py
부위에 찍힌 keypoint 사이의 거리를 계산한다.
사람일 확률을 받아온다. 일정 확률이 넘어가면 사람으로 인정된다.
부위별 확률을 계산하여 리턴한다.
확률의 크기에 상관없이 전부다 리턴시킨다.
predict하여 도출된 값들을 정리하여 활용가능하게 만들어준다.
자세한 동작은 주석을 참고
decode.py
주어진 edge_id와 source_keypoint를 사용하여 target_keypoint_id와 일치하는 키포인트를 찾는 함수
예측한 키포인트 관련 정보를 사용하여 이미지 상에서 실제 키포인트 좌표를 디코딩하는 함수
자세한 동작 과정은 주석을 참고
detection.py
본문의 반복문에 있던 코드를 하나의 함수로 구현했다.
앞 부분에서는 현재 프래임을 predict 하는 부분이다. decode_mulitiple_pose에서 predict가 실행된다.
매게변수로 받는 gesture 라는 변수를 기준으로 figure_out_command함수로 가거나 draw_parts_name을 실행한다.
draw_parts_name은 평시 상태에서 사용되며, 부위별 좌표를 받아내는 것 이외 동작은 없다.
figure_out_command는 제스처 모드에 사용되며, 제스처를 구분하는 제스처 모드가 바로 이것이다.
gesture_mode.py
박세빈님이 구현한 내용으로 대체
model.py
파라미터에 따라 다른 모델을 불러온다.
여기서는 101만 불러오기 때문에 3을 리턴시킨다.
레이어와 모델이 들어있은 config.yaml 파일을 읽어오는 부분이다.
converter 모듈로 최초에 _model 을 생성하고나서 _model의 내용을 읽어오는 부분으로 구성되어 있다.
초기에 argparse에 의해 model의 특징을 선택 할 수 있도록 되어져 있었는데, 이 부분은 그대로 사용했다.
utils.py
유효한 해상도를 계산하는 함수
입력 이미지를 처리하는 함수이다.
입력 이미지는 source_img로 제공, scale_factor와 output_stride 매개변수를 사용하여 이미지를 전처리한다.
웹캠에서 읽은 영상 프레임을 입력으로 받아 함수 호출을 통한 처리 후 반환하는 함수
점의 좌표를 가지고 오는 함수 (연결된 키포인트들의 좌표를 계산)
입력 이미지 위에 PoseNet 알고리즘이 예측한 결과를 시각화하여 출력 이미지를 반환하는 함수
Beta Was this translation helpful? Give feedback.
All reactions