# How can I reproduce the result of AgeEstimation model in MXNet-Python?

How can I reproduce the result of AgeEstimation model in MXNet-Python?

I want the result of Mathematica and the result of MXNet-Python are the same or closely.

For example:

"Age Estimation VGG-16 Trained on IMDB-WIKI Data"

I've also extracted a Mean Image, so you can implement into MXNet-Python, if necessary.

One result of this little_girl image in one version MXNet-Python is

[ 23 50 27 18 19 25 26 54 29 21 33 58 17 24 22 28 49 20 48 51 53 34 30 40 52 46 43 36 37 45 41 35 47 32 15 44 56 38 55 60 57 61 39 63 16 31 59 42 13 64 14 65 12 11 62 10 69 68 67 71 66 9 8 70 79 72 75 73 74 76 77 7 78 1 5 6 80 84 82 81 4 2 83 85 86 87 0 3 90 88 89 91 96 93 92 100 94 95 98 99 97]

• "I found in this codes, AgeEstimation is very challenging": If you read the example page for this model, it tells you it expects an image of their face ("Predict a person's age from an image of their face"). Hence why its doing terribly here. – Sebastian May 23 '18 at 11:31
• @Sebastian I've extracted an MeanImage, is it enough? – HyperGroups May 23 '18 at 11:34
• @Sebastian but even I use my croped face image, the result in Mathematica is also hard to reproduce in MXNet-Python – HyperGroups May 23 '18 at 11:38

I get a better result if I use FindFaces as a basis to crop the image.

Get the same image and net model that you're using:

img = Import["https://github.com/HyperGroups/MachineLearning/blob/master/mxnet/python/Data/little_girl.jpg?raw=true"];

model = NetModel["Age Estimation VGG-16 Trained on IMDB-WIKI Data"]


Use FindFaces to get a bounding box, then post-process it a bit. Two things are done: pad the bounding box by 50% on each side since FindFaces gives a very tight box and a bit more visual context is useful, and convert from x-y coordinates to row-column so that we can use ImageTake.

{w, h} = ImageDimensions[img];

s = .5;
faces = FindFaces[img, "BoundingBox"] /.
Rectangle[{xmin_, ymin_}, {xmax_, ymax_}] :>
{Reverse[{h - Clip[ymin - s (ymax - ymin), {0, h}],
h - Clip[ymax + s (ymax - ymin), {0, h}]}],
{Clip[xmin - s (xmax - xmin), {0, w}],
Clip[xmax + s (xmax - xmin), {0, w}]}}


Extract the faces and apply the age estimation model:

faceimages = ImageTake[img, ##] & @@@ faces

model /@ faceimages


Depending on the amount of padding (values of s between 0 and 1), I've gotten estimates of 10, 13, and 19.