【问题标题】:What is the output of tf.split?tf.split 的输出是什么?
【发布时间】:2017-11-22 06:18:54
【问题描述】:

所以假设我有这个:

TensorShape([Dimension(None), Dimension(32)])

我在这个张量 _X 上使用 tf.split,尺寸为上述:

_X = tf.split(_X, 128, 0) 

这个新张量的形状是什么?输出是一个列表,因此很难知道这个新张量的形状。

【问题讨论】:

    标签: python arrays tensorflow tensor


    【解决方案1】:

    新版tensorflow定义split函数如下:

    tf.split( 价值, num_or_size_splits, 轴=0, 数字=无, 名称='拆分' )

    但是,当我尝试在 R 中运行它时:

    X = tf$random_uniform(minval=0,
                          maxval=10,shape(256, 32),name = "X");
    
    Y = tf$split(X,num_or_size_splits = 2,axis = 0)
    

    它报告错误信息:

    Error in py_call_impl(callable, dots$args, dots$keywords) : 
      ValueError: Rank-0 tensors are not supported as the num_or_size_splits argument to split. Argument provided: 2.0
    

    【讨论】:

      【解决方案2】:

      tf.split(X, row = n, column = m)用于将变量的数据集拆分为n按行数和m按列数。

      例如,我们有大小为(10,10) 的data_set x, 然后tf.split(x, 2, 0) 将打破x 的数据集在2 组大小(5, 10)

      但是如果我们采用tf.split(x, 2, 2), 那么我们会得到4组大小为(5, 5)的数据。

      【讨论】:

      • 元素的顺序呢?比如原轴0包含[1,2,3,4,5,6,7,8,9,10],那么split(x,2,0)之后会变成[1,2,3,4,5]和 [6,7,8,9,10] [1,3,5,7,9] 和 [2,4,6,8,10]?似乎没人愿意问这个??
      【解决方案3】:

      tf.split() 返回张量对象的列表。你可以知道每个张量对象的形状如下

      import tensorflow as tf
      
      X = tf.random_uniform([256, 32]);
      Y = tf.split(X,128,0)
      Y_shape = tf.shape(Y[1])
      
      sess = tf.Session()
      X_v,Y_v,Y_shape_v = sess.run([X,Y,Y_shape]) 
      # numpy style
      print X_v.shape
      print len(Y_v)
      print Y_v[100].shape
      # TF style
      print len(Y)
      print Y_shape_v
      

      输出:

      (256, 32)
      128
      (2, 32)
      128
      [ 2 32]
      

      我希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-21
        • 2017-09-13
        • 1970-01-01
        • 1970-01-01
        • 2017-02-04
        • 2016-02-11
        • 2020-01-17
        • 2019-11-01
        相关资源
        最近更新 更多