Advertisement
Deerenaros

tensorflow homework

Nov 28th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. from __future__ import absolute_import, division, print_function, unicode_literals
  2. import tensorflow as tf
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. xx = np.arange (-5, 10, 0.5)
  6. yy = 3*xx**2 - 2*xx + 1
  7. print (xx)
  8. print (yy)
  9. print("версия Tensorflow:", tf.__version__)
  10. print("используемое GPU:", tf.test.gpu_device_name())
  11. xx = np.array(xx)
  12. yy = np.array(yy, dtype=float)
  13. for i, c in enumerate(xx):
  14.   print("{} xx= {} yy "
  15.   .format(c, yy[i]))
  16. l0 = tf.keras.layers.Dense(units=1, input_shape=[1])
  17. model = tf.keras.Sequential([l0])
  18. model.compile(loss='mean_squared_logarithmic_error', optimizer=tf.keras.optimizers.Adam(0.1))
  19. history = model.fit(xx, yy, epochs=3000, verbose=False)
  20. print ("Завершили тренировку модели")
  21. plt.xlabel('Epoch')
  22. plt.ylabel('Loss')
  23. plt.plot(history.history['loss'])
  24. print(model.predict([-10.0]))
  25. print("Это значения переменных слоя: {}".format(l0.get_weights()))
  26.  
  27.  
  28. xx = np.linspace(-100, 100, 1000)
  29. yy = np.sin(xx)
  30.  
  31. plt.plot(xx, yy)
  32. plt.show()
  33.  
  34.  
  35.  
  36. from __future__ import absolute_import, division, print_function, unicode_literals
  37. import tensorflow as tf
  38. import numpy as np
  39. import matplotlib.pyplot as plt
  40.  
  41. xx = np.linspace(-100, 100, 1000)
  42. yy = np.sin(xx)
  43.  
  44. plt.plot(xx, yy)
  45. plt.show()
  46.  
  47. print("версия Tensorflow:", tf.__version__)
  48. print("используемое GPU:", tf.test.gpu_device_name())
  49. for i, c in enumerate(xx):
  50.   print("{} xx= {} yy "
  51.   .format(c, yy[i]))
  52. l0 = tf.keras.layers.Dense(units=1, input_shape=[1])
  53. model = tf.keras.Sequential([l0])
  54. model.compile(loss='mean_squared_logarithmic_error', optimizer=tf.keras.optimizers.Adam(0.1))
  55. history = model.fit(xx, yy, epochs=3000, verbose=False)
  56. print ("Завершили тренировку модели")
  57. plt.xlabel('Epoch')
  58. plt.ylabel('Loss')
  59. plt.plot(history.history['loss'])
  60. print(model.predict([-10.0]))
  61. print("Это значения переменных слоя: {}".format(l0.get_weights()))
  62.  
  63.  
  64.  
  65. from __future__ import absolute_import, division, print_function, unicode_literals
  66. import tensorflow as tf
  67. import numpy as np
  68. import matplotlib.pyplot as plt
  69. xx = np.linspace(-2, 2, 100)
  70. yy = np.exp(xx + 2)
  71.  
  72. plt.plot(xx, yy)
  73. plt.show()
  74. print("версия Tensorflow:", tf.__version__)
  75. print("используемое GPU:", tf.test.gpu_device_name())
  76. xx = np.array(xx)
  77. yy = np.array(yy, dtype=float)
  78. for i, c in enumerate(xx):
  79.   print("{} xx= {} yy "
  80.   .format(c, yy[i]))
  81. l0 = tf.keras.layers.Dense(units=1, input_shape=[1])
  82. model = tf.keras.Sequential([l0])
  83. model.compile(loss='mean_squared_logarithmic_error', optimizer=tf.keras.optimizers.Adam(0.1))
  84. history = model.fit(xx, yy, epochs=3000, verbose=False)
  85. print ("Завершили тренировку модели")
  86. plt.xlabel('Epoch')
  87. plt.ylabel('Loss')
  88. plt.plot(history.history['loss'])
  89. print(model.predict([-10.0]))
  90. print("Это значения переменных слоя: {}".format(l0.get_weights()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement