Safemotion Lib
Loading...
Searching...
No Matches
smaction

  • safemotion의 행동인식 라이브러리

구조

│ ├── smaction
│ │ ├── builder
│ │ │ ├── model_builder.py
│ │ │ ├── runner_builder.py
│ │ ├──configs
│ │ │ ├── mmaction
| │ │ │ ├── ...
│ │ │ ├── ...
│ │ ├── datasets
| │ │ ├── transform
| │ │ │ ├── pose_transform.py
| │ │ ├── action_dataset_loader.py
| │ │ ├── ...
│ │ ├── demo
| │ │ ├── action_demo_with_anno.py
| │ │ ├── action_demo_with_video.py
│ │ ├── models
| │ │ ├── backbones
| │ │ │ ├── resnet2d.py
| │ │ │ ├── resnet3d.py
| │ │ │ ├── ...
| │ │ ├── heads
| │ │ │ ├── cat_layer.py
| │ │ │ ├── i3d_fusion.py
| │ │ │ ├── i3d_head.py
| │ │ │ ├── linear_head.py
| │ │ │ ├── mlp_head.py
| │ │ │ ├── ...
│ │ ├── runner
│ │ │ ├── action_recognition_runner.py
│ │ │ ├── ...
│ │ ├── utils
│ │ │ ├── action_utils.py
│ │ │ ├── ...
  • builder : models, runner의 클래스를 생성하는 함수
  • configs : runner 객체를 생성하기 위한 cfg 파일
  • datasets : 행동인식을 위한 데이터 관련 파일, 로더 및 데이터 변환 기능, 레이블맵 포함
  • demo : smdetect를 사용하는 간단한 데모 스크립트
  • models : 자체 개발 또는 내제화 모델, 모듈이 들어갈 폴더
  • runner : 오픈 소스 및 models의 구성을 활용한 클래스 정의
  • utils : smaction에서 사용될 유틸성 기능

구현 방법

  • smaction/models에 모듈 구현
  • smaction/runner에 클래스 구현
  • smaction/builder에 구현된 runner 및 모듈의 빌드 기능 설정
  • smaction/config에 구현된 runner 및 모듈을 기반으로 모델 정의

config 파일 구조

model = dict(
type='ActionRecognitionRunner', # <-runner 키
#아래는 runner의 파라미터, 아래 예시에는 backbone, head, predict_keys가 runner의 파라미터이다.
#runner의 구현에 따라서 알맞은 파라미터 설정 필요
backbone=dict(
resnet3d = dict(
type='ResNet3d', #<- 모듈의 키, models에 구현된 모듈
#아래는 모듈의 파라미터
in_channels = 17,
base_channels = 64,
stage_blocks = (4, 6, 3),
out_indices = (2, ),
spatial_strides = (2, 2, 2),
temporal_strides = (1, 1, 2),
dilations = (1, 1, 1),
conv1_kernel = (1, 7, 7),
conv1_stride_s = 1,
conv1_stride_t = 1,
pool1_stride_s = 1,
pool1_stride_t = 1,
inflate = (0, 1, 1),
inflate_style = '3x1x1',
input_key = 'pose_heatmap'
),
),
head=dict(
action_upper = dict(
type='I3DHead',
in_channels=1024,
num_classes=6,
dropout_ratio=0.5,
input_key = 'resnet3d',
),
action_lower = dict(
type='I3DHead',
in_channels=1024,
num_classes=12,
dropout_ratio=0.5,
input_key = 'resnet3d',
),
),
predict_keys = dict(
pred_action_upper = 'action_upper',
pred_action_lower = 'action_lower',
)
)

데모 실행

데모 준비 사항

  1. docker container 생성
    docker run --gpus all -v /media:/media --ipc=host -it -p 1200:1200 --name safemotion_lib_test docker.safemotion.kr:11443/library/smlab:v0.3
  2. smutils, smdetect, smtrack, smpose, smdataset 설치
  3. 각 기능별 모델 cfg 및 모델 파라미터 준비

실행 방법

  1. 데모스크립트(action_demo_with_anno.py, action_demo_with_video.py) 수정
    • 사용하는 모델의 cfg 경로 수정
    • 모델의 출력에 맞는 레이블 맵 사용
    • 모델 출력 변환 테이블 수정
    • 저장 경로 수정
    • action_demo_with_anno.py
      • 어노테이션 파일이 저장된 폴더 수정
    • action_demo_with_video.py
      • 비디오 파일이 저장된 폴더 수정
      • 비디오 파일의 확장자 수정
  2. 데모스크립트 실행
    • 어노테이션 파일 기반 행동인식 데모
      cd demo
      python action_demo_with_anno.py

행동인식 과정 설명

  1. 각 모델 빌드(검출, 추적, 포즈, 행동)
  2. 데이터 로드(이미지 또는 비디오 읽기)
  3. 객체 검출 및 추적
  4. 스켈레톤 검출
  5. 추적 아이디별로 스켈레톤 데이터 모으기
  6. 행동인식

TODO

  1. Deploy 코드 작성(TensorRT 변환)
  2. TensorRT 모델 빌드 코드 작성
  3. 입력 전처리 일반화 코드 작성(pipeline)