Skip to content

Commit

Permalink
Update tests for new LJSON change
Browse files Browse the repository at this point in the history
lenna is now an ljson and therefore all the tests that assumed
every image was landmarked with PTS started failing.

Also, unpin menpofit from menpo 0.4.0a3 and let if find the master
branch so that the tests have a chance of passing.
  • Loading branch information
patricksnape committed Jan 28, 2015
1 parent 76f2083 commit 7c4cae5
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install:
- wget https://raw.githubusercontent.com/jabooth/condaci/v0.2.0/condaci.py -O condaci.py
- python condaci.py setup $PYTHON_VERSION --channel $BINSTAR_USER
- export PATH=$HOME/miniconda/bin:$PATH
#- conda config --add channels $BINSTAR_USER/channel/master
- conda config --add channels $BINSTAR_USER/channel/master

script:
- python condaci.py auto ./conda --binstaruser $BINSTAR_USER --binstarkey $BINSTAR_KEY
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ platform:
init:
- ps: Start-FileDownload 'https://raw.githubusercontent.com/jabooth/condaci/v0.2.0/condaci.py' C:\\condaci.py; echo "Done"
- cmd: python C:\\condaci.py setup %PYTHON_VERSION% --channel %BINSTAR_USER%
#- cmd: C:\\Miniconda\\Scripts\\conda config --add channels %BINSTAR_USER%/channel/master
- cmd: C:\\Miniconda\\Scripts\\conda config --add channels %BINSTAR_USER%/channel/master

install:
- cmd: C:\\Miniconda\\python C:\\condaci.py auto ./conda --binstaruser %BINSTAR_USER% --binstarkey %BINSTAR_KEY%
Expand Down
2 changes: 1 addition & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ requirements:

run:
- python
- menpo 0.4.0a3
- menpo
- numpy 1.9.0
- scipy 0.14.0
- scikit-learn 0.15.2
Expand Down
40 changes: 18 additions & 22 deletions menpofit/test/aam_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from menpo.feature import sparse_hog, igo, lbp, no_op

import menpo.io as mio
from menpo.landmark import labeller, ibug_face_68_trimesh
from menpo.landmark import ibug_face_68_trimesh
from menpofit.aam import AAMBuilder, PatchBasedAAMBuilder


Expand All @@ -19,23 +19,23 @@
for i in range(4):
im = mio.import_builtin_asset(filenames[i])
im.crop_to_landmarks_proportion_inplace(0.1)
labeller(im, 'PTS', ibug_face_68_trimesh)
if im.n_channels == 3:
im = im.as_greyscale(mode='luminosity')
training.append(im)

# build aams
template_trilist_image = training[0].landmarks[None]
trilist = ibug_face_68_trimesh(template_trilist_image)[1].lms.trilist
aam1 = AAMBuilder(features=[igo, sparse_hog, no_op],
transform=PiecewiseAffine,
trilist=training[0].landmarks['ibug_face_68_trimesh'].
lms.trilist,
trilist=trilist,
normalization_diagonal=150,
n_levels=3,
downscale=2,
scaled_shape_models=False,
max_shape_components=[1, 2, 3],
max_appearance_components=[3, 3, 3],
boundary=3).build(training, group='PTS')
boundary=3).build(training)

aam2 = AAMBuilder(features=[no_op, no_op],
transform=ThinPlateSplines,
Expand All @@ -46,7 +46,7 @@
scaled_shape_models=True,
max_shape_components=None,
max_appearance_components=1,
boundary=0).build(training, group='PTS')
boundary=0).build(training)

aam3 = AAMBuilder(features=igo,
transform=ThinPlateSplines,
Expand All @@ -57,7 +57,7 @@
scaled_shape_models=True,
max_shape_components=[2],
max_appearance_components=10,
boundary=2).build(training, group='PTS')
boundary=2).build(training)

aam4 = PatchBasedAAMBuilder(features=lbp,
patch_shape=(10, 13),
Expand All @@ -67,55 +67,51 @@
scaled_shape_models=True,
max_shape_components=1,
max_appearance_components=None,
boundary=2).build(training, group='PTS')
boundary=2).build(training)


@raises(ValueError)
def test_features_exception():
AAMBuilder(features=[igo, sparse_hog]).build(training, group='PTS')
AAMBuilder(features=[igo, sparse_hog]).build(training)


@raises(ValueError)
def test_n_levels_exception():
AAMBuilder(n_levels=0).build(training, group='PTS')
AAMBuilder(n_levels=0).build(training)


@raises(ValueError)
def test_downscale_exception():
aam = AAMBuilder(downscale=1).build(training,
group='PTS')
aam = AAMBuilder(downscale=1).build(training)
assert (aam.downscale == 1)
AAMBuilder(downscale=0).build(training, group='PTS')
AAMBuilder(downscale=0).build(training)


@raises(ValueError)
def test_normalization_diagonal_exception():
aam = AAMBuilder(normalization_diagonal=100).build(training,
group='PTS')
aam = AAMBuilder(normalization_diagonal=100).build(training)
assert (aam.appearance_models[0].n_features == 382)
AAMBuilder(normalization_diagonal=10).build(training, group='PTS')
AAMBuilder(normalization_diagonal=10).build(training)


@raises(ValueError)
def test_max_shape_components_exception():
AAMBuilder(max_shape_components=[1, 0.2, 'a']).build(training,
group='PTS')
AAMBuilder(max_shape_components=[1, 0.2, 'a']).build(training)


@raises(ValueError)
def test_max_appearance_components_exception():
AAMBuilder(max_appearance_components=[1, 2]).build(training,
group='PTS')
AAMBuilder(max_appearance_components=[1, 2]).build(training)


@raises(ValueError)
def test_boundary_exception():
AAMBuilder(boundary=-1).build(training, group='PTS')
AAMBuilder(boundary=-1).build(training)


@patch('sys.stdout', new_callable=StringIO)
def test_verbose_mock(mock_stdout):
AAMBuilder().build(training, group='PTS', verbose=True)
AAMBuilder().build(training, verbose=True)


@patch('sys.stdout', new_callable=StringIO)
Expand Down
19 changes: 9 additions & 10 deletions menpofit/test/aam_fitter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import menpo.io as mio
from menpo.shape.pointcloud import PointCloud
from menpo.landmark import labeller, ibug_face_68_trimesh
from menpo.landmark import ibug_face_68_trimesh
from menpofit.aam import AAMBuilder, LucasKanadeAAMFitter
from menpofit.lucaskanade.appearance import (
AlternatingForwardAdditive, AlternatingForwardCompositional,
Expand Down Expand Up @@ -307,35 +307,34 @@
for i in range(4):
im = mio.import_builtin_asset(filenames[i])
im.crop_to_landmarks_proportion_inplace(0.1)
labeller(im, 'PTS', ibug_face_68_trimesh)
if im.n_channels == 3:
im = im.as_greyscale(mode='luminosity')
training_images.append(im)

# build aam
template_trilist_image = training_images[0].landmarks[None]
trilist = ibug_face_68_trimesh(template_trilist_image)[1].lms.trilist
aam = AAMBuilder(features=igo,
transform=DifferentiablePiecewiseAffine,
trilist=training_images[0].landmarks['ibug_face_68_trimesh'].
lms.trilist,
trilist=trilist,
normalization_diagonal=150,
n_levels=3,
downscale=2,
scaled_shape_models=True,
max_shape_components=[1, 2, 3],
max_appearance_components=[3, 2, 1],
boundary=3).build(training_images, group='PTS')
boundary=3).build(training_images)

aam2 = AAMBuilder(features=igo,
transform=DifferentiablePiecewiseAffine,
trilist=training_images[0].landmarks['ibug_face_68_trimesh'].
lms.trilist,
trilist=trilist,
normalization_diagonal=150,
n_levels=1,
downscale=2,
scaled_shape_models=True,
max_shape_components=[1],
max_appearance_components=[1],
boundary=3).build(training_images, group='PTS')
boundary=3).build(training_images)


def test_aam():
Expand Down Expand Up @@ -368,7 +367,7 @@ def test_n_appearance_exception():

def test_pertrurb_shape():
fitter = LucasKanadeAAMFitter(aam)
s = fitter.perturb_shape(training_images[0].landmarks['PTS'].lms,
s = fitter.perturb_shape(training_images[0].landmarks[None].lms,
noise_std=0.08, rotation=False)
assert (s.n_dims == 2)
assert (s.n_landmark_groups == 0)
Expand Down Expand Up @@ -410,7 +409,7 @@ def aam_helper(aam, algorithm, im_number, max_iters, initial_error,
fitter = LucasKanadeAAMFitter(aam, algorithm=algorithm)
fitting_result = fitter.fit(
training_images[im_number], initial_shape[im_number],
gt_shape=training_images[im_number].landmarks['PTS'].lms,
gt_shape=training_images[im_number].landmarks[None].lms,
max_iters=max_iters)
assert_allclose(
np.around(fitting_result.initial_error(error_type=error_type), 5),
Expand Down
25 changes: 11 additions & 14 deletions menpofit/test/atm_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
im = mio.import_builtin_asset(filenames[i])
if im.n_channels == 3:
im = im.as_greyscale(mode='luminosity')
training.append(im.landmarks['PTS']['all'])
training.append(im.landmarks[None].lms)
templates.append(im)

# build atms
Expand All @@ -31,7 +31,7 @@
downscale=2,
scaled_shape_models=False,
max_shape_components=[1, 2, 3],
boundary=3).build(training, templates[0], group='PTS')
boundary=3).build(training, templates[0])

atm2 = ATMBuilder(features=[no_op, no_op],
transform=ThinPlateSplines,
Expand All @@ -41,7 +41,7 @@
downscale=1.2,
scaled_shape_models=True,
max_shape_components=None,
boundary=0).build(training, templates[1], group='PTS')
boundary=0).build(training, templates[1])

atm3 = ATMBuilder(features=igo,
transform=ThinPlateSplines,
Expand All @@ -51,7 +51,7 @@
downscale=3,
scaled_shape_models=True,
max_shape_components=[2],
boundary=2).build(training, templates[2], group='PTS')
boundary=2).build(training, templates[2])

atm4 = PatchBasedATMBuilder(features=lbp,
patch_shape=(10, 13),
Expand All @@ -60,8 +60,7 @@
downscale=1.2,
scaled_shape_models=True,
max_shape_components=1,
boundary=2).build(training, templates[3],
group='PTS')
boundary=2).build(training, templates[3])


@raises(ValueError)
Expand All @@ -76,23 +75,21 @@ def test_n_levels_exception():

@raises(ValueError)
def test_downscale_exception():
atm = ATMBuilder(downscale=1).build(training, templates[2], group='PTS')
atm = ATMBuilder(downscale=1).build(training, templates[2])
assert (atm.downscale == 1)
ATMBuilder(downscale=0).build(training, templates[2], group='PTS')
ATMBuilder(downscale=0).build(training, templates[2])


@raises(ValueError)
def test_normalization_diagonal_exception():
atm = ATMBuilder(normalization_diagonal=100).build(training, templates[3],
group='PTS')
atm = ATMBuilder(normalization_diagonal=100).build(training, templates[3])
assert (atm.warped_templates[0].n_true_pixels() == 1246)
ATMBuilder(normalization_diagonal=10).build(training, templates[3])


@raises(ValueError)
def test_max_shape_components_exception():
ATMBuilder(max_shape_components=[1, 0.2, 'a']).build(training, templates[0],
group='PTS')
ATMBuilder(max_shape_components=[1, 0.2, 'a']).build(training, templates[0])


@raises(ValueError)
Expand All @@ -102,12 +99,12 @@ def test_max_shape_components_exception_2():

@raises(ValueError)
def test_boundary_exception():
ATMBuilder(boundary=-1).build(training, templates[1], group='PTS')
ATMBuilder(boundary=-1).build(training, templates[1])


@patch('sys.stdout', new_callable=StringIO)
def test_verbose_mock(mock_stdout):
ATMBuilder().build(training, templates[2], group='PTS', verbose=True)
ATMBuilder().build(training, templates[2], verbose=True)


@patch('sys.stdout', new_callable=StringIO)
Expand Down
18 changes: 9 additions & 9 deletions menpofit/test/atm_fitter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from menpo.shape.pointcloud import PointCloud
from menpofit.atm import ATMBuilder, LucasKanadeATMFitter
from menpofit.lucaskanade.image import (ImageInverseCompositional,
ImageForwardAdditive,
ImageForwardCompositional)
ImageForwardAdditive,
ImageForwardCompositional)


initial_shape = []
Expand Down Expand Up @@ -302,7 +302,7 @@
im.crop_to_landmarks_proportion_inplace(0.1)
if im.n_channels == 3:
im = im.as_greyscale(mode='luminosity')
training_shapes.append(im.landmarks['PTS']['all'])
training_shapes.append(im.landmarks[None].lms)
templates.append(im)


Expand All @@ -314,7 +314,7 @@
downscale=2,
scaled_shape_models=True,
max_shape_components=[1, 2, 3],
boundary=3).build(training_shapes, templates[0], group='PTS')
boundary=3).build(training_shapes, templates[0])

atm2 = ATMBuilder(features=igo,
transform=DifferentiablePiecewiseAffine,
Expand All @@ -323,7 +323,7 @@
downscale=2,
scaled_shape_models=True,
max_shape_components=[1],
boundary=3).build(training_shapes, templates[1], group='PTS')
boundary=3).build(training_shapes, templates[1])

atm3 = ATMBuilder(features=igo,
transform=DifferentiablePiecewiseAffine,
Expand All @@ -332,7 +332,7 @@
downscale=2,
scaled_shape_models=True,
max_shape_components=[1, 2, 3],
boundary=3).build(training_shapes, templates[2], group='PTS')
boundary=3).build(training_shapes, templates[2])

atm4 = ATMBuilder(features=igo,
transform=DifferentiablePiecewiseAffine,
Expand All @@ -341,7 +341,7 @@
downscale=2,
scaled_shape_models=True,
max_shape_components=[1],
boundary=3).build(training_shapes, templates[3], group='PTS')
boundary=3).build(training_shapes, templates[3])


def test_atm1():
Expand Down Expand Up @@ -371,7 +371,7 @@ def test_n_shape_exception_2():

def test_pertrurb_shape():
fitter = LucasKanadeATMFitter(atm1)
s = fitter.perturb_shape(templates[0].landmarks['PTS'].lms,
s = fitter.perturb_shape(templates[0].landmarks[None].lms,
noise_std=0.08, rotation=False)
assert (s.n_dims == 2)
assert (s.n_landmark_groups == 0)
Expand Down Expand Up @@ -412,7 +412,7 @@ def atm_helper(atm, algorithm, im_number, max_iters, initial_error,
fitter = LucasKanadeATMFitter(atm, algorithm=algorithm)
fitting_result = fitter.fit(
templates[im_number], initial_shape[im_number],
gt_shape=templates[im_number].landmarks['PTS'].lms,
gt_shape=templates[im_number].landmarks[None].lms,
max_iters=max_iters)
assert_allclose(
np.around(fitting_result.initial_error(error_type=error_type), 5),
Expand Down
Loading

0 comments on commit 7c4cae5

Please sign in to comment.