In [1]:
%matplotlib inline
%pylab inline
In [2]:
repeat = 3
In [3]:
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 = '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 [6]:
from menpo.visualize import visualize_images
visualize_images(test_images)
In [ ]:
from alabortijcv2015.aam.algorithm import SIC
algorithm_cls = SIC
sampling_step = 1
sampling_mask = np.require(np.zeros((17, 17)), dtype=np.bool)
sampling_mask[::sampling_step, ::sampling_step] = True
n_shape = [3, 12]
n_appearance = [50, 100]
noise_std = [None, 0, 0.02, 0.04, 0.06]
max_iters = 20
prior = False
In [8]:
from alabortijcv2015.utils import pickle_load
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_global_pwa_int')
In [9]:
from alabortijcv2015.aam import StandardAAMFitter
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [10]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
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
print n
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'FastSIC', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp1_global_pwa_int_fastsic' + str(n))
In [11]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [12]:
from alabortijcv2015.utils import pickle_load
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_global_tps_int')
In [13]:
from alabortijcv2015.aam import StandardAAMFitter
from alabortijcv2015.aam.algorithm import FastSIC_GN
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [14]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
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
print n
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'FastSIC', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp1_global_tps_int_fastsic' + str(n))
In [15]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [16]:
from alabortijcv2015.utils import pickle_load
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_patch_int')
In [17]:
from alabortijcv2015.aam import StandardAAMFitter
from alabortijcv2015.aam.algorithm import FastSIC_GN
fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [18]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
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
print n
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'FastSIC', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp1_patch_int_fastsic' + str(n))
In [19]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [20]:
from alabortijcv2015.utils import pickle_load
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_linear_global_pwa_int')
In [21]:
from alabortijcv2015.aam import LinearAAMFitter
from alabortijcv2015.aam.algorithm import FastSIC_GN
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [22]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
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
print n
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'FastSIC', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp1_linear_global_pwa_int_fastsic' + str(n))
In [23]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [24]:
from alabortijcv2015.utils import pickle_load
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_linear_global_tps_int')
In [25]:
from alabortijcv2015.aam import LinearAAMFitter
from alabortijcv2015.aam.algorithm import FastSIC_GN
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [26]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
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
print n
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'FastSIC', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp1_linear_global_tps_int_fastsic' + str(n))
In [27]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [28]:
from alabortijcv2015.utils import pickle_load
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_linear_patch_int')
In [29]:
from alabortijcv2015.aam import LinearAAMFitter
from alabortijcv2015.aam.algorithm import FastSIC_GN
fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_step=sampling_step)
In [30]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
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
print n
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'FastSIC', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp1_linear_patch_int_fastsic' + str(n))
In [31]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [32]:
from alabortijcv2015.utils import pickle_load
aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_parts_int')
In [33]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import FastSIC_GN
fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
n_appearance=n_appearance, sampling_mask= sampling_mask)
In [34]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
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
print n
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'FastSIC', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/ijcv2015/exp1_parts_int_fastsic' + str(n))
In [35]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)