Guest User

Untitled

a guest
Dec 15th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. from keras.layers import Input, Dense, Conv1D, MaxPooling1D, UpSampling1D
  2. from keras.models import Model
  3. from keras import backend as K
  4. import scipy as scipy
  5. import numpy as np
  6. import matplotlib.pyplot as plt
  7. from scipy.cluster.vq import whiten
  8.  
  9. mat = scipy.io.loadmat('bcgdata.mat')
  10. emat = mat['bcgdata']
  11. #whiten(emat)
  12. emat = emat / np.max(emat)
  13. #emat = emat-np.min(emat)
  14.  
  15. input_img = Input(shape=(64,1)) # adapt this if using `channels_first` image data format
  16. encoded = Dense(16, activation='relu')(input_img)
  17. encoded = Dense(8, activation='relu')(encoded)
  18.  
  19. decoded = Dense(16, activation='relu')(encoded)
  20. decoded = Dense(1, activation='relu')(decoded)
  21.  
  22. autoencoder = Model(input_img, decoded)
  23. autoencoder.compile(optimizer='SGD', loss='mean_squared_error')
  24. autoencoder.summary()
  25.  
  26. x_train = np.transpose(emat[:,0:50000])
  27. x_train = np.expand_dims(x_train,axis=2)
  28. #x_train = np.reshape(x_train, (x_train.shape[1], 64, 1))
  29. x_test = np.transpose(emat[:,50000:80000])
  30. x_test = np.expand_dims(x_test,axis=2)
  31. #x_test = np.reshape(x_test, (x_test.shape[1], 64, 1))
  32.  
  33. from keras.callbacks import TensorBoard
  34.  
  35. autoencoder.fit(x_train, x_train,
  36. epochs=50,
  37. batch_size=150,
  38. shuffle=True,
  39. validation_data=(x_test, x_test),
  40. callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])
  41.  
  42.  
  43. preds = autoencoder.predict(x_test)
  44. plt.plot(x_test[0:500,1,0])
  45. plt.plot(preds[0:500,1,0])
  46. plt.show()
Add Comment
Please, Sign In to add comment