Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.layers import Input, Dense, Conv2D, Conv3D, LSTM, Flatten, Conv2DTranspose, MaxPooling2D, UpSampling2D, Conv3DTranspose, UpSampling3D, MaxPooling3D
- from keras.models import Model, Sequential
- from keras.datasets import mnist
- import numpy as np
- from sklearn.model_selection import train_test_split
- from keras.utils import to_categorical
- # use Matplotlib (don't ask)
- import matplotlib.pyplot as plt
- # this is the size of our encoded representations
- encoding_dim = 64 # 32 floats -> compression of factor 24.5, assuming the input is 784 floats
- '''
- # this is our input placeholder
- input_img = Input(shape=(1440000,))
- # "encoded" is the encoded representation of the input
- encoded = Dense(encoding_dim, activation='relu')(input_img)
- # "decoded" is the lossy reconstruction of the input
- decoded = Dense(1440000, activation='sigmoid')(encoded)
- # this model maps an input to its reconstruction
- autoencoder = Model(input_img, decoded)
- # this model maps an input to its encoded representation
- encoder = Model(input_img, encoded)
- # create a placeholder for an encoded (32-dimensional) input
- encoded_input = Input(shape=(encoding_dim,))
- # retrieve the last layer of the autoencoder model
- decoder_layer = autoencoder.layers[-1]
- # create the decoder model
- decoder = Model(encoded_input, decoder_layer(encoded_input))
- '''
- autoencoder = Sequential()
- autoencoder.add(Conv3D(64, kernel_size=3, activation='relu', input_shape=(99,75,120,160)))
- autoencoder.add(MaxPooling3D(pool_size=2))
- autoencoder.add(Conv3D(32, kernel_size=3, activation='relu'))
- autoencoder.add(MaxPooling3D(pool_size=2))
- autoencoder.add(Conv3D(16, kernel_size=3, activation='relu'))
- autoencoder.add(MaxPooling3D(pool_size=2))
- '''
- autoencoder.add(Flatten())
- autoencoder.add(Dense(encoding_dim))
- '''
- autoencoder.add(Conv3DTranspose(16, kernel_size=3, activation='relu', data_format="channels_last"))
- autoencoder.add(UpSampling3D(size=2))
- autoencoder.add(Conv3DTranspose(32, kernel_size=3, activation='relu'))
- autoencoder.add(UpSampling3D(size=2))
- autoencoder.add(Conv3DTranspose(64, kernel_size=3, activation='relu'))
- autoencoder.compile(optimizer='adagrad', loss='mse')
- #split data to test and train
- data = np.load(r"C:Usersshj_kDesktopProjecthandclapping.npy")
- data = to_categorical(data)
- print (data.shape)
- (x_train,x_test) = train_test_split(data)
- #print("Xtrain",x_train)
- x_train = x_train.astype('float32') / 255.
- x_test = x_test.astype('float32') / 255.
- x_train = x_train.reshape((len(x_train), np.prod(x_train.shape[1:])))
- x_test = x_test.reshape((len(x_train), np.prod(x_train.shape[1:])))
- print (x_train.shape)
- print (x_test.shape)
- autoencoder.fit(x_train, x_train,
- epochs=100,
- batch_size=25,
- shuffle=False,
- validation_data=(x_test, x_test))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement