Created
July 27, 2015 15:14
-
-
Save patricksnape/d36d7f2c3a855737a6a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%matplotlib inline\nimport numpy as np\nimport menpo.io as mio\nfrom itertools import chain, islice\nfrom functools import partial\nfrom menpo.feature import ndfeature, fast_dsift", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@ndfeature\ndef menpo_dsift(pixels):\n return fast_dsift(pixels).astype(np.float32)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from menpofit.fitter import noisy_shape_from_bounding_box\nfrom menpofit.sdm import Newton\n\nbbox_method = partial(noisy_shape_from_bounding_box, noise_percentage=0.001)\nsdm_alg = partial(Newton, alpha=0.01)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sdm = SupervisedDescentFitter(images, \n group='sclera',\n bounding_box_group='bbox',\n sd_algorithm_cls=sdm_alg,\n patch_features=sparse_hog, \n scales=(1, 0.5), \n iterations=10, \n patch_shape=(17, 17),\n n_perturbations=20, \n perturb_from_bounding_box=bbox_method,\n verbose=False, \n batch_size=None)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sdm.increment(images, \n group='sclera', \n bounding_box_group='bbox', \n verbose=True, \n batch_size=None)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(sdm)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "mio.export_pickle(sdm, '/mnt/data/sdm_test.pkl.gz', overwrite=True)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from menpofit.fitter import align_shape_with_bounding_box\nfrom menpo.transform import AlignmentAffine, AlignmentSimilarity\n\n\ninit = align_shape_with_bounding_box(sdm.reference_shape, \n im.landmarks['bbox'],\n alignment_transform_cls=AlignmentSimilarity)\nleye_result = sdm.fit(im, init, crop_image=1)", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python2", | |
"display_name": "Python 2", | |
"language": "python" | |
}, | |
"notify_time": "30", | |
"language_info": { | |
"mimetype": "text/x-python", | |
"nbconvert_exporter": "python", | |
"name": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.10", | |
"file_extension": ".py", | |
"codemirror_mode": { | |
"version": 2, | |
"name": "ipython" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment