Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import h5py
  2. import numpy as np
  3. import tensorflow as tf
  4. import matplotlib.pyplot as plt
  5. import math as math
  6. import scipy
  7.  
  8. f = h5py.File('/Users/Krzysztof/PycharmProjects/untitled/venv/4studs.hdf5', 'r')
  9.  
  10. keys = list(f.keys())
  11.  
  12. def wejscie(k): #zwraca (1, 32, 6250, 1)
  13. x = f.get(keys[k])
  14. x1 = tf.slice(x,[0,0],[32,6250])
  15. x2 = tf.reshape(x1,[1,32,6250,1])
  16. x3 = tf.keras.utils.normalize(x2)
  17. return x3
  18.  
  19. def wyjscie(k): #zwraca (1, 1, 1, 6211)
  20. x = f.get(keys[180+k])
  21. x1 = tf.slice(x,[0],[6211])
  22. x2 = tf.reshape(x1,[1,1,1,6211])
  23. return x2
  24.  
  25. #MODEL
  26. model = tf.keras.Sequential([
  27. tf.keras.layers.Conv2D(64, kernel_size=(32,40),padding='valid',input_shape=(32,6250,1)),
  28. tf.keras.layers.Dense(32,activation='tanh'),
  29. tf.keras.layers.Dense(1,activation='linear')
  30. ])
  31. model.compile(optimizer='nadam',loss='mse',metrics=['accuracy'])
  32.  
  33. for n in range(1):
  34. model.fit(wejscie(n),wyjscie(n),epochs=3)
  35. pred = model.predict(wejscie(179))
  36. print(pred.shape)
  37.  
  38. pred1 = tf.reshape(pred,[-1,1,6211])
  39. pred2 = tf.reshape(pred1,[-1,6211])
  40. pred3 = tf.reshape(pred2,[6211])
  41. plt.figure()
  42. plt.plot(pred3)
  43. plt.plot(f.get(keys[359]))
  44. plt.show()
  45.  
  46. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement