@@ -0,0 +1,2680 @@
+import numpy as np%0Afrom keras.layers import Input, Dense, Convolution2D, MaxPooling2D, UpSampling2D%0Afrom keras.models import Model%0Afrom keras.datasets import mnist%0Aimport matplotlib.pyplot as plt%0A%0A# https://blog.keras.io/building-autoencoders-in-keras.html%0A%0Aif __name__ == %22__main__%22:%0A    # create model%0A    # 4D tensor dim_ordering is (samples, rows, cols, channels) as default (tf)%0A    input_img = Input(shape=(28, 28, 1))%0A%0A    x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(input_img)%0A    x = MaxPooling2D((2, 2), border_mode='same')(x)%0A    x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)%0A    x = MaxPooling2D((2, 2), border_mode='same')(x)%0A    x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)%0A    encoded = MaxPooling2D((2, 2), border_mode='same')(x)%0A%0A    # at this point the representation is (8, 4, 4)%0A%0A    x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(encoded)%0A    x = UpSampling2D((2, 2))(x)%0A    x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)%0A    x = UpSampling2D((2, 2))(x)%0A    x = Convolution2D(16, 3, 3, activation='relu')(x)%0A    x = UpSampling2D((2, 2))(x)%0A    decoded = Convolution2D(1, 3, 3, activation='sigmoid', border_mode='same')(x)%0A%0A    autoencoder = Model(input_img, decoded)%0A    from keras.utils.visualize_util import plot%0A    plot(autoencoder, to_file='architecture.png', show_shapes=True)%0A    %0A    # compile model%0A    autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')%0A%0A    # load mnist datasets%0A    (X_train, _), (X_test, _) = mnist.load_data()%0A%0A    X_train = X_train.astype('float32') / 255.0%0A    X_test = X_test.astype('float32') / 255.0%0A%0A    X_train = np.reshape(X_train, (len(X_train), 28, 28, 1))%0A    X_test = np.reshape(X_test, (len(X_test), 28, 28, 1))%0A%0A    print(X_train.shape)%0A    print(X_test.shape)%0A%0A    # train model%0A    autoencoder.fit(X_train, X_train,%0A                    nb_epoch=1,%0A                    batch_size=128,%0A                    shuffle=True,%0A                    validation_data=(X_test, X_test))%0A%0A    # encode and decode some digits%0A    decoded_imgs = autoencoder.predict(X_test)%0A%0A    n = 10%0A    plt.figure(figsize=(20, 4))%0A    for i in range(n):%0A        # display original%0A        ax = plt.subplot(2, n, i + 1)%0A        plt.imshow(X_test%5Bi%5D.reshape(28, 28))%0A        plt.gray()%0A        ax.get_xaxis().set_visible(False)%0A        ax.get_yaxis().set_visible(False)%0A%0A        # display reconstruction%0A        ax = plt.subplot(2, n, i + 1 + n)%0A        plt.imshow(decoded_imgs%5Bi%5D.reshape(28, 28))%0A        plt.gray()%0A        ax.get_xaxis().set_visible(False)%0A        ax.get_yaxis().set_visible(False)%0A    plt.show()%0A

Add mnist_conv_autoencoder.py