U2-Net Portrait Generator Trained on APDrawing Data

Generate a portrait sketch from a photo

This model is an art-oriented spinoff of the original U2-Net project for semantic segmentation. While still taking an image and outputting probabilities for a binary mask, the output of this model is interpreted as pixel values for a grayscale artistic portrait version of the input image, which is assumed to depict a human.

Training Set Information

Model Information

Examples

Resource retrieval

Get the pre-trained net:

In[1]:=
NetModel["U2-Net Portrait Generator Trained on APDrawing Data"]
Out[1]=

Basic usage

Get a face image:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/c60a91e8-9cae-4b6e-92f6-9e7c2449b2c9"]

Obtain the portrait version of the image:

In[3]:=
NetModel["U2-Net Portrait Generator Trained on APDrawing Data"]@img
Out[3]=

Adapt to aspect ratios

The net resizes the image to 320x320 before processing and outputs an image of the same size, hence non-square images will result in distorted outputs:

In[4]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/b5cfac32-3ac4-4a5e-9b99-14f496f7d0bc"]
In[5]:=
NetModel[
  "U2-Net Portrait Generator Trained on APDrawing Data"]@nonSquareImg
Out[5]=

For this reason, it is advised to manually extract a square crop before feeding the image to the net:

In[6]:=
squareCrop = ImageTake[nonSquareImg, {41, 233}, All]
Out[6]=
In[7]:=
ImageDimensions[squareCrop]
Out[7]=
In[8]:=
NetModel[
  "U2-Net Portrait Generator Trained on APDrawing Data"]@squareCrop
Out[8]=

Alternatively, it’s also possible to manually resize the output image to the dimensions of the original image:

In[9]:=
ImageResize[
 NetModel["U2-Net Portrait Generator Trained on APDrawing Data"]@
  nonSquareImg, ImageDimensions[nonSquareImg]]
Out[9]=

Net information

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

In[10]:=
Information[
 NetModel[
  "U2-Net Portrait Generator Trained on APDrawing Data"], "ArraysElementCounts"]
Out[10]=

Obtain the total number of parameters:

In[11]:=
Information[
 NetModel[
  "U2-Net Portrait Generator Trained on APDrawing Data"], "ArraysTotalElementCount"]
Out[11]=

Obtain the layer type counts:

In[12]:=
Information[
 NetModel[
  "U2-Net Portrait Generator Trained on APDrawing Data"], "LayerTypeCounts"]
Out[12]=

Display the summary graphic:

In[13]:=
Information[
 NetModel[
  "U2-Net Portrait Generator Trained on APDrawing Data"], "SummaryGraphic"]
Out[13]=

Resource History

Reference