【问题标题】:Why/How image dataet dimensions get changed after it converts into tensorflow 2.0 dataset为什么/如何在转换为 tensorflow 2.0 数据集后更改图像数据集的尺寸
【发布时间】:2020-05-31 01:02:24
【问题描述】:

我正在使用 CIFAR10 数据集。它具有原始大小:(60000,32,32,3) ,将其转换为 tensorflow 数据集后,将其转换为 tf.Tensor : shape(64,24,24,3)。 我从上面了解到的是,每批 3 个通道中有 64 张 24 x 24 的图像。(如果我错了,请知道) 这是我的代码 sn-p。

(x_train,y_train),(x_test,y_test)=tf.keras.datasets.cifar10.load_data()
train_dataset=tf.data.Dataset.from_tensor_slices((x_train,y_train)).batch(64).shuffle(10000)
train_dataset=train_dataset.map(lambda x,y:(tf.cast(x,tf.float32)/255.0,y))
train_dataset=train_dataset.map(lambda x,y:(tf.image.central_crop(x,0.75),y))
train_dataset=train_dataset.map(lambda x,y:(tf.image.random_flip_left_right(x),y))
train_dataset=train_dataset.repeat()

据我了解,这是因为它被集中裁剪了 75%。如果是对的,那么究竟如何?

【问题讨论】:

    标签: deep-learning conv-neural-network tensorflow2.0 tensorflow-datasets


    【解决方案1】:

    你的理解是正确的。 central_crop 通过删除图像的外部部分来裁剪图像的中心区域。因此,对于central_fraction=0.75,图像的新尺寸将为32*0.75 = 24。这是该方法的文档:

    central_crop(image, central_fraction)
        Crop the central region of the image(s).
    
        Remove the outer parts of an image but retain the central region of the image
        along each dimension. If we specify central_fraction = 0.5, this function
        returns the region marked with "X" in the below diagram.
    
             --------
            |        |
            |  XXXX  |
            |  XXXX  |
            |        |   where "X" is the central 50% of the image.
             --------
    
        This function works on either a single image (`image` is a 3-D Tensor), or a
        batch of images (`image` is a 4-D Tensor).
    
        Args:
          image: Either a 3-D float Tensor of shape [height, width, depth], or a 4-D
            Tensor of shape [batch_size, height, width, depth].
          central_fraction: float (0, 1], fraction of size to crop
        Usage Example: ```python >> import tensorflow as tf >> x =
          tf.random.normal(shape=(256, 256, 3)) >> tf.image.central_crop(x, 0.5) ```
    
        Raises:
          ValueError: if central_crop_fraction is not within (0, 1].
    
        Returns:
          3-D / 4-D float Tensor, as per the input.
    

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 1970-01-01
      相关资源
      最近更新 更多