Wolfram Computation Meets Knowledge

Gender Prediction VGG-16 Trained on IMDB-WIKI Data

Predict a person's gender from an image of their face

Released in 2015 as a pre-trained model for the launch of the IMDB-WIKI dataset by the Computer Vision Lab at ETH Zurich, this model is based on the VGG-16 architecture and is designed to run on cropped images of faces only.

Number of layers: 40 | Parameter count: 134,268,738 | Trained size: 538 MB

Training Set Information

Examples

Resource retrieval

Retrieve the resource object:

In[1]:=
ResourceObject["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"]
Out[1]=

Get the pre-trained net:

In[2]:=
NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"]
Out[2]=

Basic usage

Guess the gender of a person from a photograph:

In[3]:=
CloudGet["https://www.wolframcloud.com/objects/7b962803-7d90-4fa8-bfd5-b7be28d11a7a"] (* Evaluate this cell to copy the example input from a cloud object *)
Out[3]=

Obtain the probabilities:

In[4]:=
CloudGet["https://www.wolframcloud.com/objects/2f7e86dc-7218-4e3a-a3c9-472156023143"] (* Evaluate this cell to copy the example input from a cloud object *)
Out[4]=

This net was designed to work with cropped images of faces. If the photograph is not a cropped image of a face, the results may be unexpected:

In[5]:=
CloudGet["https://www.wolframcloud.com/objects/a4b63f38-d51d-45a3-be04-5cefaa700ce8"] (* Evaluate this cell to copy the example input from a cloud object *)
In[6]:=
NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"][img]
Out[6]=

Crop the photograph:

In[7]:=
crop = ImageTrim[img, #] & /@ FindFaces[img]
Out[7]=

Guess the gender of a person from the cropped image:

In[8]:=
NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"][crop]
Out[8]=

Net information

Inspect the number of parameters of all arrays in the net:

In[9]:=
NetInformation[
 NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"], \
"ArraysElementCounts"]
Out[9]=

Obtain the total number of parameters:

In[10]:=
NetInformation[
 NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"], \
"ArraysTotalElementCount"]
Out[10]=

Obtain the layer type counts:

In[11]:=
NetInformation[
 NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"], \
"LayerTypeCounts"]
Out[11]=

Display the summary graphic:

In[12]:=
NetInformation[
 NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"], \
"SummaryGraphic"]
Out[12]=

Export to MXNet

Export the net into a format that can be opened in MXNet:

In[13]:=
jsonPath = 
 Export[FileNameJoin[{$TemporaryDirectory, "net.json"}], 
  NetModel["Gender Prediction VGG-16 Trained on IMDB-WIKI Data"], 
  "MXNet"]
Out[13]=

Export also creates a net.params file containing parameters:

In[14]:=
paramPath = FileNameJoin[{DirectoryName[jsonPath], "net.params"}]
Out[14]=

Get the size of the parameter file:

In[15]:=
FileByteCount[paramPath]
Out[15]=

The size is similar to the byte count of the resource object:

In[16]:=
ResourceObject[
  "Gender Prediction VGG-16 Trained on IMDB-WIKI Data"]["ByteCount"]
Out[16]=

Represent the MXNet net as a graph:

In[17]:=
Import[jsonPath, {"MXNet", "NodeGraphPlot"}]
Out[17]=

Requirements

Wolfram Language 11.2 (September 2017) or above

Reference