In [1]:
%matplotlib inline
%pylab inline
In [2]:
repeat = 3
In [3]:
import menpo.io as mio
from menpo.landmark import labeller, ibug_face_66
from menpofast.utils import convert_from_menpo
path = '/data/'
group = 'ibug_face_66'
db = 'lfpw'
test_images = []
for i in mio.import_images(path + 'PhD/DataBases/faces/' + db + '/testset',
verbose=True, max_images=None):
# 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 [4]:
from menpo.visualize import visualize_images
visualize_images(test_images)
In [5]:
from menpofast.feature import no_op, fast_dsift
from alabortijcv2015.utils import pickle_load
aam_type = 'GlobalAAM_PWA'
features_type = fast_dsift.__name__
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_' + aam_type + '_' + features_type)
In [6]:
sampling_step = 2
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 = [100, 100]
noise_std = [0.04]
max_iters = 40
prior = False
imshow(sampling_mask)
Out[6]:
In [7]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import SIC
algorithm_cls = SIC
if isinstance(aam, PartsAAM):
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [8]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
for n in noise_std:
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images):
gt_s = i.landmarks[group].lms
if n is not None:
s = fitter.perturb_shape(gt_s, noise_std=n)
else:
s = gt_s
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
fitter_results.append(fr)
fr.downscale = 0.5
#print 'Image: ', j
#print fr
if n is None or 0:
break
print n
alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp2_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [9]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import SFC
algorithm_cls = SFC
if isinstance(aam, PartsAAM):
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [10]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
for n in noise_std:
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images):
gt_s = i.landmarks[group].lms
if n is not None:
s = fitter.perturb_shape(gt_s, noise_std=n)
else:
s = gt_s
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
fitter_results.append(fr)
fr.downscale = 0.5
#print 'Image: ', j
#print fr
if n is None or 0:
break
print n
alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp2_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [11]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import AIC
algorithm_cls = AIC
if isinstance(aam, PartsAAM):
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [12]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
for n in noise_std:
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images):
gt_s = i.landmarks[group].lms
if n is not None:
s = fitter.perturb_shape(gt_s, noise_std=n)
else:
s = gt_s
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
fitter_results.append(fr)
fr.downscale = 0.5
#print 'Image: ', j
#print fr
if n is None or 0:
break
print n
alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp2_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [13]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import AFC
algorithm_cls = AFC
if isinstance(aam, PartsAAM):
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [14]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
for n in noise_std:
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images):
gt_s = i.landmarks[group].lms
if n is not None:
s = fitter.perturb_shape(gt_s, noise_std=n)
else:
s = gt_s
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
fitter_results.append(fr)
fr.downscale = 0.5
#print 'Image: ', j
#print fr
if n is None or 0:
break
print n
alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp2_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [15]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import BIC
algorithm_cls = BIC
if isinstance(aam, PartsAAM):
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [16]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
for n in noise_std:
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images):
gt_s = i.landmarks[group].lms
if n is not None:
s = fitter.perturb_shape(gt_s, noise_std=n)
else:
s = gt_s
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
fitter_results.append(fr)
fr.downscale = 0.5
#print 'Image: ', j
#print fr
if n is None or 0:
break
print n
alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp2_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [17]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import BFC
algorithm_cls = BFC
if isinstance(aam, PartsAAM):
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [18]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
for n in noise_std:
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images):
gt_s = i.landmarks[group].lms
if n is not None:
s = fitter.perturb_shape(gt_s, noise_std=n)
else:
s = gt_s
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
fitter_results.append(fr)
fr.downscale = 0.5
#print 'Image: ', j
#print fr
if n is None or 0:
break
print n
alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp2_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [19]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import PIC
algorithm_cls = PIC
if isinstance(aam, PartsAAM):
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM):
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
else:
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [20]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
for n in noise_std:
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images):
gt_s = i.landmarks[group].lms
if n is not None:
s = fitter.perturb_shape(gt_s, noise_std=n)
else:
s = gt_s
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
fitter_results.append(fr)
fr.downscale = 0.5
#print 'Image: ', j
#print fr
if n is None or 0:
break
print n
alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp2_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)