In [1]:
%matplotlib inline
%pylab inline
In [2]:
import menpo.io as mio
from menpo.landmark import labeller, ibug_face_49
from menpofast.utils import convert_from_menpo
path = '/data/'
group = 'ibug_face_49'
db = 'afw'
test_images = []
for i in mio.import_images(path + 'PhD/DataBases/faces/' + db,
verbose=True, max_images=1):
# convert the image from menpo Image to menpofast Image (channels at front)
i = convert_from_menpo(i)
labeller(i, 'PTS', eval(group))
i.crop_to_landmarks_proportion_inplace(0.5, group='PTS')
i = i.rescale_landmarks_to_diagonal_range(150, group=group)
if i.n_channels == 3:
i = i.as_greyscale(mode='average')
test_images.append(i)
In [3]:
from menpofast.feature import no_op, fast_dsift
from alabortijcv2015.utils import pickle_load
aam_type = 'PartsAAM'
features = fast_dsift
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_' + aam_type + '_' + features.__name__ )
In [4]:
from alabortijcv2015.aam.algorithm import SIC
algorithm_cls = SIC
sampling_step = 7
sampling_mask = np.require(np.zeros((17, 17)), dtype=np.bool)
sampling_mask[1::sampling_step, 1::sampling_step] = True
n_shape = [3, 12]
n_appearance = [25, 50]
noise_std = 0.04
max_iters = 20
prior = False
imshow(sampling_mask)
Out[4]:
In [5]:
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import SIC
algorithm_cls = SIC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [6]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SICN
algorithm_cls = SICN
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [7]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SFC
algorithm_cls = SFC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [8]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SFCN
algorithm_cls = SFCN
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [9]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SSC
algorithm_cls = SSC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [92]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SBC
algorithm_cls = SBC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [94]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AIC
algorithm_cls = AIC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [93]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AICN
algorithm_cls = AICN
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [77]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AFC
algorithm_cls = AFC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [78]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AFCN
algorithm_cls = AFCN
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [95]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import ASC
algorithm_cls = ASC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [98]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import ABC
algorithm_cls = ABC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [59]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BIC
algorithm_cls = BIC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [60]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BICN
algorithm_cls = BICN
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [61]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BFC
algorithm_cls = BFC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [64]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BFCN
algorithm_cls = BFCN
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [99]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BSC
algorithm_cls = BSC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
In [100]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BBC
algorithm_cls = BBC
if aam_type is ('GlobalAAM' or 'PatchAAM'):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)
% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)