Coder Social home page Coder Social logo

tucan9389 / poseestimation-tfliteswift Goto Github PK

View Code? Open in Web Editor NEW
150.0 10.0 20.0 24.44 MB

The baseline project for inferencing various Pose Estimation tflite models with TFLiteSwift on iOS

Home Page: https://github.com/motlabs/awesome-ml-demos-with-ios

License: Apache License 2.0

Ruby 0.24% Swift 99.22% Shell 0.54%
tensorflow ios tensorflow-lite openpose posenet simplepose cpm hourglass mobilenetv2 3d-pose-estimation

poseestimation-tfliteswift's Introduction

logo-pose-estimatiton-for-tflite-3

platform-ios swift-version lisence PRs Welcome

This project is Pose Estimation on iOS with TensorFlow Lite.
If you are interested in iOS + Machine Learning, visit here you can see various DEMOs.

2D pose estimation in real-time 3D pose estimation

Features

  • Support 2D pose estimaiton TFLite models
    • Real-time demo with Metal framwork
    • Photo album demo
  • Support 3D pose estimation TFLite model
    • Real-time demo with Metal framwork (but realtime model is not ready yet)
    • Real-time pose matching demo
    • Photo album demo
  • Render the result keypoints of 2D pose estimation in 2D demo page
  • Render the result keypoints of 3D pose estimation with SceneKit
  • Render the heatmaps of 2D pose estimation output
    • Part Confidence Maps for typical heatmap based models
    • Part Affinity Fields for OpenPose (2D multi-person)
  • Implemented pose-matching with cosine similiarity in 3D pose demo
  • Implemented to fix the shoulders' keypoints in 3D pose estimation to pre-process for pose-matching

Models

Source Images

Name gif img-0 img-1 img-2
Source -

Joint Samples

Model Names gif img-0 img-1 img-2
PoseNet - pose-demo-linedot-posenet-0 pose-demo-linedot-posenet-2 pose-demo-linedot-posenet-3
PEFM CPM - pose-demo-PEFMCPM-0 pose-demo-PEFMCPM-2 pose-demo-PEFMCPM-3
PEFM Hourglass - pose-demo-PEFMHourglass-0 pose-demo-PEFMHourglass-2 pose-demo-PEFMHourglass-3
OpenPose (multi-person) - pose-demo-openpose-0 pose-demo-openpose-2 pose-demo-openpose-3

Heatmap-ConfidenceMap Samples

Model Names gif img-0 img-1 img-2
PoseNet - - - -
PEFM CPM - pose-demo-heatmap-PEFMCPM-0 pose-demo-heatmap-PEFMCPM-2 pose-demo-heatmap-PEFMCPM-3
PEFM Hourglass - pose-demo-heatmap-PEFMHourglass-0 pose-demo-heatmap-PEFMHourglass-2 pose-demo-heatmap-PEFMHourglass-3
OpenPose (multi-person) - pose-demo-heatmap-posenet-0 pose-demo-heatmap-posenet-2 pose-demo-heatmap-posenet-3

Heatmap-PAF Samples

Model Names gif img-0 img-1 img-2
OpenPose (PAF x) - pose-demo-heatmap-pafx-PEFMHourglass-0 pose-demo-heatmap-pafx-PEFMHourglass-2 pose-demo-heatmap-pafx-PEFMHourglass-3
OpenPose (PAF y) - pose-demo-heatmap-pafy-PEFMHourglass-0 pose-demo-heatmap-pafy-PEFMHourglass-2 pose-demo-heatmap-pafy-PEFMHourglass-3

Meta Data

2D

✅ vs ☑️ Name Size Inference
Time
on iPhone11Pro
Post-process
Time
on iPhone11Pro
PCKh-0.5 multi person
vs
single person
Model Source Paper tflite
download
PoseNet 13.3 MB - - - single tensorflow/tensorflow PersonLab
PEFM CPM 2.4 MB - - - single edvardHua/PoseEstimationForMobile Convolutional Pose Machines
PEFM Hourglass v1 1.8 MB - - - single edvardHua/PoseEstimationForMobile Stacked Hourglass Networks
PEFM Hourglass v2 1.7 MB - - - single edvardHua/PoseEstimationForMobile Stacked Hourglass Networks
OpenPose 7.8 MB - - - multi ildoonet/tf-pose-estimation OpenPose
☑️ AlphaPose - - - - single osmr/imgclsmob RMPE
☑️ SelecSLS - - - - single osmr/imgclsmob -
☑️ IBPPose - - - - single osmr/imgclsmob -
☑️ Lightweight OpenPose - - - - single osmr/imgclsmob OpenPose

3D

✅ vs ☑️ Name Size Inference
Time
on iPhone11Pro
Post-process
Time
on iPhone11Pro
(metric) Model Source Paper tflite
download
Baseline3DPose 137.1 MB 347 ms 79 ms - mks0601/3DMPPE_POSENET_RELEASE Baseline3D download
LiteBaseline3DPose 16.6 MB 116 ms
(cpu only)
19 ms
(cpu only)
SangbumChoi/MobileHumanPose MHP download

Requirements

  • Xcode 11.3+
  • iOS 11.0+
  • Swift 5
  • CocoaPods
gem install cocoapods

Build & Run

  1. Install dependencies with cocoapods
cd ~/{PROJECT_PATH}
pod install
  1. Open the PoseEstimation-TFLiteSwift.xcworkspace and run the project

See also

License

This repository is licensed under Apache 2.0. Full license text is available in LICENSE.

poseestimation-tfliteswift's People

Contributors

tucan9389 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

poseestimation-tfliteswift's Issues

Baseline3DPoseEstimator returns only 14 points, not 18 points.

I have cloned this repo and tried 3D pose estimation using Baseline3DPoseEstimator, not LightBaseline3DPoseEstimator.
I have noticed that only 14 points are displayed on the screen. I mean from Pelvis to L_Wrist. As a result, right half of the human body is not drawn on the screen, while they are drawn on gifs on the REAME, and they are defined in types on the code.
I just thought this is dues to vagueness of bitmaps I input to the model, but whatever images I give to the model, it returns 14 points, which I have verified using print function.
I have read through softArgmax3D function, but I don't understand mathematical intricacies of the function, so it might be the problem.
Does anyone know how to solve this problem?

Support OpenPose tflite model (multi-pose)

Post-process Logic

  • 1. Get points from confidence map (make nodes) #38
  • 2. Make a bipartite graph with each part of points (make edges) #42
  • 3. Calculate line integral with PAF (compute costs of each edge) #42
  • 4. Connect each point and make human (solve assignment) #42
  • 5. Merge if a point is used duplicated in multiple human #42

Checklist

  • Add parameter control UIs for PAF #47
  • Limit the number of human on post-process #48
  • Test other model

Reference

Calculate the inference time of each model

Dear author,
May I ask you how to calculate the inference (the inference time and pose process time) time of each 3D human pose model as you showed?
Thank you so much!

Implement benchmark on real device (CPU, GPU, NPU)

Dataset

Metric

Define

ref: https://nanonets.com/blog/human-pose-estimation-2d-guide/

Percentage of Correct Key-points - PCK: A detected joint is considered correct if the distance between the predicted and the true joint is within a certain threshold. The threshold can either be:

.tflite files are missing

I am trying to run the project in Xcode 11.4.1 but all the .tflite files are missing under imgclsmob-Pose folder in Xcode. Anyone, please help me out with this. I want to compile the project.

Thanks

Inference with a still image

Purpose

Implement to import an image and inference

Tasks

  • Create tabbar for separating live captured image inference - #11
  • Get an image from device's photo album - #14
  • Inference the image - #25
  • Draw the result of inference - #25

Cannot inference with GPU on simulator (Xcode Version 11.4.1 (11E503a))

Summary

Couldn't run the model with .metal option on iPhone simulator after updating my Xcode to 11.4.1

Environment

  • macOS: Version 10.15.4 (19E287)
  • Xcode: Version 11.4.1 (11E503a)
  • TensorFlowLiteSwift: 2.1.0

How to solve

  • If you want to run on the simulator, change the accelerator default param to .cpu (163 line on TFLiteImageInterpreter.swift)

Responsibility of each layer

There are three layers for using tflite pose estimation model:

  • TFLiteImageInterpretor: the wrapper class for image preprocessing before inference
  • PoseEstimator: a simple protocol for abstraction
  • PoseNetPoseEstimator: concrete implement for PoseNet model

TFLiteImageInterpretor

TFLiteImageInterpretor is similar to VNCoreMLRequest. It has some pre-process logic for image and a tflite interpretor. Only TFLiteImageInterpretor class has a dependency with TensorFlowLiteSwift.

PoseEstimator

A simple protocol for abstraction. Users can create the concrete type conforming to PoseEstimator protocol and then use the estimator instance with the protocol, not concrete type. So except for the creation point, there is no use of the concrete type.

PoseNetPoseEstimator

PoseNetPoseEstimator is concrete type of PoseEstimator. It has PoseNet model specific information like input/output shape and normalization type.
For example, tensorflow/examples's PoseNet model needs following information:

  • input: [1, 257, 257, 3]
  • output: [1, 9, 9, 17]
  • input range: 0.0~1.0
  • input type: float32
  • quantized: false

TODO

  • preprocess
  • inference
  • postprocess

Support PoseNet tflite model

Model Infos

  • source: https://www.tensorflow.org/lite/models/pose_estimation/overview
  • file name: posenet_mobilenet_v1_100_257x257_multi_kpt_stripped.tflite
  • file size: 13.3 MB
  • input: [1, 257, 257, 3]
    • rgb color image
    • need normalized input 0.0~1.0
  • outputs: 4 output - postprocess in iOS
    • outputs[0]: [1, 9, 9, 17]
      • 17 heatmaps (because 17 keypoints output)
    • outputs[1]: [1, 9, 9, 34]
      • 17 * 2 offsets (because col and row offsets output) → as input size
    • outputs[2]: [1, 9, 9, 32] - ??
    • outputs[3]: [1, 9, 9, 32] - ??

Benchmark

mAP

Preparing

Processing Time

Preparing

How it performs

image
https://www.tensorflow.org/lite/models/pose_estimation/overview

Update README for v1.1.0

  • Add gif demos for each model (1 image per model)
    • Video: <#TODO#>
  • Add png demos for each model (3~4 images per model)
    • Image1: <#TODO#>
    • Image2: <#TODO#>
    • Image3: <#TODO#>
    • Image4: <#TODO#>

Package.swift has no Package.swift manifest for version 0.2.8

I try to build the project locally but have issues with the TFLiteSwift-Vision dependeny.
I get the error:

No such module 'TFLiteSwift_Vision'

and

/Package.swift has no Package.swift manifest for version 0.2.8 in https://github.com/tucan9389/TFLiteSwift-Vision

Using Xcode 13.4.1.

Any ideas what I am doing wrong?

Support shoulder auto-adjustment in pose matching

Goal

  • For robust pose matching algorithm, implement pre-processing before cosine similarity

How to make it

  1. Adjust predicted pose keypoints by captured right and left shoulder's keypoint
    • transform the predicted keypoints as same shoulder keypoints coordinate between predicted and captured

LiteBaseline3DPose No such file

Hello, I am having trouble finding these files.

PoseEstimation-TFLiteSwift/PoseEstimation-TFLiteSwift/LiteBaseline3DPose/litebaseline_3dpose_real_S.tflite: No such file or directory

PoseEstimation-TFLiteSwift/PoseEstimation-TFLiteSwift/LiteBaseline3DPose/litebaseline_3dpose_real_L.tflite: No such file or directory

I found the 'imgclsmob-Pose' and the 'Baseline3DPose' tflite files but am still having trouble finding the 'LiteBaseline3DPose' files

Thank you in advance.

which 3D model is being used?

Dear author!
Thank you for your work.
I am new to swift code and ios devices.
May I ask you when I build your code, which 3D pose model being used? the basedline3D or the lite one?
And how can I check it?
Thank you so much!

Please specify license.

Hi.
Thanks for your awesome work, we refered your postprocess implementation about openpose+TFlite.
When we'd like to use in a production code, we wondering if we can use it.

Add post-processing param control UIs

New UIs

  • Separate with sections
    • Part, Pair, Human
  • Control
    • Threshold of pair (Pair section)
    • Filter size using on NMS (Pair section)
    • Maximum number of people (Human section)

Concept UI

Support imgclsmob's pose estimation model

There are so many pose estimation models on imgclsmob repo. I'll collect the model's link and mobile models converted to .tflite format.

Model Name Model Extractor TFLite Model Link TFLite Model Size TFLite Model Input Shape TFLite Model Output Shape Keras Model Link (.h5) Keras Model Size
AlphaPose Fast-SE-ResNet-101b N/A 238.1 MB (1,224,224,3) (1,56,56,17) link 211 MB
SimplePose ResNet-18 link 61.5 MB (1,224,224,3) (1,56,56,17) link 54.3 MB
SimplePose ResNet-50b link 135.9 MB (1,224,224,3) (1,56,56,17) link 120 MB
SimplePose ResNet-101b link 211.8 MB (1,224,224,3) (1,56,56,17) link 188 MB
SimplePose ResNet-152b link 274.3 MB (1,224,224,3) (1,56,56,17) link 243 MB
SimplePose ResNet(A)-50b link 136 MB (1,224,224,3) (1,56,56,17) link 120 MB
SimplePose ResNet(A)-101b link 211.9 MB (1,224,224,3) (1,56,56,17) link 188 MB
SimplePose ResNet(A)-152b link 274.4 MB (1,224,224,3) (1,56,56,17) link 243 MB
SimplePose(Mobile) ResNet-18 N/A 51.4 MB (1,224,224,3) (1,56,56,17) link 45.4 MB
SimplePose(Mobile) ResNet-50b N/A 102.3 MB (1,224,224,3) (1,56,56,17) link 90.5 MB
SimplePose(Mobile) 1.0 MobileNet-224 N/A 20.1 MB (1,224,224,3) (1,56,56,17) link 17.8 MB
SimplePose(Mobile) 1.0 MobileNetV2b-224 N/A 16.4 MB (1,224,224,3) (1,56,56,17) link 14.6 MB
SimplePose(Mobile) MobileNetV3 Small 224/1.0 N/A 10.5 MB (1,224,224,3) (1,56,56,17) link 9.23 MB
SimplePose(Mobile) MobileNetV3 Large 224/1.0 N/A 19.1 MB (1,224,224,3) (1,56,56,17) link 16.9 MB
Lightweight OpenPose 2D MobileNet N/A 16.4 MB (1,224,224,3) (1,28,28,57) link 14 MB
Lightweight OpenPose 3D MobileNet N/A 20.4 MB (1,224,224,3) (1,28,28,114) link 17.5 MB
IBPPose - N/A - - - link 339 MB

Model Source

https://github.com/osmr/imgclsmob/tree/v0.0.460/tensorflow2#coco-keypoints-detection

TFLite Converting Script

https://github.com/osmr/imgclsmob/blob/bb5532e21ff27689e9f1dc133d86933b04396a1c/examples/convert_tf2_to_tfl.py

Sample Command

python convert_tf2_to_tfl.py \
--model lwopenpose2d_mobilenet_cmupan_coco \
--output-dir /home/outputs/pose/tflite;

reco for body "standing" horizontally (standing not on the feet)

Hello,

I am playing with pose estimation models. I am trying to find a model which run on iOS and able to identify join when the body is horizontal.
It seems most models (at least poseNet posenet_mobilenet_v1_100_257x257_multi_kpt_strippe) works better vertically.

do you have any suggestions ?

Thank you

CIContext is able to generate overly

In pixelBufferFromImage(UIImageExtension),

CIContext is generated whenever pixelBufferFromImage called.
I recommend to use shared CIContext object(But This isn't just meaning to make single-ton).
Becauase, If CIContext is generated overly then It cause memory issues(zombie object or leak).
So you should use shared CIContext object as possible.

Don't worry about to use shared CIContext object.
This object is thread safe.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.