国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

TensorFlow實現保存訓練模型為pd文件并恢復

2020-02-15 21:21:37
字體:
來源:轉載
供稿:網友

TensorFlow保存模型代碼

import tensorflow as tffrom tensorflow.python.framework import graph_utilvar1 = tf.Variable(1.0, dtype=tf.float32, name='v1')var2 = tf.Variable(2.0, dtype=tf.float32, name='v2')var3 = tf.Variable(2.0, dtype=tf.float32, name='v3')x = tf.placeholder(dtype=tf.float32, shape=None, name='x')x2 = tf.placeholder(dtype=tf.float32, shape=None, name='x2')addop = tf.add(x, x2, name='add')addop2 = tf.add(var1, var2, name='add2')addop3 = tf.add(var3, var2, name='add3')initop = tf.global_variables_initializer()model_path = './Test/model.pb'with tf.Session() as sess:  sess.run(initop)  print(sess.run(addop, feed_dict={x: 12, x2: 23}))  output_graph_def = graph_util.convert_variables_to_constants(sess, sess.graph_def, ['add', 'add2', 'add3'])  # 將計算圖寫入到模型文件中  model_f = tf.gfile.FastGFile(model_path, mode="wb")  model_f.write(output_graph_def.SerializeToString())

讀取模型代碼

import tensorflow as tfwith tf.Session() as sess:  model_f = tf.gfile.FastGFile("./Test/model.pb", mode='rb')  graph_def = tf.GraphDef()  graph_def.ParseFromString(model_f.read())  c = tf.import_graph_def(graph_def, return_elements=["add2:0"])  c2 = tf.import_graph_def(graph_def, return_elements=["add3:0"])  x, x2, c3 = tf.import_graph_def(graph_def, return_elements=["x:0", "x2:0", "add:0"])  print(sess.run(c))  print(sess.run(c2))  print(sess.run(c3, feed_dict={x: 23, x2: 2}))

以上這篇TensorFlow實現保存訓練模型為pd文件并恢復就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泊头市| 长治县| 德化县| 梅州市| 城口县| 淮阳县| 建德市| 丰原市| 东乌| 揭西县| 铜鼓县| 灵川县| 鄂尔多斯市| 阿拉尔市| 建水县| 平和县| 杂多县| 建昌县| 太湖县| 基隆市| 江津市| 县级市| 涞源县| 虞城县| 石屏县| 隆安县| 康保县| 合川市| 公主岭市| 阿鲁科尔沁旗| 南城县| 会理县| 辉县市| 庄浪县| 始兴县| 西盟| 镇巴县| 喀什市| 海城市| 青铜峡市| 太和县|