• Tensorflow-01


    tensorflow基本组件

    • 使用图 (graph) 来表示计算任务
    • 在被称之为会话 (Session) 的上下文 (context) 中执行图
    • 使用 tensor 表示数据
    • 通过变量 (Variable) 维护状态
    • 使用 feed 和 fetch 可以为任意的操作(arbitrary operation) 赋值或者从其中获取数据
      import tensorflow as tf
      
      a=tf.constant(2)
      b=tf.constant(3)
      
      with tf.Session() as sess:
          print("a:%i" % sess.run(a) , "b:%i" % sess.run(b))
          print("Addition with constants: %i" % sess.run(a+b))
          print("Multiplication with constant: %i" % sess.run(a*b))
      
      print ("使用变量Variable构造计算图a,b")
      a = tf.placeholder(tf.int16)
      b = tf.placeholder(tf.int16)
      add = tf.add(a,b)
      mul = tf.multiply(a,b)
      with tf.Session() as sess:
          print("Addition with variables: %i" % sess.run(add, feed_dict={a: 2, b: 3}))
          print("Addition with variables: %i" % sess.run(mul, feed_dict={a: 2, b: 3}))
      
      print("
      " + "构造计算图")
      matrix1=tf.constant([[3.,3.]])
      matrix2=tf.constant([[2.],[2.]])
      product=tf.matmul(matrix1,matrix2)
      with tf.Session() as sess:
          result = sess.run(product)
          print(result)

  • 相关阅读:
    POJ 1680 Fork() Makes Trouble
    课堂改进意见
    梦断代码 读后感3
    梦断代码 读后感2
    找一问题
    软件评价——搜狗输入法
    《梦断代码》读后感1
    站立会议第十天
    站立会议第九天
    站立会议第八天
  • 原文地址:https://www.cnblogs.com/mxk123456/p/14941534.html
Copyright © 2020-2023  润新知