由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

Tensorflow

  1. ##!/usr/locol/bin/python3.6
  2. import tensorflow as tf
  3. import numpy as np
  4. ## creat data
  5. x_data = np.random.rand(100).astype(np.float32)
  6. y_data = x_data*0.1 + 0.3
  7. #### creat tnsorflow structure start
  8. Weights = tf.Variable(tf.random_uniform([1],-1.0,1.0))
  9. biases = tf.Variable(tf.zeros([1]))
  10. y = Weightess =tf.Session()
  11. *x_data + biases
  12. loss = tf.reduce_mean(tf.square(y - y_data))
  13. optimizer = tf.train.GradientDescentOptimizer(0.5)
  14. train = optimizer.minimize(loss)
  15. init = tf.initialize_all_variables()
  16. ###create tensorflow structure end ###
  17. sess =tf.Session()
  18. sess.run(init)
  19. for step in range(201):
  20. sess.run(train)
  21. if step % 20 == 0:
  22. print(step, sess.run(Weights),sess.run(biases))
  23. #### add a laier###
  24. def add_layer(inputs, in_size, out_size, activation_function=None):
  25. Weights = tf.Variable(tf.random_normal([in_size, out_size]))
  26. biases = tf.Variable(tf.zeros([1, out_size]) + 0.1)
  27. Wx_plus_b = tf.matmul(inputs, Weights) + biases
  28. if activation_function is None:
  29. outputs = Wx_plus_b
  30. else:
  31. outputs = activation_function(Wx_plus_b)
  32. return outputs
  33. ##################
  34. ###From https://tensorflow.google.cn/get_started/premade_estimators##
  35. #############

Enjoy~

本文由Python腳本GitHub/語雀自動更新

由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

GitHub: Karobben
Blog:Karobben
BiliBili:史上最不正經的生物狗