In [ ]:
%matplotlib inline
%pylab inline

Load training data


In [ ]:
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'

training_images = []
for i in mio.import_images(path + 'PhD/DataBases/faces/lfpw/trainset/',
                           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(200, group=group)
    
    if i.n_channels == 3:
        i = i.as_greyscale(mode='average')
    training_images.append(i)

In [ ]:
for i in mio.import_images(path + 'PhD/DataBases/faces/helen/trainset/',
                           verbose=True, max_images=2000):
    
    # 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(200, group=group)
    
    if i.n_channels == 3:
        i = i.as_greyscale(mode='average')
    training_images.append(i)

In [ ]:
for i in mio.import_images(path + 'PhD/DataBases/faces/ibug/',
                           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(200, group=group)
    
    if i.n_channels == 3:
        i = i.as_greyscale(mode='average')
    training_images.append(i)

In [ ]:
from menpo.visualize import visualize_images

visualize_images(training_images)

Unified HDMs and PBDMs

Build and Save


In [ ]:
from menpofast.feature import no_op, fast_dsift
from alabortcvpr2015.unified import PartsUnifiedBuilder
from alabortcvpr2015.utils import pickle_dump

#n_images = [pow(2,i) for i in range(5, 12)]

#for j, limit in enumerate(n_images):

#    unified = PartsUnifiedBuilder(parts_shape=(17, 17),
#                                  features=fast_dsift,
#                                  diagonal=100,
#                                  normalize_parts=False,
#                                  covariance=3,
#                                  scales=(1, .5),
#                                  max_shape_components=25,
#                                  max_appearance_components=500).build(training_images[:limit],
#                                                                       group=group,
#                                                                       verbose=True)

#    pickle_dump(unified, path + 'PhD/Models/unified_lfpw_fast_dsift' + str(j))

#    del unified
    
unified = PartsUnifiedBuilder(parts_shape=(17, 17),
                              features=fast_dsift,
                              diagonal=100,
                              normalize_parts=False,
                              covariance=3,
                              scales=(1, .5),
                              max_shape_components=25,
                              max_appearance_components=500).build(training_images,
                                                                   group=group,
                                                                   verbose=True)

pickle_dump(unified, path + 'PhD/Models/unified_lfpw_fast_dsift' + str(7))