In [1]:
%matplotlib inline
%pylab inline
In [2]:
repeat = 1
In [3]:
import menpo.io as mio
from menpo.landmark import labeller, lfpw_face
from menpofast.utils import convert_from_menpo
path = '/data/'
group = 'lfpw_face'
test_images = []
for i in mio.import_images(path + 'PhD/DataBases/faces/cofw/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(1, group='PTS')
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 alabortcvpr2015.utils import pickle_load
unified = pickle_load(path + 'PhD/Models/unified_cofw_fast_dsift')
In [6]:
sampling_mask = np.require(np.zeros(unified.parts_shape), dtype=np.bool)
sampling_mask[3::7, 3::7] = True
imshow(sampling_mask)
Out[6]:
In [ ]:
from alabortcvpr2015.unified import PartsUnifiedFitter, AICRLMS
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
fitter = PartsUnifiedFitter(unified, algorithm_cls=AICRLMS, n_shape=[3, 12],
n_appearance=[25, 50], sampling_mask=sampling_mask)
fitter_results = []
for seed in xrange(repeat):
np.random.seed(seed=seed)
for j, i in enumerate(test_images[:100]):
gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=0.05)
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=False, a=0.9)
fitter_results.append(fr)
fr.downscale = 0.5
print 'Image: ', j
print fr
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'AICRLMS', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/unified_aicrlms_cofw_fast_dsift')
In [15]:
np.mean([fr.final_error(error_type='rmse') for fr in fitter_results])
Out[15]:
In [9]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [13]:
sampling_mask = np.require(np.zeros(unified.parts_shape), dtype=np.bool)
sampling_mask[3::7, 3::7] = True
imshow(sampling_mask)
Out[13]:
In [14]:
from alabortcvpr2015.unified import PartsUnifiedFitter, PICRLMS
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult
fitter = PartsUnifiedFitter(unified, algorithm_cls=PICRLMS, n_shape=[3, 12],
n_appearance=[25, 50], sampling_mask=sampling_mask)
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
s = fitter.perturb_shape(gt_s, noise_std=0.05)
fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=False)
fitter_results.append(fr)
fr.downscale = 0.5
print 'Image: ', j
print fr
results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'PICRLMS', fr.gt_shape)
for fr in fitter_results]
pickle_dump(results, path + 'PhD/Results/unified_picrlms_cofw_fast_dsift')
In [ ]:
np.mean([fr.final_error(error_type='rmse') for fr in fitter_results])
In [11]:
from menpofit.visualize import visualize_fitting_results
visualize_fitting_results(fitter_results)
In [ ]: