Wolfram Computation Meets Knowledge

Pix2pix Photo-to-Street-Map Translation

Generate a street map from a satellite photo

Released in 2016, this model is an application of a powerful method for general-purpose image-to-image translation using conditional adversarial networks. The automatic learning of the loss function with the adversarial networks technique allows the same paradigm to generalize across a wide range of image translation tasks. The architecture enables an efficient aggregation of features of multiple scales through skip connections with concatenations. This particular model was trained to generate a street map from a satellite photo.

Number of layers: 56 | Parameter count: 54,419,459 | Trained size: 218 MB

Training Set Information

Examples

Resource retrieval

Retrieve the resource object:

In[1]:=
ResourceObject["Pix2pix Photo-To-Street-Map Translation"]
Out[1]=

Get the pre-trained net:

In[2]:=
NetModel["Pix2pix Photo-To-Street-Map Translation"]
Out[2]=

Basic usage

Obtain a satellite photo:

In[3]:=
img = ImageResize[
  GeoImage[Entity["City", {"LasVegas", "Nevada", "UnitedStates"}], 
   GeoRange -> 200], {256, 256}]
Out[3]=

Use the net to draw the street map:

In[4]:=
map = NetModel["Pix2pix Photo-To-Street-Map Translation"][img]
Out[4]=

Evaluate accuracy

Overlap photo and prediction:

In[5]:=
ImageCompose[img, SetAlphaChannel[map, 0.8]]
Out[5]=

Obtain the actual street map:

In[6]:=
actualMap = 
 ImageResize[
  GeoImage[Entity["City", {"LasVegas", "Nevada", "UnitedStates"}], 
   "StreetMap", GeoRange -> 200], {256, 256}]
Out[6]=

Compare the generated street map with the actual street map:

In[7]:=
ImageAssemble[{map, actualMap}]
Out[7]=

Issues

More complex patterns are harder to render. Obtain a new photo and street map pair:

In[8]:=
{img, actualMap} = 
 ImageResize[
    GeoImage[GeoPosition[{41.940360, 12.533762}], #, 
     GeoRange -> 200], {256, 256}] & /@ {"Satellite", "StreetMap"}
Out[8]=

Compare the prediction with the actual street map:

In[9]:=
ImageAssemble[{NetModel["Pix2pix Photo-To-Street-Map Translation"][
   img], actualMap}]
Out[9]=

Net information

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

In[10]:=
NetInformation[
 NetModel["Pix2pix Photo-To-Street-Map Translation"], \
"ArraysElementCounts"]
Out[10]=

Obtain the total number of parameters:

In[11]:=
NetInformation[
 NetModel["Pix2pix Photo-To-Street-Map Translation"], \
"ArraysTotalElementCount"]
Out[11]=

Obtain the layer type counts:

In[12]:=
NetInformation[
 NetModel["Pix2pix Photo-To-Street-Map Translation"], \
"LayerTypeCounts"]
Out[12]=

Display the summary graphic:

In[13]:=
NetInformation[
 NetModel["Pix2pix Photo-To-Street-Map Translation"], \
"SummaryGraphic"]
Out[13]=

Export to MXNet

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

In[14]:=
jsonPath = 
 Export[FileNameJoin[{$TemporaryDirectory, "net.json"}], 
  NetModel["Pix2pix Photo-To-Street-Map Translation"], "MXNet"]
Out[14]=

Export also creates a net.params file containing parameters:

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

Get the size of the parameter file:

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

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

In[17]:=
ResourceObject["Pix2pix Photo-To-Street-Map Translation"]["ByteCount"]
Out[17]=

Represent the MXNet net as a graph:

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

Requirements

Wolfram Language 11.2 (September 2017) or above

Reference