[s1d][week 20]pytorch landmark和pycpd
===
# 零、dlib、pytorch landmark和比較模型
* dlib
* ![](https://www.pyimagesearch.com/wp-content/uploads/2017/04/facial_landmarks_68markup-768x619.jpg)
* pytorch
* 來源[face-alignment-issue](https://github.com/1adrianb/face-alignment/issues/120)
* ![](https://user-images.githubusercontent.com/174475/58765561-168cf280-8529-11e9-98fe-8fc9e2e07f0c.png)
* 比較
* ![](https://i.imgur.com/0PeqCtW.png)
___
# 一、pycpd的rotation和translation
> 來自[PyCPD: Tutorial on the Coherent Point Drift Algorithm](http://siavashk.github.io/2017/05/14/coherent-point-drift/)
>
* 假定一個實際未知參數$\{\theta=30^。,t=(0.2,0.2)\}$則
```python=
import numpy as np
# transformation parameters
theta = np.pi/6.0
t = np.array([[0.2], [0.2]])
# rotation matrix
R = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
X = np.array([[0, 0, 10], [0, 10, 0]])
Y = np.dot(R, X) + t
xLabels = ["X1", "X2", "X3"]
yLabels = ["Y1", "Y2", "Y3"]
```
* 儘管官方的範例是這樣寫,但實際去看程式碼發現順序不對(rigid_registration.py)
```python=36
def transform_point_cloud(self, Y=None):
if Y is None:
self.TY = self.s * np.dot(self.Y, self.R) + self.t
return
else:
return self.s * np.dot(Y, self.R) + self.t
```
:::success
所以得到的Rotation可以這樣寫,都可以成功反推
$scale*(Y\cdot Rotation)+Translation=scale*(Rotation^T\cdot Y^T)^T+Translation$
代表我們所獲得的`Rotation Matrix`必須要`Transpose`,與`solvePnP`得到的結果不同
:::
___
# 二、pytorch landmark
> 使用人練臉 :: 範例人臉的全部平均
### 1、正規到相同大小
* 期望有不同的`Error(min distance error)`
* 選擇圖片
* ![](https://i.imgur.com/hvAoiCT.png)
* 2D模型預測
* ![](https://i.imgur.com/lIxbKsB.png)
* 3D模型預測
* ![](https://i.imgur.com/plZaIPh.png)
* scale幾乎都在`2.3`-`2.8`左右
* ERROR最大
* ![](https://i.imgur.com/5X0zvuO.png)
* ERROR最小
* ![](https://i.imgur.com/ZWEUFWb.png)
### 2、不同大小人臉
* 主要看scale是否隨著人臉大小不同變化
* 選擇圖片
* ![](https://i.imgur.com/A5sqaFq.png)
* 3D模型預測
* ![](https://i.imgur.com/rKHOXYF.png)
* scale最小(1.0431945171542256)
* ![](https://i.imgur.com/ZwxFK2b.png)
* scale最大(2.722211524185319)
* ![](https://i.imgur.com/Hjacz5O.png)
:::success
可以確定,不同人臉會有不同的模型,雖然用min distance error可能不容易看出來,但可以直接看圖片。在不同大小人臉之下,`pycpd`可以找到適合的scale
:::
___
# pycpd過程出的問題
* 實際使用時,出現一個情況,當source和target的角度大約相差180度時,pycpd不會有旋轉的迭代,可能的原因是當旋轉的迭代會使ERROR值提升(猜測)
* 而教授給的模型恰好是偵測結果對Z軸旋轉180度
* [不旋轉(0度)](http://johnny88850tw.asuscomm.com/hackmd/meeting/s1d_week20/degree_0.gif)
* [旋轉90度](http://johnny88850tw.asuscomm.com/hackmd/meeting/s1d_week20/degree_90.gif)
* [旋轉180度](http://johnny88850tw.asuscomm.com/hackmd/meeting/s1d_week20/degree_180.gif)