Guest User

Untitled

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import plaidml.keras
  2. plaidml.keras.install_backend()
  3.  
  4. import math
  5. import numpy as np
  6. from keras.models import Sequential
  7. from keras.layers import Dense
  8.  
  9. batch_size = 1024
  10.  
  11. def genxy():
  12. pi2 = math.pi * 2
  13. while True:
  14. x = np.random.rand(batch_size)
  15. y = np.sin(x * pi2)
  16. yield (x, y)
  17.  
  18. model = Sequential()
  19. model.add(Dense(2, activation='relu', input_shape=(1, )))
  20. model.add(Dense(4, activation='relu'))
  21. model.add(Dense(8, activation='relu'))
  22. model.add(Dense(16, activation='relu'))
  23. model.add(Dense(32, activation='relu'))
  24. model.add(Dense(1, name='output'))
  25. model.compile(loss='mean_squared_error', optimizer='nadam')
  26. model.fit_generator(
  27. genxy(),
  28. 1024,
  29. 4,
  30. verbose=2,
  31. validation_data=genxy(),
  32. validation_steps=1,
  33. )
Add Comment
Please, Sign In to add comment