# 3.20. Auto-encoder with Conv2D¶

In [1]:

from conx import *

Using TensorFlow backend.
/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
return f(*args, **kwds)
conx, version 3.5.15

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), colormap="gray", activation="relu"))
net.add(Conv2DLayer("Conv2D-2", 132, (5,5), activation="relu"))
net.add(Layer("output", 28 * 28, vshape=(28,28), activation='softmax'))
net.connect()

In [3]:

net.compile(error="mse", optimizer="adam")

In [4]:

net.dataset.get("mnist")

In [5]:

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 [6]:

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 [7]:

net.dataset.targets.reshape(28 * 28)

In [8]:

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 [9]:

net.dashboard()

In [10]:

np.min(net.propagate_to("input", net.dataset.inputs[0]))

Out[10]:

0.0

In [11]:

net["maxpool1"].activation

In [12]:

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)

========================================================================
|  Training |  Training |  Validate |  Validate
Epochs |     Error |  Accuracy |     Error |  Accuracy
------ | --------- | --------- | --------- | ---------
#   50 |   0.10628 |   0.00000 |   0.10314 |   0.00000