ValueError:Shape(?,21,2)在tf.SparseTensor中的等级必须为2

时间:2018-12-09 23:49:06

标签: python tensorflow keras tensor keras-2

我的代码:

def f(x):
    import tensorflow as tf
    print('x.shape={0}'.format(x.shape))
    idx = K.cast(x[:, :, 0:2]*15.5+15.5, "int64")
    print('idx.shape={0}'.format(idx.shape))
    st_z = tf.SparseTensor(idx, values=0.0, dense_shape=[K.shape(x)[0], 32, 32])

输出:

x.shape=(?, 21, 3)
idx.shape=(?, 21, 2)

错误:

ValueError: Shape (?, 21, 2) must have rank 2

如何解决此问题?谢谢

0 个答案:

没有答案