zoukankan      html  css  js  c++  java
  • tensorflow 基本内容

    tensorflow的结构

    1、使用图(graphs)来表示计算任务

    2、在被称之为会话(Session)的上下文(context)中执行图

    3、使用tensor表示数据

    4、通过变量(Variable)维护状态

    5、使用feed和fetch可以为任意的操作赋值或者从中获取数据

    1、基本操作:

     m1 = tf.constant([[3,3]]) 1行2列   m2 = tf.constant([[2],[3]])   创建常量 

    product =  tf.matmul(m1,m2)    矩阵乘法  

    sess= tf.Session()       定义一个会话

    with tf.Session()as sess:

    relult = sess.run(product),启动默认图     只有用会话才能去调用上面的三个操作 用 

    sess.close()   关闭会话。

    2、变量

    x = tf.Variable([1,2])      tensorflow 变量

    sub = tf.subtract(x,a)  减法。tf.add(x,a) 加法

    init = tf.global_variales_initializer()全局初始化所有变量。

    update = tf.assign(state,new_value)  #赋值语句state = new_value

    for  _in range(5):  #循环执行5次   

    3、Fetch 可以执行多个操作      

    result = sess.run([mul,add])

    4、Feed 以字典的形式传入值

    input1 = tf.placeholder(tf.float32)#定义占位符 里面的值不确定

    sess.run(操作,feed_dict = {操作占位符1:[8.],操作占位符2:[2.]})

    5简单实例

       

    6、import matplotlib.pylot as plt 导入python 画图的包

    x_data = np.linspace(-0.5,0.5,200)[:,np.newaxis]  #numpy生成200个-0.5到0.5的值,维度是 200行1列

    np.random(0,0.02,x_data.shape)#形状和x_data 一样   np.square(x)x的平方

    tf.nn.tanh()或一个激活函数。

    plt.figure()  plt.scatter(x,y)将x,y 用散点图打印出来

    plt.plot(x,y,'r-',lw = 5)  表示画出来宽为5的红色的实线

  • 相关阅读:
    POJ3320 Jessica's Reading Problem
    POJ3320 Jessica's Reading Problem
    CodeForces 813B The Golden Age
    CodeForces 813B The Golden Age
    An impassioned circulation of affection CodeForces
    An impassioned circulation of affection CodeForces
    Codeforces Round #444 (Div. 2) B. Cubes for Masha
    2013=7=21 进制转换
    2013=7=15
    2013=7=14
  • 原文地址:https://www.cnblogs.com/Liudanxixi/p/10597029.html
Copyright © 2011-2022 走看看