【问题标题】:how to add one dimension in the front of an image?如何在图像前面添加一维?
【发布时间】:2022-01-13 13:23:54
【问题描述】:

现在我通过这些方法将图像 (32,32) 更改为 (32,32,1)

img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = np.expand_dims(img, axis=-1)
img = img.astype(np.float32)/255
img = tf.image.resize(img, [32,32])

但是现在,我想从(32,32,1)变成(1,32,32,1),所以我尝试使用

img = img.reshape(1,32,32,1)

但是,它显示'EagerTensor' object has no attribute 'reshape'. 那我还能用什么方法呢?

【问题讨论】:

    标签: python numpy tensorflow opencv


    【解决方案1】:

    试试:

    img = tf.random.normal((64, 64, 1))
    img = tf.image.resize(img, [32,32])
    
    img = tf.reshape(img, (1,32,32,1))
    

    或者

    img = tf.expand_dims(img, axis=0)
    

    【讨论】:

      猜你喜欢
      • 2017-11-17
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 2021-07-08
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多