zoukankan      html  css  js  c++  java
  • tensorflow中张量_常量_变量_占位符

    1.tensor

    在tensorflow中,数据是被封装在tensor对象中的。tensor是张量的意思,即包含从0到任意维度的张量。常数是0维度的张量,向量是1维度的张量,矩阵是二维度的张量,以及还有多维度的张量。

    
    
    1 # tensor1 是一个0维的 int32 tensor
    2 tensor1 = tf.constant(1234) 
    3 # tensor2 是一个1维的 int32 tensor
    4 tensor2 = tf.constant([123,456,789]) 
    5  # tensor3 是一个二维的 int32 tensor
    6 tensor3 = tf.constant([ [123,456,789], [222,333,444] ])
    View Code
    
    
    
     

    2.tf.constant

    constant函数提供在tensorflow中定义常量(不可更改的张量)的方法

    如:

    tensor_constant = tf.constant([1,2,3,4)

    3.tf.Variable

    tensorflow中的变量是通过Variable类来实现的。tensorflow中需要定义为变量的包括训练过程中的输入数据,输出数据,以及控制从输入到输出的学习机制,即网络参数。输入输出数据在tf中是用placeholder占位符来定义的,网络参数是用tf.Variable来定义的。

    4.tf.placeholder

    用于声明一个张量的数据格式,告诉系统这里会有一个这种格式的张量,但是还没有传入具体的值。

    如:

    X = tf.placeholder("float", shape=[None, 100])

    上面声明了一个张量X,数据类型是float,100列,行数不确定。

    5.tf.Session

    以上部分都是搭建一个计算图的代码,在tf中,先搭建好计算图,然后再启动session,运行定义好的图。

    1 import tensorflow as tf
    2  
    3 x = tf.placeholder("string")
    4 with tf.Session() as sess:
    5     output = sess.run(x, feed_dict={x : "run the map"})
    6     print(output)
    View Code
  • 相关阅读:
    Python实现MapReduce,wordcount实例,MapReduce实现两表的Join
    structure needs cleaning
    Lifecycle of an ASP.NET MVC 5 Application
    ASP.NET Integration with IIS 7
    Execution order of modules in IIS7
    Assembly Binding redirect: How and Why?
    Cannot See Worker Processes Icon in IIS
    What is the main difference between a key, an IV and a nonce?
    核心玩法的三要素
    ruby各种循环输出数组元素
  • 原文地址:https://www.cnblogs.com/xinmomoyan/p/10170958.html
Copyright © 2011-2022 走看看