def test_dataset(): """ Load Virtual MNIST dataset after network creation. """ net = Network("MNIST") net.add(Layer("input", shape=784, vshape=(28, 28), colormap="hot", minmax=(0,1))) net.add(Layer("hidden1", shape=512, vshape=(16,32), activation='relu', dropout=0.2)) net.add(Layer("hidden2", shape=512, vshape=(16,32), activation='relu', dropout=0.2)) net.add(Layer("output", shape=10, activation='softmax')) net.connect('input', 'hidden1') net.connect('hidden1', 'hidden2') net.connect('hidden2', 'output') net.compile(optimizer="adam", error="binary_crossentropy") net.get_dataset("mnist") assert net is not None net.dataset.clear()
def test_images(): net = Network("MNIST") net.get_dataset("mnist") assert net.dataset.inputs.shape == [(28,28,1)] net.add(Layer("input", shape=(28, 28, 1), colormap="hot", minmax=(0,1))) net.add(FlattenLayer("flatten")) net.add(Layer("hidden1", shape=512, vshape=(16,32), activation='relu', dropout=0.2)) net.add(Layer("hidden2", shape=512, vshape=(16,32), activation='relu', dropout=0.2)) net.add(Layer("output", shape=10, activation='softmax')) net.connect('input', 'flatten') net.connect('flatten', 'hidden1') net.connect('hidden1', 'hidden2') net.connect('hidden2', 'output') net.compile(optimizer="adam", error="binary_crossentropy") svg = net.to_svg() assert svg is not None net.dataset.clear()
def test_cifar10(): """ Test the cifar10 API and training. """ from conx import Network, Layer, Conv2DLayer, MaxPool2DLayer, FlattenLayer batch_size = 32 num_classes = 10 epochs = 200 data_augmentation = True num_predictions = 20 net = Network("CIRAR10") net.add(Layer("input", (32, 32, 3))) net.add(Conv2DLayer("conv1", 32, (3, 3), padding='same', activation='relu')) net.add(Conv2DLayer("conv2", 32, (3, 3), activation='relu')) net.add(MaxPool2DLayer("pool1", pool_size=(2, 2), dropout=0.25)) net.add(Conv2DLayer("conv3", 64, (3, 3), padding='same', activation='relu')) net.add(Conv2DLayer("conv4", 64, (3, 3), activation='relu')) net.add(MaxPool2DLayer("pool2", pool_size=(2, 2), dropout=0.25)) net.add(FlattenLayer("flatten")) net.add(Layer("hidden1", 512, activation='relu', vshape=(16, 32), dropout=0.5)) net.add(Layer("output", num_classes, activation='softmax')) net.connect() # initiate RMSprop optimizer opt = RMSprop(lr=0.0001, decay=1e-6) net.compile(error='categorical_crossentropy', optimizer=opt) net.get_dataset("cifar10") widget = net.dashboard() widget.goto("begin") widget.goto("next") widget.goto("end") widget.goto("prev") widget.prop_one() net.dataset.slice(10) net.dataset.shuffle() net.dataset.split(.5) net.train(plot=False) net.propagate(net.dataset.inputs[0]) net.dataset.clear()