13. PCMをヒートマップで表示
public func openPoseHeatMapTest(){
let model = MobileOpenPose()
let uiImage = UIImage(named: "runner.png")!
let loop = Array(0..<19)
if let pixelBuffer = uiImage.pixelBuffer(width: 368,height: 368) {
if let prediction = try? model.prediction(image: pixelBuffer) {
heatMapView(prediction.net_output,loop: loop)
}
}
}
画像を読み込み、CVPixelBufferに変換
入力の画像からCoreMLで推論
CoreMLの推論結果(行列)を表示に渡す
CoreMLの処理への組み込みは数行
先程のモデル
14. func heatMapView(_ p : MLMultiArray, loop: Array<Int>){
// MultiArray (Double 57 x 46 x 46)
let shape = [p.shape[1],p.shape[2]]
let width = p.shape[1].intValue , height = p.shape[2].intValue
let m = try! MLMultiArray(shape: shape, dataType: .double)
for j in loop {
let n = j * m.count
for i in 0..<m.count {
m[i] = p[i+n]
}
let img = UIImageView(image: m.image(offset: 0, scale: 255))
img.frame = CGRect(
origin: CGPoint(x: width*zoom*(j%turn), y:
height*zoom*Int(j/turn)),
size: CGSize(width: width * zoom, height: height * zoom)
)
self.view.addSubview(img)
}
}
結果の行列: 57の内PCMが19、PAFが36
46x46のブロックで初期化
46x46の行列(中身は浮動小数点)を
0~255の範囲に変換し、ヒートマップを生成
21. References
• Joint Training of a Convolutional Network and a Graphical Model
for Human Pose Estimation
• https://arxiv.org/abs/1406.2984
• OpenPose
• http://github.com/CMU-Perceptual-Computing-Lab/openpose
• Realtime Multi-Person 2D Pose Estimation using Part Affinity
Fields
• https://arxiv.org/abs/1611.08050
• tf-pose-estimation
• https://github.com/ildoonet/tf-pose-estimation
• CoreMLHelpers
• https://github.com/hollance/CoreMLHelpers