3.20. Auto-encoder with Conv2DΒΆ

In [22]:
from conx import *
In [23]:
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'))
net.connect()
In [24]:
net.compile(error="mse", optimizer="adam")
In [25]:
net.dataset.get("mnist")
In [26]:
net.dataset.summary()

Dataset name: MNIST

Original source: http://yann.lecun.com/exdb/mnist/

The MNIST database of handwritten digits, available from this page, has 70,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image. It is a good database for people who want to try learning techniques and pattern recognition methods on real-world data while spending minimal efforts on preprocessing and formatting.

Dataset Split: * training : 70000 * testing : 0 * total : 70000

Input Summary: * shape : [(28, 28, 1)] * range : [(0.0, 1.0)]

Target Summary: * shape : [(10,)] * range : [(0.0, 1.0)]

In [27]:
net.dataset.set_targets_from_inputs()
WARNING: network 'Auto-Encoding with Conv' target bank #0 has a multi-dimensional shape, which is not allowed
In [28]:
net.dataset.targets.reshape(28 * 28)
In [29]:
net.dataset.summary()

Dataset name: MNIST

Original source: http://yann.lecun.com/exdb/mnist/

The MNIST database of handwritten digits, available from this page, has 70,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image. It is a good database for people who want to try learning techniques and pattern recognition methods on real-world data while spending minimal efforts on preprocessing and formatting.

Dataset Split: * training : 70000 * testing : 0 * total : 70000

Input Summary: * shape : [(28, 28, 1)] * range : [(0.0, 1.0)]

Target Summary: * shape : [(784,)] * range : [(0.0, 1.0)]

In [30]:
net.dashboard()
In [31]:
net.dataset.chop(100)
In [32]:
net.dataset.split(0.1)
In [33]:
net.dataset.summary()

Dataset name: MNIST

Original source: http://yann.lecun.com/exdb/mnist/

The MNIST database of handwritten digits, available from this page, has 70,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image. It is a good database for people who want to try learning techniques and pattern recognition methods on real-world data while spending minimal efforts on preprocessing and formatting.

Dataset Split: * training : 90 * testing : 10 * total : 100

Input Summary: * shape : [(28, 28, 1)] * range : [(0.0, 1.0)]

Target Summary: * shape : [(784,)] * range : [(0.0, 1.0)]

In [34]:
net.reset()
net.train(50, plot=True)
_images/Auto-encoder_with_Conv2D_13_0.svg
========================================================================
       |  Training |  Training |  Validate |  Validate
Epochs |     Error |  Accuracy |     Error |  Accuracy
------ | --------- | --------- | --------- | ---------
#   50 |   0.10628 |   0.00000 |   0.10314 |   0.00000