In [1]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib

Load training data


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'

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)


- Loading 811 assets: [====================] 100%

In [ ]:
for i in mio.import_images(path + 'PhD/DataBases/faces/helen/trainset/',
                           verbose=True, max_images=500):
    
    # 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 [4]:
from menpo.visualize import visualize_images

visualize_images(training_images)


Unified HDMs and PBDMs

Build


In [5]:
from menpofast.feature import no_op, fast_dsift
from alabortcvpr2015.unified import GlobalUnifiedBuilder

unified = GlobalUnifiedBuilder(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)


- Building models
  - Level 0: Done
  - Level 1: Done

In [6]:
unified.parts_filters()[0][18].view()


Out[6]:
<menpo.visualize.viewmatplotlib.MatplotlibImageSubplotsViewer2d at 0x7f6ac7d45ed0>

Save


In [9]:
from alabortcvpr2015.utils import pickle_dump

pickle_dump(unified, path + 'PhD/Models/global_unified_lfpw_fast_dsift')

In [ ]: