Test Dataset 준비
AI-Hub
샘플 데이터 ? ※샘플데이터는 데이터의 이해를 돕기 위해 별도로 가공하여 제공하는 정보로써 원본 데이터와 차이가 있을 수 있으며, 데이터에 따라서 민감한 정보는 일부 마스킹(*) 처리가 되
www.aihub.or.kr
AI Hub에서 제공하는 “버스 승객 승하차 영상” 중, OpenPose 테스트를 위해 버스 내부를 촬영한 영상 데이터만 다운로드
압축 풀기 (.tar, 분할 압축)
* API 다운로드 파일은 분할 압축되어 다운로드 됩니다. 분할 압축 해제를 위해서는 분할 압축 해제를 지원하는 프로그램(예: 반디집, 7-Zip)을 사용하시길 권장합니다.
How to unzip a multipart (spanned) ZIP on Linux?
How to unzip a multipart (spanned) ZIP on Linux?
I need to upload a 400mb file to my web server, but I'm limited to 200mb uploads. My host suggested I use a spanned archive, which I've never done on Linux. I created a test in its own folder, zip...
unix.stackexchange.com
# .tar 파일 압축 풀기
$ tar -xvf [파일명].tar
# 분할 압축 풀기
# 1. You will need to join them first
$ cat [파일명].zip.part* > busdata.zip
# 2. unzip(command) / Extract here
$ unzip busdata.zip
연속된 이미지 → 동영상 변환 (ffmpeg 명령어)
동영상으로 변환하기 위해서는 이미지 파일명이 연속되어야 하므로 rename.py 코드 작성
이때, 그냥 rename을 하게 되면 파일이 정렬되지 않은 채로 바뀌기 때문에 코드 내에서 파일명대로 정렬하는 기능 추가
참고한 블로그:
https://jakupsil.tistory.com/31
파이썬으로 파일을 정렬하고 이름 변경하기
제가 평소에 다루는 파일 중에 capture_{번호}.bmp라는 형식으로 저장된 이미지 파일들이 있습니다. 저는 이 파일들을 sequence_{스텝 번호}_{패턴 번호}.bmp라는 형식으로 파일 이름을 고치려고 합니다.
jakupsil.tistory.com
# rename.py
import os
# 파일명에 포함된 숫자를 추출하여 정수형으로 변환하기
# 오름차순으로 정렬하기
# 정렬된 번호를 이용해서 순서대로 파일 불러오기
directory = '[your images file directory]'
file_list = [f for f in os.listdir(directory) if '.jpg' in f]
num_list = sorted([int(l.split('_')[2].split('.')[0]) for l in file_list])
# print(num_list)
for idx in range(len(file_list)):
src_file = directory + '[district]attend_660C_{}.jpg'.format(num_list[idx])
output = directory + '{:04d}.jpg'.format(idx)
# print('{} --> {}'.format(src_file, output))
os.rename(src_file, output)
rename 후 연속된 이미지를 동영상으로 변환
# 10 fps로 설정
ffmpeg -r 10 -i "%04d.jpg" -vcodec libx264 "output.mp4"
back_in: 후문으로 승차, 후문 focus
back_out: 후문으로 하차, 후문 focus
crowd_out: 매우 많은 승객이 있을 때 후문으로 하차, 후문 focus
front_out: 후문으로 하차, 정문 focus
innout: 정문으로 승차 및 후문으로 하차, 정문 focus
mid_out: 후문으로 하차, 중간 focus
실습 with GitHub Code
https://github.com/felixchenfy/Realtime-Action-Recognition
GitHub - felixchenfy/Realtime-Action-Recognition: Apply ML to the skeletons from OpenPose; 9 actions; multiple people. (WARNING:
Apply ML to the skeletons from OpenPose; 9 actions; multiple people. (WARNING: I'm sorry that this is only good for course demo, not for real world applications !!! Those ary very difficult !!!...
github.com
개발 환경
Python 3.8.5 (≥3.6.)
git clone <https://github.com/felixchenfy/Realtime-Action-Recognition.git> --recursive
cd Realtime-Action-Recognition
pip install -r requirements.txt
Download tf-pose-estimation
export MyRoot=$PWD
# src 경로에 githubs 폴더 추가
cd src/githubs
git clone <https://github.com/felixchenfy/ildoonet-tf-pose-estimation>
mv ildoonet-tf-pose-estimation tf-pose-estimation
Find pretrained models
src/githubs/tf-pose-estimation/models/graph 경로에 mobilenet_thin 모델 확인
Install libraries
$ conda create -n tf tensorflow-gpu
$ conda activate tf
$ cd $MyRoot/src/githubs/tf-pose-estimation
$ pip install -r requirements.txt
$ pip install jupyter tqdm
# Install tensorflow (2.x는 tensorflow.contrib 지원 안함)
$ conda install tensorflow==1.15
# Compile c++ library
$ sudo apt install swig
$ pip3 install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"
$ cd $MyRoot/src/githubs/tf-pose-estimation/tf_pose/pafprocess
$ swig -python -c++ pafprocess.i && python3 setup.py build_ext --inplace
ERROR: Cannot uninstall 'certifi'. …. 해결
-> pip install [install 하고자 하는 것] --ignore-installed certifi
Verify Installation
# Make sure you can successfully run its demo examples:
$ cd $MyRoot/src/githubs/tf-pose-estimation
$ python run.py --model=mobilenet_thin --resize=432x368 --image=./images/p1.jpg
Run: Inference (Test)
경로: Realtime-Action-Recognition
Video file
python src/s5_test.py \\
--model_path model/trained_classifier.pickle \\
--data_type video \\
--data_path data_test/exercise.avi \\
--output_folder output
Folder of Images
python src/s5_test.py \\
--model_path model/trained_classifier.pickle \\
--data_type folder \\
--data_path data_test/apple/ \\
--output_folder output
Web Camera
python src/s5_test.py \\
--model_path model/trained_classifier.pickle \\
--data_type webcam \\
--data_path 0 \\
--output_folder output
ImportError: cannot import name 'keras'
-> ! pip install tensorflow --upgrade
ModuleNotFoundError: No module named 'sklearn.neighbors.classification’
-> pip uninstall scikit-learn $ pip install scikit-learn==0.20.4
Test Result (video)
output/exercise/
├── skeletons
│ ├── 00000.txt
│ ├── 00001.txt
│ └── ...
└── video.avi
위와 같은 형식으로 output 생성
결론
장점
모델 테스트 속도가 빨라 실시간성에 용이하다.
순간순간의 action recognition이 잘 된다.
코드가 단순하여 수정하기 좋다.
단점
버스(BRT) 특성 상 사람의 몸이 의자에 일부 가려져 보이지 않는 경우가 많다.
버스가 혼잡하면 사람을 잘 인식하지 못한다.
'컴퓨터비전 > 실습' 카테고리의 다른 글
[컴퓨터비전/실습] RAPiD를 이용한 overhead human detection (0) | 2024.02.02 |
---|---|
[컴퓨터비전/실습] YOLOv8을 이용한 Head Detection 간단 실습 (0) | 2024.01.25 |
[컴퓨터비전/실습] MotionBERT를 이용한 Single Person 3D Pose Estimation (0) | 2023.12.27 |
[컴퓨터비전/논문리뷰] Real-time smart lighting control using human motion tracking from depth camera (0) | 2023.12.13 |
[컴퓨터비전/실습] Instant-NGP with Custom Dataset (0) | 2023.12.13 |