Tensorflow入门__实例:图计算
生活随笔
收集整理的這篇文章主要介紹了
Tensorflow入门__实例:图计算
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
import tensorflow.compat.v1 as tf
#tf.compat.v1.get_default_graph#定義方程的參數(shù)為常量
a = tf.constant(5.0)
b = tf.constant(4.5)
c = tf.constant(3.0)#定義x為變量 默認值為0
x = tf.Variable(0., name = 'x')#定義y為輸出 它是a、b、c和x上的操作
y = (a * x**2) + (b * x) + cfrom IPython.display import clear_output, Image, display, HTML
import numpy as np def strip_consts(graph_def, max_const_size=32):"""去掉graph_def中的大數(shù)值"""strip_def = tf.GraphDef()for n0 in graph_def.node:n = strip_def.node.add() n.MergeFrom(n0)if n.op == 'Const':tensor = n.attr['value'].tensorsize = len(tensor.tensor_content)if size > max_const_size:tensor.tensor_content = "<stripped %d bytes>"%sizereturn strip_defdef show_graph(graph_def, max_const_size=32):"""可視化TensorFlow graph."""if hasattr(graph_def, 'as_graph_def'):graph_def = graph_def.as_graph_def()strip_def = strip_consts(graph_def, max_const_size=max_const_size)code = """<script>function load() {{document.getElementById("{id}").pbtxt = {data};}}</script><link rel="import" href="https://tensorboard.appspot.com/tf-graph-basic.build.html" οnlοad=load()><div style="height:600px"><tf-graph-basic id="{id}"></tf-graph-basic></div>""".format(data=repr(str(strip_def)), id='graph'+str(np.random.rand()))iframe = """<iframe seamless style="width:1200px;height:620px;border:0" srcdoc="{}"></iframe>""".format(code.replace('"', '"'))display(HTML(iframe))show_graph(tf.get_default_graph().as_graph_def())
總結(jié)
以上是生活随笔為你收集整理的Tensorflow入门__实例:图计算的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人工神经网络_图像加载(数据挖掘入门与实
- 下一篇: 机器学习 KD树_递归_回溯_搜索(ma