使用BIWI人腦姿態(tài)數(shù)據(jù)集來回歸人腦中心位置猾骡。
有請人工智能四大天王寸痢。
- 數(shù)據(jù)
- 模型
- 損失
- 算法
下面分別介紹fastai解決BIWI的套路蚊锹。
1 數(shù)據(jù)
數(shù)據(jù)集的下載地址BIWI head pose侈询。
當(dāng)然數(shù)據(jù)集也可以直接使用python下載
%reload_ext autoreload
%aureload 2
%matplotlib inline
from fastai.visoion import *
path = untar_data(URLs.BIWI_HEAD_POSE)
數(shù)據(jù)注意坐標(biāo)變換妻献,rgb.cal中包含中心位置轉(zhuǎn)換的坐標(biāo)值贪庙。
每一個單獨的文件夾下獨有一個rgb.cal
蜘犁。
cal = np.genfromtxt(path/'01'/'rgb.cal', skip_footer=6)
為了由數(shù)據(jù)集中的姿態(tài)數(shù)據(jù)得到人頭的中心位置,腳本做了如下變換
def convert_biwi(coords):
c1 = coords[0] * cal[0][0]/coords[2] + cal[0][2]
c2 = coords[1] * cal[1][1]/coords[2] + cal[1][2]
return tensor([c2,c1])
def get_ctr(f):
ctr = np.genfromtxt(img2txt_name(f), skip_header=3)
return convert_biwi(ctr)
def get_ip(img,pts): return ImagePoints(FlowField(img.size, pts), scale=True)
其中get_ctr(f)
從圖片文件名止邮,得到圖片中人臉的中心位置坐標(biāo)这橙。
數(shù)據(jù)加載使用PointItemList
data = (PointsItemList.from_folder(path)
.split_by_valid_func(lambda o: o.parent.name=='13')
.label_from_func(get_ctr)
.transform(get_transforms(), tfm_y=True, size=(120,160))
.databunch().normalize(imagenet_stats)
)
這里簡單分析下上面的數(shù)據(jù)加載代碼奏窑。使用了PointsItemList的from_folder來加載數(shù)據(jù),直接從文件夾中提取數(shù)據(jù)屈扎。然后將文件夾名為13的文件夾下的數(shù)據(jù)作為驗證集數(shù)據(jù)埃唯。標(biāo)簽使用get_ctr函數(shù)來從txt文件中讀取人臉中心坐標(biāo),數(shù)據(jù)增強需要設(shè)置tfm_y=True
鹰晨,因為原始圖像變換了墨叛,坐標(biāo)也要跟這邊,不然不在人臉中心位置了模蜡。后面的databunch和normalize都是常規(guī)操作了漠趁。
圖1 部分訓(xùn)練數(shù)據(jù),注意人臉中心紅點
2
圖2 識別結(jié)果