如何在图像前面添加一维?

how to add one dimension in the front of an image?

现在我已经通过这些方法将图像 (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'.那我还能用什么方法呢?

尝试:

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)