The example project of inferencing Pose Estimation using Core ML

Overview

logo-pose-estimatiton-for-coreml-3

platform-ios swift-version lisence

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

한국어 README

Jointed Keypoints Hatmaps Still Image

Video source:

Pose Capturing Pose Matching

Features

  • Estimate body pose on a image
  • Inference with camera's pixel buffer on real-time
  • Inference with a photo library's image
  • Visualize as heatmaps
  • Visualize as lines and points
  • Pose capturing and pose matching

How it works

how_it_works

Requirements

  • Xcode 9.2+
  • iOS 11.0+
  • Swift 4

Model

Get PoseEstimationForMobile's model

Download this temporary models from following link.

Or

☞ Download Core ML model model_cpm.mlmodel or hourglass.mlmodel.

input_name_shape_dict = {"image:0":[1,192,192,3]} image_input_names=["image:0"]
output_feature_names = ['Convolutional_Pose_Machine/stage_5_out:0']

-in https://github.com/tucan9389/pose-estimation-for-mobile

Model Size, Minimum iOS Version, Input/Output Shape

Model Size
(MB)
Minimum
iOS Version
Input Shape Output Shape
cpm 2.6 iOS11 [1, 192, 192, 3] [1, 96, 96, 14]
hourhglass 2 iOS11 [1, 192, 192, 3] [1, 48, 48, 14]

Infernece Time (ms)

Model vs. Device 11
Pro
XS
Max
XR X 8 8+ 7 7+ 6S+ 6+
cpm 5 27 27 32 31 31 39 37 44 115
hourhglass 3 6 7 29 31 32 37 42 48 94

mobile-pose-estimation

Total Time (ms)

Model vs. Device 11
Pro
XS
Max
XR X 8 8+ 7 7+ 6S+ 6+
cpm 23 39 40 46 47 45 55 58 56 139
hourhglass 23 15 15 38 40 40 48 55 58 106

FPS

Model vs. Device 11
Pro
XS
Max
XR X 8 8+ 7 7+ 6S+ 6+
cpm 15 23 23 20 20 21 17 16 16 6
hourhglass 15 23 23 24 23 23 19 16 15 8

Get your own model

Or you can use your own PoseEstimation model

Build & Run

1. Prerequisites

1.1 Import pose estimation model

모델 불러오기.png

Once you import the model, compiler generates model helper class on build path automatically. You can access the model through model helper class by creating an instance, not through build path.

1.2 Add permission in info.plist for device's camera access

prerequest_001_plist

2. Dependencies

No external library yet.

3. Code

3.1 Import Vision framework

import Vision

3.2 Define properties for Core ML

// properties on ViewController
typealias EstimationModel = model_cpm // model name(model_cpm) must be equal with mlmodel file name
var request: VNCoreMLRequest!
var visionModel: VNCoreMLModel!

3.3 Configure and prepare the model

override func viewDidLoad() {
    super.viewDidLoad()

    visionModel = try? VNCoreMLModel(for: EstimationModel().model)
	request = VNCoreMLRequest(model: visionModel, completionHandler: visionRequestDidComplete)
	request.imageCropAndScaleOption = .scaleFill
}

func visionRequestDidComplete(request: VNRequest, error: Error?) {
    /* ------------------------------------------------------ */
    /* something postprocessing what you want after inference */
    /* ------------------------------------------------------ */
}

3.4 Inference 🏃‍♂️

// on the inference point
let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer)
try? handler.perform([request])

Performance Test

1. Import the model

You can download cpm or hourglass model for Core ML from tucan9389/pose-estimation-for-mobile repo.

2. Fix the model name on PoseEstimation_CoreMLTests.swift

3. Run the test

Hit the ⌘ + U or click the Build for Testing icon.

See also

Comments
  • Hourglass model

    Hourglass model

    Try to use hourglass model in here.

    • input_image_shape: [1, 192, 192, 3]
    • output_shape: [1, 48, 48, 14]
    • input_node_name: image
    • output_node_name: hourglass_out_3

    I think it will speed up 3x than old model and the precision is acceptable.

    Tomorrow I will update my repo.

    Look forward to your replay ( ? FPS on ipx )

    opened by edvardHua 9
  • Performance problem in Xcode 11.3

    Performance problem in Xcode 11.3

    Run Joint View sample in Xcode 10.3, the FPS is 15 ~ 20, But run same project in Xcode 11.3, the FPS dropdown to 6~7, my device is iPhone 7, Is anything setting I need to change ?

    opened by vml933 4
  • Can't build project

    Can't build project

    Keep running into

    Unknown class _TtC21PoseEstimation_CoreML19JointViewController in Interface Builder file.
    

    Error

    Tried running on Iphone 6 and Iphone 11 simulators

    opened by TheBuilderJR 3
  • How to add normalization to the image in preprocess?

    How to add normalization to the image in preprocess?

    Hello

    I need to add normalization to the image in the preprocess

    This is how it's being done in python (From here):

        parser.add_argument('--std', type=list, default=[0.229, 0.224, 0.225],
                            help='the std used to normalize your images')
        parser.add_argument('--mean', type=list, default=[0.485, 0.456, 0.406],
                            help='the mean used to normalize your images')
    
        normalize = transforms.Normalize(std=args.std,
                                         mean=args.mean)
    
        transformation = transforms.Compose([transforms.ToTensor()])
    
        man_normalize = transformation(man_resize)
    

    This is how it's being done in Android:

    @Override
      | protected void addPixelValue(int pixelValue) {
      | imgData.putFloat((((pixelValue >> 16) & 0xFF)/255f - IMAGE_MEAN[0]) / IMAGE_STD[0]);
      | imgData.putFloat((((pixelValue >> 8) & 0xFF)/255f - IMAGE_MEAN[1]) / IMAGE_STD[1]);
      | imgData.putFloat(((pixelValue & 0xFF)/255f - IMAGE_MEAN[2]) / IMAGE_STD[2]);
      | }
    

    How can I do similar thing in your Swift application?

    Thanks

    opened by yonatanbitton 2
  • Support pose matching feature

    Support pose matching feature

    Demo

    | Pose Capturing | Pose Matching | | ---- | ---- | | demo-pose-capturing | demo-pose-matching |

    PR Point

    • Add pose capturing and matching

    How to make the matching rate

    1. Vector based method

    1. Get the connected points (p1_1, p1_2) from captured points
    2. Get the connected points (p2_1, p2_2) from predicted points
    3. Exception handling (nil check, confidence check)
    4. Get two vector
    let vec1: CGPoint = p1_2 - p1_1
    let vec2: CGPoint = p2_2 - p2_1
    
    1. Calculate the angle with vec1, (0, 0), vec2: angle loss
    2. Sum all angle loss and divide by (numberOfLoss) * (π/2): loss rate
    3. Check the 6th's result is on 0.0 to 1.0 range.
    4. Flip the result
    let matchingRate = 1 - lossRate
    

    2. Angle based method

    Implemented on source code

    💪 enhancement 
    opened by tucan9389 0
  • Need some suggestion in library

    Need some suggestion in library

    Hello @tucan9389 @taehyen ,

    Thanks for creating wonderful library for pose detection. But I need to know that can we draw dots only selected part of body instead full body while full body visible in front of camera.

    Thanks and Regards

    opened by Deepak-kumar-varshney 2
  • Understanding performance test

    Understanding performance test

    Hello. Thanks for the amazing repository!

    I built the project and it works great.

    I am trying to understand the performance test. I would be glad if you can elaborate about what was measured.

    Looking at Measure.swift:

    func 🎬🤚() {
           🏷(for: index, with: "end")
           
           let beforeMeasurement = getBeforeMeasurment(for: index)
           let currentMeasurement = measurements[index]
           if let startTime = currentMeasurement["start"],
               let endInferenceTime = currentMeasurement["endInference"],
               let endTime = currentMeasurement["end"],
               let beforeStartTime = beforeMeasurement["start"] {
               delegate?.updateMeasure(inferenceTime: endInferenceTime - startTime,
                                       executionTime: endTime - startTime,
                                       fps: Int(1/(startTime - beforeStartTime)))
           }
           
       }
    

    startTime is the moment that the image is received. It is a pixelBuffer, (640x480) image. endInferenceTime is the moment when the inference was stopped, receiving a (14, 96, 96) heatmap from the CPM model. beforeStartTime is the start time of the previous frame. Why do we measure it?

    If so I understand what is:

    • inferenceTime: endInferenceTime - startTime - from pixelBuffer, (640x480) image to (14, 96, 96) heatmap .
    • executionTime: endTime - startTime - from pixelBuffer, (640x480), including post-process (convertToPredictedPoints, and moving average filter. BTW - what is this filter?)

    But I don't understand what is fps: Int(1/(startTime - beforeStartTime))) - why is the beforeStartTime relevant?

    To summarize, my questions are:

    1. Did I understand correctly the inferenceTime and executionTime?
    2. Why is the fps calculated with beforeStartTime?
    3. Why do you have moving average filter in the post-process code? Is it instead the gaussian_filter in the original CPM code?

    Thank you very much.

    opened by yonatanbitton 2
  • Minimal example for image inference

    Minimal example for image inference

    Hello

    I am trying to use other model and it gets complicated.

    I was wondering whether someone haev minimal example on how to run inference on existing image from memory? This way it will be simpler to understand how to adapt different model.

    Thanks for the repo!

    opened by yonatanbitton 3
  • Need Help with pose capturing and pose matching technique

    Need Help with pose capturing and pose matching technique

    hello @tucan9389 i'm flutter developer i don't understand swift language and i just want to know about how you captured the poses with only skeleton drawn and compared it with live feed i'm using different posenet moel here please guide me with this.

    Since this is not an issue so you can close this and please reply here email : [email protected]

    Thanks :)

    opened by rohitshirur007 2
The example project of inferencing Semantic Segementation using Core ML

SemanticSegmentation-CoreML This project is Object Segmentation on iOS with Core ML. If you are interested in iOS + Machine Learning, visit here you c

tucan9389 248 Dec 17, 2022
Real-time single person pose estimation for Android and iOS.

This repository currently implemented the CPM and Hourglass model using TensorFlow. Instead of normal convolution, inverted residuals (also known as M

null 953 Jan 3, 2023
The example of running Depth Prediction using Core ML

DepthPrediction-CoreML This project is Depth Prediction on iOS with Core ML. If you are interested in iOS + Machine Learning, visit here you can see v

tucan9389 113 Nov 17, 2022
Swift framework for document classification using a Core ML model.

DocumentClassifier Overview DocumentClassifier is a Swift framework for classifying documents into one of five categories (Business, Entertainment, Po

Todd Kramer 40 Nov 15, 2022
Photo Assessment using Core ML and Metal.

PhotoAssessment Photo Assessment (i.e. quality score) using Core ML and Metal. ?? Article 使用 Metal 和 Core ML 评价照片质量 Parallel Computation using MPS ??

杨萧玉 59 Dec 26, 2022
Classifying Images With Vision And Core ML

Classifying Images with Vision and Core ML Preprocess photos using the Vision framework and classify them with a Core ML model. Overview With the Core

Ivan Kolesov 2 Nov 15, 2022
iOS Core ML implementation of waifu2x

waifu2x on iOS Introduction This is a Core ML implementation of waifu2x. The target of this project is to run waifu2x models right on iOS devices even

Yi Xie 469 Jan 8, 2023
MXNet to Core ML - iOS sample app

Bring Machine Learning to iOS apps using Apache MXNet and Apple Core ML

Amazon Web Services - Labs 54 Nov 9, 2022
A demo for iOS machine learning framework : Core ML

CoreMLDemo A demo for iOS machine learning framework : Core ML Only Xcode9 and above are supported. Model Places205-GoogLeNet comes from [Apple Machin

null 32 Sep 16, 2022
This project is Text Recognition using Firebase built-in model on iOS

TextRecognition-MLKit This project is Text Recognition using Firebase built-in model on iOS. If you are interested in iOS + Machine Learning, visit he

tucan9389 80 Nov 17, 2022
TextDetection-CoreML - This project is Text Detection on iOS using Vision built-in model

This project is Text Detection on iOS using Vision built-in model. If you are interested in iOS + Machine Learning, visit here yo

tucan9389 61 Nov 17, 2022
Apple Developer Academy, Nano Challenge_2 Project

How Old Am I Key Features • Authors • Screenshots • Skills & Tech Stack • License ?? Project Title AI 나이측정 테스트, How Old Am I Key Features 얼굴 인식 선택된 이미

Jung Yunseong 2 Sep 14, 2022
Demo of using TensorFlow Lite on iOS

TensorFlowLiteiOS Demo of using TensorFlow Lite on iOS Use the image classification model mobilenet_quant_v1_224. This is an excerpt and arrangement o

MLBoy 4 Jan 27, 2022
Holistically-Nested Edge Detection (HED) using CoreML and Swift

HED-CoreML Holistically-Nested Edge Detection (HED) using CoreML and Swift This is the repo for tutorial, that contains an example application that ru

Andrey Volodin 101 Dec 25, 2022
The MobileNet neural network using Apple's new CoreML framework

MobileNet with CoreML This is the MobileNet neural network architecture from the paper MobileNets: Efficient Convolutional Neural Networks for Mobile

Matthijs Hollemans 698 Dec 4, 2022
golf pose detection Analyzing golf pose with MLKit pose detection

golf-pose golf pose detection Analyzing golf pose with MLKit pose detection (PHI NETWORKS, 창의적통합설계, 2021) Standard & Frameworks iOS platform (Swift, R

Donghyun Lee 1 Jan 24, 2022
The example project of inferencing Semantic Segementation using Core ML

SemanticSegmentation-CoreML This project is Object Segmentation on iOS with Core ML. If you are interested in iOS + Machine Learning, visit here you c

tucan9389 248 Dec 17, 2022
Real-time single person pose estimation for Android and iOS.

This repository currently implemented the CPM and Hourglass model using TensorFlow. Instead of normal convolution, inverted residuals (also known as M

null 953 Jan 3, 2023
Pose Estimation on iOS with TensorFlow Lite

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

tucan9389 125 Nov 28, 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