3.21. Auto-encoder with Conv2DΒΆ

In [1]:
from conx import *
conx, version 3.4.0
Using Theano backend.
In [2]:
net = Network("Auto-Encoding with Conv")
net.add(Layer("input", (28,28,1), colormap="hot", minmax=(0,1)))
net.add(Conv2DLayer("Conv2D-1", 16, (5,5), activation="relu"))
net.add(MaxPool2DLayer("maxpool1", (2,2)))
net.add(Conv2DLayer("Conv2D-2", 132, (5,5), activation="relu"))
net.add(MaxPool2DLayer("maxpool2", (2,2)))
net.add(FlattenLayer("flatten", visible=True))
net.add(Layer("output", 28 * 28, vshape=(28,28), activation='softmax'))
In [3]:
net.connect()
In [4]:
net.dataset.get("mnist")
In [5]:
net.compile(error="mse", optimizer="adam")
In [6]:
net.dashboard()
In [7]:
net.dataset.summary()
Input Summary:
   count  : 70000 (70000 for training, 0 for testing)
   shape  : [(28, 28, 1)]
   range  : (0.0, 1.0)
Target Summary:
   count  : 70000 (70000 for training, 0 for testing)
   shape  : [(10,)]
   range  : (0.0, 1.0)
In [8]:
net.dataset.set_targets_from_inputs()
In [9]:
net.dataset.summary()
Input Summary:
   count  : 70000 (70000 for training, 0 for testing)
   shape  : [(28, 28, 1)]
   range  : (0.0, 1.0)
Target Summary:
   count  : 70000 (70000 for training, 0 for testing)
   shape  : [(28, 28, 1)]
   range  : (0.0, 1.0)
In [10]:
net.dataset.targets.reshape(28*28)
In [11]:
net.dataset.summary()
Input Summary:
   count  : 70000 (70000 for training, 0 for testing)
   shape  : [(28, 28, 1)]
   range  : (0.0, 1.0)
Target Summary:
   count  : 70000 (70000 for training, 0 for testing)
   shape  : [(784,)]
   range  : (0.0, 1.0)
In [23]:
net.dataset.chop(100)
In [24]:
net.dataset.split(0.1)
In [26]:
net.dataset.summary()
Input Summary:
   count  : 100 (90 for training, 10 for testing)
   shape  : [(28, 28, 1)]
   range  : (0.0, 1.0)
Target Summary:
   count  : 100 (90 for training, 10 for testing)
   shape  : [(784,)]
   range  : (0.0, 1.0)
In [29]:
net.reset()
net.train(50, plot=True)
_images/Auto-encoder_with_Conv2D_15_0.svg
========================================================================
       |  Training |  Training |  Validate |  Validate
Epochs |     Error |  Accuracy |     Error |  Accuracy
------ | --------- | --------- | --------- | ---------
#   50 |   0.10623 |   0.00000 |   0.10319 |   0.00000