在张量流中调整图像大小?
Image resize in tensorflow?
(1300, 730)
(433, 320)
(428, 320)
(428, 320)
(108, 108)
(416, 301)
(42, 42)
(307, 307)
(34, 34)
(1253, 1880)
(260, 194)
(428, 320)
(436, 322)
(1253, 1880)
(428, 320)
(285, 236)
(1253, 1880)
(259, 194)
如果我有上述尺寸的图像,那么如何将它们调整为 100 img 大小。我试过使用 tf.image.resize 但它需要 3D 或 4D 图像张量。我怎样才能调整它们的大小。
您将需要添加渠道和批量维度。
让我们制作一张随机的二维图像:
import tensorflow as tf
image = tf.random.uniform(shape=(40, 40), minval=0, maxval=256)
让我们通过添加我提到的两个维度将其变成 4D:
three_d_image = tf.expand_dims(image, axis=-1)
four_d_image = tf.expand_dims(three_d_image, axis=0)
您的图片现在有 4 个维度:
four_d_image.shape
TensorShape([1, 40, 40, 1])
现在您可以重塑它并验证它的形状:
tf.image.resize(four_d_image, size=(100, 100)).shape
TensorShape([1, 100, 100, 1])
(1300, 730) (433, 320) (428, 320) (428, 320) (108, 108) (416, 301) (42, 42) (307, 307) (34, 34) (1253, 1880) (260, 194) (428, 320) (436, 322) (1253, 1880) (428, 320) (285, 236) (1253, 1880) (259, 194) 如果我有上述尺寸的图像,那么如何将它们调整为 100 img 大小。我试过使用 tf.image.resize 但它需要 3D 或 4D 图像张量。我怎样才能调整它们的大小。
您将需要添加渠道和批量维度。
让我们制作一张随机的二维图像:
import tensorflow as tf
image = tf.random.uniform(shape=(40, 40), minval=0, maxval=256)
让我们通过添加我提到的两个维度将其变成 4D:
three_d_image = tf.expand_dims(image, axis=-1)
four_d_image = tf.expand_dims(three_d_image, axis=0)
您的图片现在有 4 个维度:
four_d_image.shape
TensorShape([1, 40, 40, 1])
现在您可以重塑它并验证它的形状:
tf.image.resize(four_d_image, size=(100, 100)).shape
TensorShape([1, 100, 100, 1])