close
The Wayback Machine - https://web.archive.org/web/20240419052924/https://resources.wolframcloud.com/NeuralNetRepository/resources/CycleGAN-Photo-to-Monet-Translation/

CycleGAN Photo-to-Monet Translation

Turn a photo into a Monet-style painting

Released in 2017, this model exploits a novel technique for image translation, in which two models translating from A to B and vice versa are trained jointly with adversarial training. In addition to the adversarial loss, cycle consistency is also enforced in the loss function: when the output of the first translator is fed into the second, the final result is encouraged to match the input of the first translator. This allows successful training for image translation tasks in which only unpaired training data can be collected. This model was trained to translate photos into Monet-style paintings.

Number of layers: 94 | Parameter count: 2,855,811 | Trained size: 12 MB |

Training Set Information

Examples

Resource retrieval

Get the pre-trained net:

In[1]:=
NetModel["CycleGAN Photo-to-Monet Translation"]
Out[1]=
BERJAYA

Basic usage

Run the net on a photo:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/dd2fc56d-a920-4973-9e1c-1c9a871c4903"]
Out[2]=
BERJAYA

Adapt to any size

Automatic image resizing can be avoided by replacing the net encoders. First get the net:

In[3]:=
net = NetModel["CycleGAN Photo-to-Monet Translation"]
Out[3]=
BERJAYA

Get a photo:

In[4]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/a0327f7d-ddc3-4bcd-beef-94f80eddcfa9"]

Create a new encoder with the desired dimensions:

In[5]:=
netEnc = NetEncoder[{"Image", ImageDimensions[img]}]
Out[5]=
BERJAYA

Attach the new net encoder and run the network:

In[6]:=
resizedNet = NetReplacePart[
  net, {"Input" -> netEnc, "Output" -> NetDecoder[{"Image"}]}]
Out[6]=
BERJAYA
In[7]:=
resizedNet[img]
Out[7]=
BERJAYA

Net information

Inspect the sizes of all arrays in the net:

In[8]:=
NetInformation[
 NetModel["CycleGAN Photo-to-Monet Translation"], "ArraysSizes"]
Out[8]=
BERJAYA

Obtain the total number of parameters:

In[9]:=
NetInformation[
 NetModel["CycleGAN Photo-to-Monet Translation"], \
"ArraysTotalElementCount"]
Out[9]=
BERJAYA

Obtain the layer type counts:

In[10]:=
NetInformation[
 NetModel["CycleGAN Photo-to-Monet Translation"], "LayerTypeCounts"]
Out[10]=
BERJAYA

Display the summary graphic:

In[11]:=
NetInformation[
 NetModel["CycleGAN Photo-to-Monet Translation"], "SummaryGraphic"]
Out[11]=
BERJAYA

Export to MXNet

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

In[12]:=
jsonPath = Export[FileNameJoin[{$TemporaryDirectory, "net.json"}], NetModel["CycleGAN Photo-to-Monet Translation"], "MXNet"]
Out[12]=
BERJAYA

Export also creates a net.params file containing parameters:

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

Get the size of the parameter file:

In[14]:=
FileByteCount[paramPath]
Out[14]=
BERJAYA

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

In[15]:=
ResourceObject["CycleGAN Photo-to-Monet Translation"]["ByteCount"]
Out[15]=
BERJAYA

Represent the MXNet net as a graph:

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

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

Reference