代码之家  ›  专栏  ›  技术社区  ›  George

单通道到rgb的张量流给出秩0

  •  0
  • George  · 技术社区  · 6 年前

    我正在创建一个多维数组。

    import numpy as np
    import tensorflow as tf
    
    a = np.zeros((10, 4, 4, 1))
    
    print(a.shape)
    
    (10, 4, 4, 1)
    

    我想添加rgb通道,因此我正在执行以下操作:

    tf_a = tf.image.grayscale_to_rgb(a, name=None)
    print(tf.rank(tf_a))
    
    Tensor("Rank:0", shape=(), dtype=int32)
    

    它给了我一个秩为0而不是4的张量。

    此外,形状:

    print(tf.shape(tf_a))
    

    Tensor("Shape:0", shape=(4,), dtype=int32)

    1 回复  |  直到 6 年前
        1
  •  1
  •   Nipun Wijerathne    6 年前

    tf.等级(tf\u a) tf.形状(tf\u a) 特富瓦 .

    因此,为了得到实际结果,我对您的代码进行了一些编辑。

    import numpy as np
    import tensorflow as tf
    
    a = np.zeros((10, 4, 4, 1))
    
    tf_a = tf.image.grayscale_to_rgb(a, name=None)
    
    sess = tf.Session()
    with sess.as_default():
    
       print(tf.rank(tf_a).eval()) # rank 
       print(tf.shape(tf_a).eval()) #shape
    
     4            #rank
    [10  4  4  3] #result