Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.layers import Input, Dense, Conv1D, MaxPooling1D, UpSampling1D
- from keras.models import Model
- from keras import backend as K
- import scipy as scipy
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy.cluster.vq import whiten
- mat = scipy.io.loadmat('bcgdata.mat')
- emat = mat['bcgdata']
- #whiten(emat)
- emat = emat / np.max(emat)
- #emat = emat-np.min(emat)
- input_img = Input(shape=(64,1)) # adapt this if using `channels_first` image data format
- encoded = Dense(16, activation='relu')(input_img)
- encoded = Dense(8, activation='relu')(encoded)
- decoded = Dense(16, activation='relu')(encoded)
- decoded = Dense(1, activation='relu')(decoded)
- autoencoder = Model(input_img, decoded)
- autoencoder.compile(optimizer='SGD', loss='mean_squared_error')
- autoencoder.summary()
- x_train = np.transpose(emat[:,0:50000])
- x_train = np.expand_dims(x_train,axis=2)
- #x_train = np.reshape(x_train, (x_train.shape[1], 64, 1))
- x_test = np.transpose(emat[:,50000:80000])
- x_test = np.expand_dims(x_test,axis=2)
- #x_test = np.reshape(x_test, (x_test.shape[1], 64, 1))
- from keras.callbacks import TensorBoard
- autoencoder.fit(x_train, x_train,
- epochs=50,
- batch_size=150,
- shuffle=True,
- validation_data=(x_test, x_test),
- callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])
- preds = autoencoder.predict(x_test)
- plt.plot(x_test[0:500,1,0])
- plt.plot(preds[0:500,1,0])
- plt.show()
Add Comment
Please, Sign In to add comment