Wolfram Computation Meets Knowledge

Yahoo Open NSFW Model V1

Determine whether an image contains pornographic content

Released in 2016 by Yahoo, this net is a binary classifier (safe/not safe) fine-tuned from the pre-trained ResNet-50 model. It determines whether an image is not suitable/safe for work (NSFW), due to the presence of nudity and/or pornographic content. The original model was chosen to provide a good tradeoff between accuracy and computational weight.

Number of layers: 177 | Parameter count: 5,944,514 | Trained size: 24 MB

Training Set Information

Examples

Resource retrieval

Retrieve the resource object:

In[1]:=
ResourceObject["Yahoo Open NSFW Model V1"]
Out[1]=

Get the pre-trained net:

In[2]:=
NetModel["Yahoo Open NSFW Model V1"]
Out[2]=

Basic usage

Apply the trained net to an input image:

In[3]:=
CloudGet["https://www.wolframcloud.com/objects/9404a602-fd1e-482f-a11b-0472d3b52d97"] (* Evaluate this cell to copy the example input from a cloud object *)
Out[3]=

Obtain the probabilities for each class for two images:

In[4]:=
CloudGet["https://www.wolframcloud.com/objects/d24a7949-78c2-4202-92ec-60153448505b"] (* Evaluate this cell to copy the example input from a cloud object *)
Out[4]=

Net information

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

In[5]:=
NetInformation[
 NetModel["Yahoo Open NSFW Model V1"], "ArraysElementCounts"]
Out[5]=

Obtain the total number of parameters:

In[6]:=
NetInformation[
 NetModel["Yahoo Open NSFW Model V1"], "ArraysTotalElementCount"]
Out[6]=

Obtain the layer type counts:

In[7]:=
NetInformation[
 NetModel["Yahoo Open NSFW Model V1"], "LayerTypeCounts"]
Out[7]=

Display the summary graphic:

In[8]:=
NetInformation[NetModel["Yahoo Open NSFW Model V1"], "SummaryGraphic"]
Out[8]=

Export to MXNet

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

In[9]:=
jsonPath = 
 Export[FileNameJoin[{$TemporaryDirectory, "net.json"}], 
  NetModel["Yahoo Open NSFW Model V1"], "MXNet"]
Out[9]=

Export also creates a net.params file containing parameters:

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

Get the size of the parameter file:

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

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

In[12]:=
ResourceObject["Yahoo Open NSFW Model V1"]["ByteCount"]
Out[12]=

Requirements

Wolfram Language 11.2 (September 2017) or above

Reference