【问题标题】:why the tensorflow split function report error when X is a tensor为什么当X是张量时tensorflow split函数会报错
【发布时间】:2019-09-17 02:02:29
【问题描述】:

tensorflow函数拆分报错,搞不清楚

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

输出应该是正确的,但它报告错误消息:

py_call_impl 中的错误(可调用,dots$args,dots$keywords):

值错误: 不支持 Rank-0 张量作为拆分的 num_or_size_splits 参数。 提供的参数:2.0

【问题讨论】:

  • 从错误中说明您有一个Rank-0 tensor。听起来很像输入 X 在数字上必须是非奇异的。

标签: r tensorflow split


【解决方案1】:

它在启用了 Eager 的 tensorflow 1.14 中运行良好:

import tensorflow as tf 
tf.enable_eager_execution()
X = tf.random_uniform(shape=(256, 32),minval=0,maxval=10,name = "X");
Y = tf.split(X, num_or_size_splits = 2, axis = 0)

如果您尝试将张量用作 num_or_size_splits,请确保它是一个列表,其中包含指示每个拆分大小的元素

import tensorflow as tf 
tf.enable_eager_execution()
X = tf.random_uniform(shape=(256, 32),minval=0,maxval=10,name = "X");
n_split = tf.constant([128, 128])
Y= tf.split(X, num_or_size_splits = n_split, axis = 0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 2020-04-29
    相关资源
    最近更新 更多