below, an offline regression model is used to record the saving model and load model to make predictions .
Reference Articles:http://blog.csdn.net/thriving_fcl/article/details/71423039
train an offline regression model and save a look at the code:
Import TensorFlow as TF import numpy as NP import Matplotlib.pyplot as Plt Money=np.array ([[[109],[82],[99], [72], [87], [ [To], [to], [Astype], [+]]. Np.float32 Click=np.array ([[One], [8], [8], [6],[7], [7], [7], [8], [9], [5]]). Astyp E (Np.float32) x_test=money[0:5].reshape ( -1,1) y_test=click[0:5] X_train=money[5:].reshape ( -1,1) y_train=click[5:] X =tf.placeholder (tf.float32,[none,1],name= ' x ') #保存要输入的格式 W=TF. Variable (Tf.zeros ([1,1])) B=TF. Variable (Tf.zeros ([1])) Y=tf.matmul (x,w) +b tf.add_to_collection (' pred_network ', y) #用于加载模型获取要预测的网络结构 y_= Tf.placeholder (tf.float32,[none,1]) cost=tf.reduce_sum (Tf.pow ((Y-y_), 2)) train_step= Tf.train.GradientDescentOptimizer (0.000001). Minimize (cost) Init=tf.global_variables_initializer () sess=tf. Session () Sess.run (init) cost_history=[] saver = Tf.train.Saver () to I in range (MB): Feed={x:x_train,y_:y_train} SESS.R Un (train_step,feed_dict=feed) cost_history.append (Sess.run (cost,feed_dict=feed)) # outputs the final w,b and cost value of print ("109 of the predicted value is: ", Sess.run (Y, Feed_dICT={X: [[[109]]}) Print ("W_value:%f"% Sess.run (W), "B_value:%f"% Sess.run (b), "Cost_value:%f"% sess.run (cost, Feed_ dict=feed)) Saver_path = Saver.save (Sess, "/users/shuubiasahi/desktop/tensorflow/mod