Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The big refactor #67

Merged
merged 460 commits into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
460 commits
Select commit Hold shift + click to select a range
45486aa
Merge branch 'refactor' into aam_fixes
patricksnape Aug 4, 2015
afc4c43
Fix incremental Gauss-Newton
patricksnape Aug 4, 2015
b0fefcc
Refactoring AAM to match SD-AAM
patricksnape Aug 4, 2015
b9a4cd9
Refactor results to take a transform rather than algorithm
patricksnape Aug 4, 2015
dc67955
Fix menpofit widgets
patricksnape Aug 4, 2015
6c25a53
Nasty bug about truncating shape model
patricksnape Aug 5, 2015
ee9e58b
Fix __str__ for AAMs
patricksnape Aug 5, 2015
d887081
Change results back to taking algorithm
patricksnape Aug 5, 2015
b4fe608
Partial commit - moving home due to tube strike
patricksnape Aug 5, 2015
537b6df
Remove xrange - for Python 3 compat
patricksnape Aug 6, 2015
15706b6
Incorrect call to super - fixed
patricksnape Aug 6, 2015
ca0f3f7
Fix noise variance bug
patricksnape Aug 6, 2015
a95f861
Refactor trilist check method
patricksnape Aug 6, 2015
03c3216
Remove mention of downscale etc from visualize
patricksnape Aug 6, 2015
f5b4217
Remove unused methods
patricksnape Aug 6, 2015
d782cf8
Fix bugs using wrong index in AAM
patricksnape Aug 6, 2015
5640d60
Update ATM to work with AAM layout
patricksnape Aug 6, 2015
665ef0a
Refactor LK to match new scheme
patricksnape Aug 6, 2015
2684100
Rename Patch{ATM,AAM} to Masked and Parts to Patch
patricksnape Aug 6, 2015
b548310
Update travis and appveyor
patricksnape Aug 7, 2015
13394e1
Fix a bunch of relative import errors
patricksnape Aug 7, 2015
9eaf568
Merge pull request #60 from menpo/aam_fixes
Aug 10, 2015
5a01c06
Refactor training to be more consistent
patricksnape Aug 10, 2015
5ab5f67
Move _train to top in CLM - consistent with AAM etc
patricksnape Aug 10, 2015
0b7e0b7
Merge pull request #62 from menpo/cleaning
Aug 10, 2015
d642ab1
Fix silly bug in PatchAAM
patricksnape Aug 11, 2015
95c965d
Small inhancement for no_op
patricksnape Aug 11, 2015
554ccd1
Fix printing a bit
patricksnape Aug 11, 2015
343190e
Change fitting methods to fit_from_shape/bb
patricksnape Aug 11, 2015
497e527
Rename Parts interfaces to patch
patricksnape Aug 11, 2015
781c293
Universally rename patch_shape to patch_size
patricksnape Aug 11, 2015
efea68a
Renaming features parameters
patricksnape Aug 13, 2015
ad3f7bd
Rename partsinterface to patchinterface
patricksnape Aug 13, 2015
28f2e82
Merge pull request #66 from menpo/features_naming
Aug 13, 2015
b753004
Modify ModelDrivenTransforms
May 20, 2015
7202888
Update modelinstance.py
May 20, 2015
4f892a9
Add convenient functions to builder.py
May 20, 2015
7b845ad
Add check funtions to check.py
May 20, 2015
9a58a55
Update import in transforms.__init__
May 20, 2015
9e1fd61
Add new AAM types
May 20, 2015
b8fc1ad
Add builders for all AAM classes
May 20, 2015
e4c24a5
Update documentation in aam.base.py
May 20, 2015
e7c93f4
Minor documnetation changes in aam.base and aam.builder
May 20, 2015
a21ada4
Restructure aam.base
May 21, 2015
0685876
Restructure aam.builder
May 21, 2015
2ce01e0
Restructure fitter.py
May 21, 2015
3c57634
Force OrthoMDTransform and OrthoMDPDM to use only similarity transforms
May 21, 2015
c90639a
Add LKAAMFitter
May 21, 2015
d3057ae
Add results.py
May 21, 2015
a12b5af
Add results for AAMs
May 21, 2015
d81760e
Add small fix in aam.fitter
May 21, 2015
4671bd7
Small corrections to fitters
May 21, 2015
6570e04
More corrections to fitters
May 21, 2015
f8e3918
Add basic AAM algorithms
May 21, 2015
b899e41
Update aam.__init__.py
May 21, 2015
3b155c9
Slight modification to aam.algorithm
May 21, 2015
d1bfa8c
Unify AAM sampling
May 21, 2015
92aea20
Small changes to fitter.py
May 21, 2015
ae959f5
Small renaming
May 21, 2015
75305c3
Modify noisy_align in fitter.py
May 21, 2015
0e1f951
Add LKFitter
May 21, 2015
86b107f
Add results for LK
May 21, 2015
1731a53
Add residuals for LK
May 21, 2015
0abda37
Add algorithms for LK
May 21, 2015
ff1dc0a
Update lk.__init__
May 21, 2015
2847864
Add accidentaly deleted view_shape_models_widget to AAM
May 22, 2015
faacec7
More small changes to aam.base
May 22, 2015
001ba8f
Small changes to AAM
May 22, 2015
764111a
Add TODO in lk.algorithm
May 22, 2015
7db14cf
Add ATM base classes
May 26, 2015
e5d0ac3
Remove SerializableAAMFitterResult
May 26, 2015
9033837
Small changes in menpofit.builder
May 26, 2015
05ff85a
Small changes in menpofit.fitter
May 26, 2015
fed1723
Add Builders for ATMs
May 26, 2015
29a9db4
Add Results for ATMs
May 26, 2015
563d25c
Add LKFitters for ATMs
May 26, 2015
82dad4c
Add algorithms for ATMs
May 26, 2015
e57dbcd
Add __init__.py for ATMs
May 26, 2015
e049ac7
Make shapes a property in results.py
May 29, 2015
651c0df
Make shape a property for LinearAAMAlgorithmResult
May 29, 2015
29ac18e
Add funtion rescale_images_to_reference_frame to menpofit.builder
May 29, 2015
e18272e
Add CR AAM Fitter
May 29, 2015
4d79e9a
Rename aam.algorithm.py to aam.algorithm.lk.py
May 29, 2015
3668774
Add first version of CR Algorithms
May 29, 2015
7e654ac
Delete old aam.alagorithm.py and update aam.algorithm.__init__.py
May 29, 2015
7026f95
Update aam.alagorithm.__init__.py
May 29, 2015
21d0870
Add new initializations for ModelFitter
May 29, 2015
7db8622
Change prepare_max_iters in Fitter for a checking function
May 29, 2015
67b9d34
Add support for sampling being a list
May 29, 2015
c771c03
Remove ProjectOut2 from aam.algorithm.cr
May 29, 2015
6dc7b86
Small changes to training regression based AAMs
Jun 1, 2015
a100930
Removed algorithm.py
Jun 1, 2015
ee3b74b
Update fitter.py and LinearATMAlgorithmResult
Jun 1, 2015
779a052
Add small changes to fitter.py
Jun 17, 2015
d4618d0
Add first version of sdm fitter
Jun 17, 2015
395a0b0
Add first version of sdm algorithms
Jun 17, 2015
1ea756c
Update sdm/__init__.py
Jun 17, 2015
c286a5c
Slight modifications to SDM
Jun 22, 2015
465e413
Delete sdm/trainer.py
Jun 22, 2015
70b3709
Changed old ...inplace calls on lk/fitter.py and fitter.py
Jun 22, 2015
48270ef
Update initialization method for ModelFitter
Jun 23, 2015
c36037c
Make Linear(AAM, ATM) fitting results return point graph shapes
Jun 23, 2015
3b98d0c
Update checks for AAMs, ATMs and LK
Jun 29, 2015
28061ca
Fixed noise_std default value
Jun 29, 2015
47c66dc
Add psi parameter to CRAAM
Jun 29, 2015
e3b0d8c
Rename AAM, ATM, LK Fitters, Algorithms and Results.
Jun 30, 2015
4e2ad7c
Small fixes related to the previous commit
Jun 30, 2015
52ba60e
Tidy up scales in prepare_image and prepare_template
Jun 30, 2015
52ae7c8
Add new holistic sampling methods
Jun 30, 2015
aeaf292
Delete TODOs regarding sampling
Jun 30, 2015
15c2bce
Update checks
Jun 30, 2015
42b4364
Correct typo in LucasKanadeLinearInterface
Jul 1, 2015
8162ac2
Add costs to AAMs
Jul 1, 2015
11076ad
Add cost for ATMs
Jul 1, 2015
656d7ce
Add cost for LK
Jul 2, 2015
a1094c7
Remove addressed TODOs
Jul 2, 2015
50c49ba
Fix noisy_align method removed
patricksnape Jul 3, 2015
a5a9ab7
Add incremental sdm
Jul 3, 2015
3701b71
Add incremental AAM
Jul 6, 2015
89ec1a0
Small change in SDMFiter
Jul 6, 2015
6bdf976
Add initialization from user provided shapes and bounding boxes.
Jul 6, 2015
e969646
Add new math subpackage
Jul 6, 2015
7922f58
Small fix in result.py
Jul 6, 2015
134f9cd
Fix for results.py
Jul 6, 2015
2551e90
Update errors in results.
Jul 7, 2015
fac06d5
Update sdm algorithms to print more informative errors.
Jul 7, 2015
3bea708
Add the ability to train sdmfitters using a single bounding box per i…
Jul 7, 2015
7748f8d
Update widget to play well with changes on error computation
Jul 7, 2015
ed743fd
Add back ability to not use rotation on initialization.
Jul 8, 2015
62ac203
Add the ability to perturb without rotation
Jul 13, 2015
b899d55
Small refactoring of regression classes
Jul 13, 2015
d9ba910
Fix LK
Jul 15, 2015
86f54e4
Add new perturbation procedure.
Jul 20, 2015
d00174f
Fix pickling of SDM
patricksnape Jul 20, 2015
097aebc
Fix the None bounding box key error
patricksnape Jul 20, 2015
4cb37a0
Fixing verbose mode of helper functions
patricksnape Jul 20, 2015
5daa854
Update aam warp_images set_target
patricksnape Jul 20, 2015
18f3b2f
Update regression - better printing
patricksnape Jul 20, 2015
e49a718
Big change to how bboxes are created
patricksnape Jul 20, 2015
8bd8510
Small changes
Jul 21, 2015
ec5a16a
Call reset_algorithms when recalling train
patricksnape Jul 22, 2015
012f024
Properly use the perturb method for SDM
patricksnape Jul 22, 2015
4d4259b
Update increment on SDM to same as train
patricksnape Jul 22, 2015
8d22660
Fix rescaling to reference shape for incremental sdm
patricksnape Jul 23, 2015
cb21047
Remove perturb_from_shape
patricksnape Jul 24, 2015
79b84ed
Make train_incremental work on generators
patricksnape Jul 24, 2015
d617574
Fix non-verbose mode for SDM
patricksnape Jul 24, 2015
f194d4c
Add the idea of holistic features
patricksnape Jul 24, 2015
2dd1fe5
Try creating a sensible __str__ for sdm
patricksnape Jul 24, 2015
32cffd4
Calculate diagonal correctly.
patricksnape Jul 24, 2015
914e296
Update name_of_callable to support partial
patricksnape Jul 24, 2015
636ceb3
Partial commit before squash
patricksnape Jul 24, 2015
6beb4d5
Add recursive call to name_of_callable
patricksnape Jul 26, 2015
3b45c7d
Fix error in name_of_callable
patricksnape Jul 27, 2015
ffc3d2e
Incorrect indent in batch
patricksnape Jul 27, 2015
68704f8
SDM refactor training
patricksnape Jul 27, 2015
300759c
Allow batch training of incremental SDM
patricksnape Jul 27, 2015
c52424f
Remove label kwarg from builder functions
patricksnape Jul 27, 2015
bdcecce
Remove label kwarg from AAMs
patricksnape Jul 27, 2015
f6bd1e9
Remove label kwarg from ATM
patricksnape Jul 27, 2015
cca54dd
Remove label kwarg from LK package
patricksnape Jul 27, 2015
75f57af
Remove label kwarg from visualize package
patricksnape Jul 27, 2015
50237af
Cleanup the feature/patch extraction code
patricksnape Jul 27, 2015
6e8dec4
Fixes some errors introduced by sdm_refactor
Jul 27, 2015
9ba57b5
Get rid of the first_batch thing
patricksnape Jul 28, 2015
9a7c3bb
SDM, flip the scales logic so that its increasing
patricksnape Jul 28, 2015
e8b829c
Remove useless tests and benchmark packages
patricksnape Jul 28, 2015
6b33126
Remove spaces from docs and add super calls
patricksnape Jul 28, 2015
75d69be
Start moving the AAMBuilder into AAM
patricksnape Jul 28, 2015
5670a9a
Cleaning more code from the AAMBuider, mostly moving stuff around
patricksnape Jul 28, 2015
436a2e1
Finish moving build logic into base (AAM)
patricksnape Jul 29, 2015
e942f6c
Add _increment_shape_model
patricksnape Jul 29, 2015
4cacf9a
Missing check for patch features
patricksnape Jul 29, 2015
ae43fc3
Only raise warning for scale_features it True
patricksnape Jul 29, 2015
5d6584e
Accidentally worked on too many things...
patricksnape Jul 29, 2015
94bda52
Add a RegularizedSDM alias
patricksnape Jul 29, 2015
ab5cc33
Don't split patch parameter over two lines
patricksnape Jul 29, 2015
69f7613
Allow passing an explicit reference_shape to AAM
patricksnape Jul 29, 2015
034893a
Rename n_levels to n_scales
patricksnape Jul 29, 2015
6739040
Take @jalabort _prepare_image method
patricksnape Jul 29, 2015
9d1460f
Move AAM to scales away from 'levels'
patricksnape Jul 30, 2015
644c422
Move SDM to scales away from levels
patricksnape Jul 30, 2015
dd311e1
Remove scale_features
patricksnape Jul 30, 2015
58a506f
Bug using wrong index
patricksnape Jul 30, 2015
ebbdb42
Add menpofit.feature package
Jul 31, 2015
e7fc36f
Add __init__.py
Jul 31, 2015
c7fb145
Add ftt_utils.py to menpofit.math
Jul 31, 2015
bb230f5
Add correlationfilters.py to menpofit.math
Jul 31, 2015
e1f4ef8
Update __init__.py from menpofit.math
Jul 31, 2015
6cac7de
Add clm results
Jul 31, 2015
bd2ceb0
Add CLM class
Jul 31, 2015
ac9d87b
Add dummy wrapper for correlation filters
Jul 31, 2015
477ea03
Add CorrelationFilterExpertEnsamble
Jul 31, 2015
bd3427e
Add __init__.py
Jul 31, 2015
d4c7e05
Add CLMFitters
Jul 31, 2015
65b6978
Add __init__.py to menpofit.clm
Jul 31, 2015
08d3c40
Refactoring SD-AAM
patricksnape Jul 31, 2015
9335a96
Add clm base algorithm
Aug 3, 2015
c33f88f
Add clm algorithms
Aug 3, 2015
656ee2f
Add not implemented supervised descent algorthm for clms
Aug 3, 2015
7886a9b
Add __init__.py
Aug 3, 2015
242813c
Update __init__.py
Aug 3, 2015
c4679c9
Change n_levels for n_scales in aam
Aug 3, 2015
7785306
Change n_levels for n_scales in atm
Aug 3, 2015
23f617a
Change n_levels for n_scales in lk
Aug 3, 2015
ca68468
Final changes
Aug 3, 2015
2946407
GaussNewton regression needed transposing
patricksnape Aug 4, 2015
e0080f3
Remove extra space
patricksnape Aug 4, 2015
6755934
Remove unused methods and correct spelling
patricksnape Aug 4, 2015
11f69b7
Attempting to refactor SD-AAM
patricksnape Aug 4, 2015
3ed6652
Fix incremental Gauss-Newton
patricksnape Aug 4, 2015
e1bd94b
Refactoring AAM to match SD-AAM
patricksnape Aug 4, 2015
abc1dc3
Refactor results to take a transform rather than algorithm
patricksnape Aug 4, 2015
bf4eff3
Fix menpofit widgets
patricksnape Aug 4, 2015
e3fd5c4
Nasty bug about truncating shape model
patricksnape Aug 5, 2015
fa24f24
Fix __str__ for AAMs
patricksnape Aug 5, 2015
a7821ec
Change results back to taking algorithm
patricksnape Aug 5, 2015
7e714d5
Partial commit - moving home due to tube strike
patricksnape Aug 5, 2015
7a1cbf3
Remove xrange - for Python 3 compat
patricksnape Aug 6, 2015
31c5ed2
Incorrect call to super - fixed
patricksnape Aug 6, 2015
2ac167b
Fix noise variance bug
patricksnape Aug 6, 2015
79943a4
Refactor trilist check method
patricksnape Aug 6, 2015
8d6e355
Remove mention of downscale etc from visualize
patricksnape Aug 6, 2015
bda0378
Remove unused methods
patricksnape Aug 6, 2015
9fb6561
Fix bugs using wrong index in AAM
patricksnape Aug 6, 2015
ae3884c
Update ATM to work with AAM layout
patricksnape Aug 6, 2015
18135e0
Refactor LK to match new scheme
patricksnape Aug 6, 2015
ab67285
Rename Patch{ATM,AAM} to Masked and Parts to Patch
patricksnape Aug 6, 2015
facea21
Update travis and appveyor
patricksnape Aug 7, 2015
0353e72
Fix a bunch of relative import errors
patricksnape Aug 7, 2015
d53a9c1
Refactor training to be more consistent
patricksnape Aug 10, 2015
15b34c2
Move _train to top in CLM - consistent with AAM etc
patricksnape Aug 10, 2015
b0a02a2
Fix silly bug in PatchAAM
patricksnape Aug 11, 2015
ff07836
Small inhancement for no_op
patricksnape Aug 11, 2015
d592ddb
Fix printing a bit
patricksnape Aug 11, 2015
4ea9c52
Change fitting methods to fit_from_shape/bb
patricksnape Aug 11, 2015
00b28cc
Rename Parts interfaces to patch
patricksnape Aug 11, 2015
fe6cdec
Universally rename patch_shape to patch_size
patricksnape Aug 11, 2015
471e063
Renaming features parameters
patricksnape Aug 13, 2015
bc57cbd
Rename partsinterface to patchinterface
patricksnape Aug 13, 2015
b838476
Merge branch 'refactor' into refactor_merge
patricksnape Aug 13, 2015
5330aaa
Fixes for Jupyter 4.0
patricksnape Aug 18, 2015
2a57367
Update to v0.4.4 condaci
patricksnape Aug 18, 2015
7d0806a
Update condaci
patricksnape Aug 19, 2015
cc3509d
Upgrade to latest condaci
patricksnape Aug 19, 2015
f86830c
More fixes for Jupyter 4.0
patricksnape Aug 21, 2015
1f406b5
Move len(scales) to AFTER it has been checked
patricksnape Aug 21, 2015
4b127f7
ipywidgets rather than IPython (jupyter 4)
patricksnape Aug 24, 2015
c6fea14
Fix passing single scale
patricksnape Aug 24, 2015
1a7a2f4
Change asarray to stacking
patricksnape Aug 26, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finish moving build logic into base (AAM)
Now building is intimately integrated with the AAM objects. Still
need to test that these things actually work though.
  • Loading branch information
patricksnape committed Aug 13, 2015
commit 436a2e157faf361554818821c5a5084cd3cdba48
2 changes: 1 addition & 1 deletion menpofit/aam/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import AAM
from .base import AAM, LinearAAM, LinearPatchAAM, PartsAAM, PatchAAM
from .fitter import (
LucasKanadeAAMFitter, SupervisedDescentAAMFitter,
holistic_sampling_from_scale, holistic_sampling_from_step)
Expand Down
185 changes: 120 additions & 65 deletions menpofit/aam/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import division
from copy import deepcopy
import numpy as np
from menpo.shape import TriMesh
from menpo.feature import no_op
from menpo.visualize import print_dynamic
from menpo.model import PCAModel
from menpo.transform import Scale
from menpo.shape import mean_pointcloud
from menpofit import checks
from menpofit.transform import DifferentiableThinPlateSplines, \
DifferentiablePiecewiseAffine
Expand All @@ -14,7 +14,7 @@
build_reference_frame, build_patch_reference_frame,
normalization_wrt_reference_shape, compute_features, scale_images,
build_shape_model, warp_images, align_shapes,
rescale_images_to_reference_shape)
rescale_images_to_reference_shape, densify_shapes, extract_patches)


# TODO: document me!
Expand Down Expand Up @@ -118,8 +118,8 @@ class AAM(object):
def __init__(self, images, group=None, verbose=False,
features=no_op, transform=DifferentiablePiecewiseAffine,
diagonal=None, scales=(0.5, 1.0), scale_features=True,
max_shape_components=None, forgetting_factor=1.0,
max_appearance_components=None, batch_size=None):
max_shape_components=None, max_appearance_components=None,
batch_size=None):
# check parameters
checks.check_diagonal(diagonal)
scales, n_levels = checks.check_scales(scales)
Expand All @@ -135,7 +135,6 @@ def __init__(self, images, group=None, verbose=False,
self.scale_features = scale_features
self.diagonal = diagonal
self.scales = scales
self.forgetting_factor = forgetting_factor
self.max_shape_components = max_shape_components
self.max_appearance_components = max_appearance_components
self.reference_shape = None
Expand All @@ -147,6 +146,7 @@ def __init__(self, images, group=None, verbose=False,
batch_size=batch_size)

def _train(self, images, group=None, verbose=False, increment=False,
shape_forgetting_factor=1.0, appearance_forgetting_factor=1.0,
batch_size=None):
r"""
Builds an Active Appearance Model from a list of landmarked images.
Expand Down Expand Up @@ -255,7 +255,7 @@ def _train(self, images, group=None, verbose=False, increment=False,
# Increment shape model
self.shape_models[j].increment(
aligned_shapes,
forgetting_factor=self.forgetting_factor)
forgetting_factor=shape_forgetting_factor)
if self.max_shape_components is not None:
self.shape_models[j].trim_components(
self.max_appearance_components[j])
Expand Down Expand Up @@ -284,7 +284,9 @@ def _train(self, images, group=None, verbose=False, increment=False,
self.appearance_models.append(appearance_model)
else:
# increment appearance model
self.appearance_models[j].increment(warped_images)
self.appearance_models[j].increment(
warped_images,
forgetting_factor=appearance_forgetting_factor)
# trim appearance model if required
if self.max_appearance_components is not None:
self.appearance_models[j].trim_components(
Expand All @@ -293,6 +295,18 @@ def _train(self, images, group=None, verbose=False, increment=False,
if verbose:
print_dynamic('{}Done\n'.format(level_str))

def increment(self, images, group=None, verbose=False,
shape_forgetting_factor=1.0, appearance_forgetting_factor=1.0,
batch_size=None):
# Literally just to fit under 80 characters, but maintain the sensible
# parameter name
aff = appearance_forgetting_factor
return self._train(images, group=group,
verbose=verbose,
shape_forgetting_factor=shape_forgetting_factor,
appearance_forgetting_factor=aff,
increment=True, batch_size=batch_size)

def _build_shape_model(self, shapes, max_components, level):
return build_shape_model(shapes, max_components=max_components)

Expand Down Expand Up @@ -640,21 +654,26 @@ class PatchAAM(AAM):
scale_features : `boolean`
"""

def __init__(self, shape_models, appearance_models, reference_shape,
patch_shape, features, scales, scale_shapes, scale_features,
transform):
super(PatchAAM, self).__init__(shape_models, appearance_models,
reference_shape, transform, features,
scales, scale_shapes, scale_features)
self.shape_models = shape_models
self.appearance_models = appearance_models
self.transform = DifferentiableThinPlateSplines
def __init__(self, images, group=None, verbose=False, features=no_op,
diagonal=None, scales=(0.5, 1.0), patch_shape=(17, 17),
scale_features=True, max_shape_components=None,
max_appearance_components=None, batch_size=None):
self.patch_shape = patch_shape
self.features = features
self.reference_shape = reference_shape
self.scales = scales
self.scale_shapes = scale_shapes
self.scale_features = scale_features

super(PatchAAM, self).__init__(
images, group=group, verbose=verbose, features=features,
transform=DifferentiableThinPlateSplines, diagonal=diagonal,
scales=scales, scale_features=scale_features,
max_shape_components=max_shape_components,
max_appearance_components=max_appearance_components,
batch_size=batch_size)

def _warp_images(self, images, shapes, reference_shape, level, level_str,
verbose):
reference_frame = build_patch_reference_frame(
reference_shape, patch_shape=self.patch_shape[level])
return warp_images(images, shapes, reference_frame, self.transform,
level_str=level_str, verbose=verbose)

@property
def _str_title(self):
Expand Down Expand Up @@ -728,21 +747,36 @@ class LinearAAM(AAM):
scale_features : `boolean`
"""

def __init__(self, shape_models, appearance_models, reference_shape,
transform, features, scales, scale_shapes, scale_features,
n_landmarks):
super(LinearAAM, self).__init__(shape_models, appearance_models,
reference_shape, transform, features,
scales, scale_shapes, scale_features)
self.shape_models = shape_models
self.appearance_models = appearance_models
self.transform = transform
self.features = features
self.reference_shape = reference_shape
self.scales = scales
self.scale_shapes = scale_shapes
self.scale_features = scale_features
self.n_landmarks = n_landmarks
def __init__(self, images, group=None, verbose=False, features=no_op,
transform=DifferentiableThinPlateSplines, diagonal=None,
scales=(0.5, 1.0), scale_features=True,
max_shape_components=None, max_appearance_components=None,
batch_size=None):

super(LinearAAM, self).__init__(
images, group=group, verbose=verbose, features=features,
transform=transform, diagonal=diagonal,
scales=scales, scale_features=scale_features,
max_shape_components=max_shape_components,
max_appearance_components=max_appearance_components,
batch_size=batch_size)

def _build_shape_model(self, shapes, max_components, level):
mean_aligned_shape = mean_pointcloud(align_shapes(shapes))
self.n_landmarks = mean_aligned_shape.n_points
self.reference_frame = build_reference_frame(mean_aligned_shape)
dense_shapes = densify_shapes(shapes, self.reference_frame,
self.transform)
# build dense shape model
shape_model = build_shape_model(
dense_shapes, max_components=max_components)
return shape_model

def _warp_images(self, images, shapes, reference_shape, level, level_str,
verbose):
return warp_images(images, shapes, self.reference_frame,
self.transform, level_str=level_str,
verbose=verbose)

# TODO: implement me!
def _instance(self, level, shape_instance, appearance_instance):
Expand Down Expand Up @@ -801,23 +835,37 @@ class LinearPatchAAM(AAM):
n_landmarks: `int`
"""

def __init__(self, shape_models, appearance_models, reference_shape,
patch_shape, features, scales, scale_shapes, scale_features,
n_landmarks, transform):
super(LinearPatchAAM, self).__init__(shape_models, appearance_models,
reference_shape, transform,
features, scales, scale_shapes,
scale_features)
self.shape_models = shape_models
self.appearance_models = appearance_models
self.transform = DifferentiableThinPlateSplines
def __init__(self, images, group=None, verbose=False, features=no_op,
diagonal=None, scales=(0.5, 1.0), patch_shape=(17, 17),
scale_features=True, max_shape_components=None,
max_appearance_components=None, batch_size=None):
self.patch_shape = patch_shape
self.features = features
self.reference_shape = reference_shape
self.scales = scales
self.scale_shapes = scale_shapes
self.scale_features = scale_features
self.n_landmarks = n_landmarks

super(LinearPatchAAM, self).__init__(
images, group=group, verbose=verbose, features=features,
transform=DifferentiableThinPlateSplines, diagonal=diagonal,
scales=scales, scale_features=scale_features,
max_shape_components=max_shape_components,
max_appearance_components=max_appearance_components,
batch_size=batch_size)

def _build_shape_model(self, shapes, max_components, level):
mean_aligned_shape = mean_pointcloud(align_shapes(shapes))
self.n_landmarks = mean_aligned_shape.n_points
self.reference_frame = build_patch_reference_frame(
mean_aligned_shape, patch_shape=self.patch_shape[level])
dense_shapes = densify_shapes(shapes, self.reference_frame,
self.transform)
# build dense shape model
shape_model = build_shape_model(dense_shapes,
max_components=max_components)
return shape_model

def _warp_images(self, images, shapes, reference_shape, level, level_str,
verbose):
return warp_images(images, shapes, self.reference_frame,
self.transform, level_str=level_str,
verbose=verbose)

# TODO: implement me!
def _instance(self, level, shape_instance, appearance_instance):
Expand All @@ -841,6 +889,7 @@ def __str__(self):


# TODO: document me!
# TODO: implement offsets support?
class PartsAAM(AAM):
r"""
Parts based Active Appearance Model class.
Expand Down Expand Up @@ -876,21 +925,27 @@ class PartsAAM(AAM):
scale_features : `boolean`
"""

def __init__(self, shape_models, appearance_models, reference_shape,
patch_shape, features, normalize_parts, scales, scale_shapes,
scale_features, transform):
super(PartsAAM, self).__init__(shape_models, appearance_models,
reference_shape, transform, features,
scales, scale_shapes, scale_features)
self.shape_models = shape_models
self.appearance_models = appearance_models
def __init__(self, images, group=None, verbose=False, features=no_op,
normalize_parts=no_op, diagonal=None, scales=(0.5, 1.0),
patch_shape=(17, 17), scale_features=True,
max_shape_components=None, max_appearance_components=None,
batch_size=None):
self.patch_shape = patch_shape
self.features = features
self.normalize_parts = normalize_parts
self.reference_shape = reference_shape
self.scales = scales
self.scale_shapes = scale_shapes
self.scale_features = scale_features

super(PartsAAM, self).__init__(
images, group=group, verbose=verbose, features=features,
transform=DifferentiableThinPlateSplines, diagonal=diagonal,
scales=scales, scale_features=scale_features,
max_shape_components=max_shape_components,
max_appearance_components=max_appearance_components,
batch_size=batch_size)

def _warp_images(self, images, shapes, reference_shape, level, level_str,
verbose):
return extract_patches(images, shapes, self.patch_shape[level],
normalize_function=self.normalize_parts,
level_str=level_str, verbose=verbose)

# TODO: implement me!
def _instance(self, level, shape_instance, appearance_instance):
Expand Down
Loading