【问题标题】:Image resize in tensorflow?在张量流中调整图像大小?
【发布时间】:2021-05-08 21:43:58
【问题描述】:

(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 的图像张量。如何调整它们的大小。

【问题讨论】:

    标签: python python-3.x tensorflow machine-learning tensorflow2.0


    【解决方案1】:

    您需要添加渠道和批次维度。

    让我们制作一个随机的 2D 图像:

    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])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 2019-10-07
      • 2023-04-04
      相关资源
      最近更新 更多