Created
October 2, 2017 03:34
-
-
Save briandw/f8730210af19a936d1ec8f2fdf810e1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from keras.layers import Input, Dense\n", | |
"from keras.models import Model\n", | |
"\n", | |
"# this is the size of our encoded representations\n", | |
"encoding_dim = 32 # 32 floats, \n", | |
"array_size = imageSize*imageSize\n", | |
"# this is our input placeholder\n", | |
"input_img = Input(shape=(array_size,))\n", | |
"# \"encoded\" is the encoded representation of the input\n", | |
"encoded = Dense(encoding_dim, activation='relu')(input_img)\n", | |
"# \"decoded\" is the lossy reconstruction of the input\n", | |
"decoded = Dense(array_size, activation='sigmoid')(encoded)\n", | |
"\n", | |
"# this model maps an input to its reconstruction\n", | |
"autoencoder = Model(input_img, decoded)\n", | |
"\n", | |
"encoder = Model(input_img, encoded)\n", | |
"\n", | |
"# create a placeholder for an encoded (32-dimensional) input\n", | |
"encoded_input = Input(shape=(encoding_dim,))\n", | |
"# retrieve the last layer of the autoencoder model\n", | |
"decoder_layer = autoencoder.layers[-1]\n", | |
"# create the decoder model\n", | |
"decoder = Model(encoded_input, decoder_layer(encoded_input))\n", | |
"\n", | |
"autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"batch_size = 128\n", | |
"training_images = imageSet(batchSize=batch_size, imageSize=imageSize, dotsPerSide=4)\n", | |
"training_images = training_images.reshape((len(training_images), np.prod(training_images.shape[1:])))\n", | |
"for i in range(0,500):\n", | |
" autoencoder.fit(training_images, training_images,\n", | |
" epochs=1,\n", | |
" batch_size=batch_size)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment