【问题标题】:How to perform the same crop augmentation on both the image and its corresponding mask?如何对图像及其相应的蒙版执行相同的裁剪增强?
【发布时间】:2022-11-24 20:03:39
【问题描述】:

我的代码是:

randomScale = random.uniform(0.08, 1.0)
        CPtransform = transforms.RandomResizedCrop((self.height, self.width), scale=(randomScale, randomScale), ratio=(1,1), interpolation=2)
        toImage = T.ToPILImage()
        padImage= CPtransform(toImage(image).convert("L"))
        padMask = CPtransform(toImage(mask).convert("L"))
        return TF.to_tensor(padImage), TF.to_tensor(padMask)

但是如图所示,掩模与增强后的图像不对应。我对它们使用的功能都是一样的,但结果不同。

有人可以帮忙吗?谢谢!

【问题讨论】:

    标签: tensorflow deep-learning tensor torchvision data-augmentation


    【解决方案1】:

    您可以concat 图像和蒙版并将其转换为单个张量并进行转换。

    image = T.PILToTensor()(pil_image)
    mask = T.PILToTensor()(pil_mask)
    
    # concatenate the images and apply transform:
    both_images = torch.cat((image, mask),0)
    
    # Apply the transformations to both images simultaneously
    transformed_images = CPtransform(both_images)
    
    #get transformed image and mask separately
    image_trans = transformed_images[:image.shape[0]]
    mask_trans = transformed_images[image.shape[0]:]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 2021-10-02
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      相关资源
      最近更新 更多