python
主页 > 脚本 > python >

Python深度学习TensorFlow神经网络基础介绍

2021-10-17 | 秩名 | 点击:
一、基础理论

1、TensorFlow

tensor:张量(数据)

flow:流动

Tensor-Flow:数据流



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:



普通执行

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



fetches(多参数执行)

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



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}))



总代码

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()

原文链接:https://blog.csdn.net/great_yzl/article/details/120479152
相关文章
最新更新