脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python深度学习TensorFlow神经网络基础概括

Python深度学习TensorFlow神经网络基础概括

2022-01-26 10:45_睿智_ Python

这篇文章主要为大家介绍了Python深度学习中TensorFlow神经网络基础概括,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步

一、基础理论

1、TensorFlow

tensor:张量(数据)

flow:流动

Tensor-Flow:数据流

Python深度学习TensorFlow神经网络基础概括

2、TensorFlow过程

TensorFlow构成:图和会话

1、构建图阶段

构建阶段:定义了数据(张量tensor)与操作(节点operation),构成图(静态)

张量:TensorFlow中的基本数据对象。

节点:提供图中执行的操作。

2、执行图阶段(会话)

执行阶段:使用会话执行定义好的数据与操作。

 

二、TensorFlow实例(执行加法)

1、构造静态图

1-1、创建数据(张量)

#图(静态)
a = tf.constant(2)    #数据1(张量)
b = tf.constant(6)    #数据2(张量)

1-2、创建操作(节点)

c = a + b              #操作(节点)

2、会话(执行)

API:

Python深度学习TensorFlow神经网络基础概括

普通执行

#会话(执行)
with tf.Session() as sess:
  print(sess.run(a + b))

Python深度学习TensorFlow神经网络基础概括

fetches(多参数执行)

#会话(执行)
with tf.Session() as sess:
  print(sess.run([a,b,c]))

Python深度学习TensorFlow神经网络基础概括

feed_dict(参数补充)

def Feed_Add():
  #创建静态图
  a = tf.placeholder(tf.float32)
  b = tf.placeholder(tf.float32)
  c = tf.add(a,b)
  
  #会话(执行)
  with tf.Session() as sess:
      print(sess.run(c, feed_dict={a:0.5, b:2.0}))

Python深度学习TensorFlow神经网络基础概括

 

总代码

import tensorflow as tf
def Add():
  #图(静态)
  a = tf.constant(2)    #数据1(张量)
  b = tf.constant(6)    #数据2(张量)
  c = a + b              #操作(节点) 
  #会话(执行)
  with tf.Session() as sess:
      print(sess.run([a,b,c])) 
def Feed_Add():
  #创建静态图
  a = tf.placeholder(tf.float32)
  b = tf.placeholder(tf.float32)
  c = tf.add(a,b)    
  #会话(执行)
  with tf.Session() as sess:
      print(sess.run(c, feed_dict={a:0.5, b:2.0}))        
Add()
Feed_Add()

以上就是Python深度学习TensorFlow神经网络基础概括的详细内容,更多关于TensorFlow神经网络基础的资料请关注服务器之家其它相关文章!

原文链接:https://blog.csdn.net/great_yzl/article/details/120479152

延伸 · 阅读

精彩推荐