Pose Estimation on iOS with TensorFlow Lite

Overview

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.

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

    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?

    opened by pc11000 8
  • .tflite files are missing

    .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

    opened by Meri994 5
  • can not find the file lightweight_baseline_choi.tflite

    can not find the file lightweight_baseline_choi.tflite

    Hi, I was trying to run your application, but I cant seem to find lightweight_baseline_choi.tflite model file, can you please add the link for downloading.

    opened by AshishShukla-1992 3
  • LiteBaseline3DPose No such file

    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.

    opened by SpencerIO 2
  • [PR] Implement post-process of 3d pose estimation (SimpleBaseline)

    [PR] Implement post-process of 3d pose estimation (SimpleBaseline)

    | demo | | --- | | simplebaseline-3dpose-demo-stillimage |

    Related Issue

    • https://github.com/tucan9389/PoseEstimation-TFLiteSwift/issues/28

    PR Points

    • Implement the pre-process
      • Image normalization using in PyTorch usually
    • Implement the post-process
      • Define the keypoints each index
      • Implement softmax
      • Implement sum function that could get dim as augment like numpy or pytorch
      • Optimize sum and mul with Accelerate framework
    • Log the 3d points
    • Draw the 3d points in the app screen
    • Support real-time (later)
    • Implement additional post-processing for removing some noises (later)
    opened by tucan9389 2
  • reco for body

    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

    opened by sgu-fai 2
  • Please specify license.

    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.

    👍 good first issue 
    opened by Yukimune 2
  • Connection to assetsd was interrupted - assetsd exited, died, or closed the photo library Message from debugger: Terminated due to memory issue

    Connection to assetsd was interrupted - assetsd exited, died, or closed the photo library Message from debugger: Terminated due to memory issue

    hello,

    I am getting this error on iPhone8. No apps running on background. I think the msg is clear but any tips to make is work ? maybe load less models ?

    Connection to assetsd was interrupted - assetsd exited, died, or closed the photo library
    Message from debugger: Terminated due to memory issue
    

    any idea ?

    opened by sgu-fai 1
  • [PR] Make some empty class and struct for interpretor

    [PR] Make some empty class and struct for interpretor

    Related Issue

    • https://github.com/tucan9389/PoseEstimation-TFLiteSwift/issues/5

    PR Point

    • Add TFLiteImageInterpretor for implementing pre-process of image input
    • Add PoseEstimator protocol for abstraction
    • Add PoseNetPoseEstimator for specifying input/output and model name of PoseNet tflite file
    opened by tucan9389 1
  • [PR] Add shoulder fixing function for 3d pose keypoints and lines

    [PR] Add shoulder fixing function for 3d pose keypoints and lines

    PR Point

    • Implement shoulder fixing function for 3d pose keypoints
      • Implement to rotate 3d vector by x-axis, y-axis, z-axis
      • Implement custom operator for multiplying or moving 3d vector
      • Use the shoulder fixing before performing pose-matching algorithm
    • Add a shoulder fixing switch for each 3d live demo page

    Vector Rotation

    In 3D rotating around the Z-axis would be

        |cos θ   −sin θ   0| |x|   |x cos θ − y sin θ|   |x'|
        |sin θ    cos θ   0| |y| = |x sin θ + y cos θ| = |y'|
        |  0       0      1| |z|   |        z        |   |z'|
    

    around the Y-axis would be

        | cos θ    0  -sin θ| |x|   | x cos θ + z sin θ|   |x'|
        |   0      1       0| |y| = |         y        | = |y'|
        |sin θ    0    cos θ| |z|   |−x sin θ + z cos θ|   |z'|
    

    around the X-axis would be

        |1     0           0| |x|   |        x        |   |x'|
        |0   cos θ    −sin θ| |y| = |y cos θ − z sin θ| = |y'|
        |0   sin θ     cos θ| |z|   |y sin θ + z cos θ|   |z'|
    

    Reference

    • https://developer.apple.com/documentation/accelerate/working_with_matrices
    • https://stackoverflow.com/a/14609567/4160632
    opened by tucan9389 0
  • Pose capturing and matching

    Pose capturing and matching

    • [x] capture 3d pose by tapping a button or listening to "capture"
      • speech recognition: https://github.com/jen2/Speech-Recognition-Demo
    • [x] match the inferred pose and captured pose
    • [x] show the matching score and highlight which captured pose is matched
    opened by tucan9389 0
  • Where is the code for the 2D demo?

    Where is the code for the 2D demo?

    Hi, in the readme you also have the 2D Demo .gif: https://user-images.githubusercontent.com/37643248/77227994-99ba2a80-6bc7-11ea-9b08-9bb57723bc42.gif

    But where is the matching code to get this result? I only see the 3D views?

    opened by pc11000 1
  • lightweight_baseline_choi model shape issues

    lightweight_baseline_choi model shape issues

    Hi ,

    I tried my own trained model, but the output shape of my model is 1 x 21 x 3, but the model that you gave has an output shape of 1 x 672 x 32 x 32. I trained the model using https://github.com/SangbumChoi/MobileHumanPose repo. Could you please tell me why is this issue happening?

    Thanks and Regards, Ashish

    opened by AshishShukla-1992 0
  • EXC_BAD_ACCESS (code=1, address=0x14fdff900) during scale operation on cropped image

    EXC_BAD_ACCESS (code=1, address=0x14fdff900) during scale operation on cropped image

    The app sometimes crashes during the scale operation in vImageScale_ARGB8888(&croppedImage, &resizedImage, nil, vImage_Flags(0)) == kvImageNoError

    Screen Shot 2021-05-28 at 2 09 58 PM
    opened by philippgehrke 1
  • Support shoulder auto-adjustment in pose matching

    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
    opened by tucan9389 0
  • Use Accelerate framework on post-processing

    Use Accelerate framework on post-processing

    Editing Point

    https://github.com/tucan9389/PoseEstimation-https://github.com/tucan9389/PoseEstimation-TFLiteSwift/blob/da2931e39eea3065d72d4c83383387bbef482bc0/PoseEstimation-TFLiteSwift/Argmax.swift#L25-L41

    Reference

    https://github.com/hollance/CoreMLHelpers/blob/0bd7f983c3e73abcffb692b4428e889ed4cf01b6/CoreMLHelpers/Math.swift#L23-L82

    💪 enhancement 
    opened by tucan9389 0
Releases(v2.1.0)
Owner
tucan9389
ML for work, iOS for fun
tucan9389
Flutter Piano Audio Detection implemented with Tensorflow Lite Model (Google Magenta)

FlutterPianoAudioDetection Plugin Flutter Piano Audio Detection implemented with Tensorflow Lite Model (Google Magenta) Android Implementation iOS/iPa

WonyJeong 27 Dec 29, 2022
Realtime yoga pose detection and classification plugin for Flutter using MLKit

ML Kit Pose Detection Plugin Flutter plugin for realtime pose detection using MLKit's Blazepose. License Copyright (c) 2021 Souvik Biswas, Bharat Bira

Souvik Biswas 8 May 5, 2022
BetterMood is an iOS app that uses Tensorflow to recognize user’s emotions

BetterMood is an iOS app that uses Tensorflow to recognize user’s emotions, convert it into categories then send via our api along with the user’s date of birth and name, to end up with a emotion analyse and horoscope prediction.

Yosri 2 Sep 30, 2021
Easily craft fast Neural Networks on iOS! Use TensorFlow models. Metal under the hood.

Bender Bender is an abstraction layer over MetalPerformanceShaders useful for working with neural networks. Contents Introduction Why did we need Bend

xmartlabs 1.7k Dec 24, 2022
A lightweight library to calculate tensors in Swift, which has similar APIs to TensorFlow's

TensorSwift TensorSwift is a lightweight library to calculate tensors, which has similar APIs to TensorFlow's. TensorSwift is useful to simulate calcu

Qoncept, Inc. 323 Oct 20, 2022
Models and examples built with TensorFlow

Welcome to the Model Garden for TensorFlow The TensorFlow Model Garden is a repository with a number of different implementations of state-of-the-art

null 74.9k Dec 29, 2022
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.

English | 简体中文 | 繁體中文 | 한국어 State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow ?? Transformers provides thousands of pretrained models

Hugging Face 77.1k Dec 31, 2022
TensorFlow C API Class Wrapper in Server Side Swift.

Perfect TensorFlow 简体中文 This project is an experimental wrapper of TensorFlow C API which enables Machine Learning in Server Side Swift. This package

PerfectlySoft Inc. 169 Dec 11, 2022
Swift for TensorFlow

Swift for TensorFlow (Archived) Swift for TensorFlow was an experiment in the next-generation platform for machine learning, incorporating the latest

null 6.1k Dec 31, 2022
Mobile-ios-ml - SBB Mobile Machine Learning for iOS devices

ESTA library: Machine Learning for iOS This framework simplifies the integration

Swiss Federal Railways (SBB) 9 Jul 16, 2022
Largest list of models for Core ML (for iOS 11+)

Since iOS 11, Apple released Core ML framework to help developers integrate machine learning models into applications. The official documentation We'v

Kedan Li 5.6k Jan 3, 2023
Artificial intelligence/machine learning data structures and Swift algorithms for future iOS development. bayes theorem, neural networks, and more AI.

Swift Brain The first neural network / machine learning library written in Swift. This is a project for AI algorithms in Swift for iOS and OS X develo

Vishal 331 Oct 14, 2022
Model stock prediction for iOS

Stockify Problem Investing in Stocks is great way to grow money Picking the right stocks for you can get tedious and confusing Too many things to foll

Sanchitha Dinesh 1 Mar 20, 2022
Ezviz IoT Home SDK iOS Demo.

SDK Demo SDK Demo 演示了萤石 App SDK 的接入流程以及 SDK 开放的功能,因此通过参考 Demo 可以基本解决再接入过程中碰到的问题。 Demo 模块介绍: 登录模块:包含注册,登录,忘记密码功能 家庭模块:包含添加家庭,删除家庭,修改家庭信息,邀请家庭成员和移除家庭成员等

萤石.开放平台 1 May 27, 2022
Running Swift automatic differentiation on iOS

Differentiation Demo This is an example of Swift's automatic differentiation running on iOS. It is a modified version of the game from ARHeadsetKit tu

Philip Turner 7 Apr 27, 2022
Resource monitor - A flutter plugin for Android and IOS to monitor CPU and RAM usage of device.

resource_monitor A flutter plugin for Android and IOS to monitor CPU and RAM usage of device. TODO Implement Android Side of this plugin. Add listener

Skandar Munir 1 Nov 11, 2022
Slot-machine - SwiftUI - iOS App Slot Machine game

Slot Machine SwiftUI Masterclass project iPhone, iPad and Mac (with Catalyst framework) Complex interface Extensions and custom View Modifiers Input t

Arthur Neves 1 Sep 12, 2022
This repo contains beginner examples to advanced in swift. Aim to create this for learning native iOS development.

iOS-learning-with-swift-22 This repo contains beginner examples to advanced in swift. Aim to create this for learning native iOS development. Oh, you

Umesh Jangid 0 Jan 9, 2022
Hand-gesture recognition on iOS app using CoreML

GestureAI-CoreML-iOS Hand-gesture recognizer using CoreML Demo Screenshots This app is using RNN(Recurrent Neural network) with CoreML on iOS11. The m

null 151 Nov 2, 2022