Python 如何在PyTorch中为分段进行数据扩充
我正试图在torch中为我的数据加载器添加增强功能。我的所有示例图像都有遮罩,没有一个是空白的。但是,当我添加一个像Python 如何在PyTorch中为分段进行数据扩充,python,pytorch,data-augmentation,Python,Pytorch,Data Augmentation,我正试图在torch中为我的数据加载器添加增强功能。我的所有示例图像都有遮罩,没有一个是空白的。但是,当我添加一个像RandomRotation这样的增强时,我发现数据集中的一些示例会生成一个不再有标签的图像,并且图像会崩溃 在Pytork中是否有正确处理此问题的方法。这里是问题的例子吗 def __getitem__(self, idx): # load image and mask img_path = os.path.join(self.root, self.ima
RandomRotation
这样的增强时,我发现数据集中的一些示例会生成一个不再有标签的图像,并且图像会崩溃
在Pytork中是否有正确处理此问题的方法。这里是问题的例子吗
def __getitem__(self, idx):
# load image and mask
img_path = os.path.join(self.root, self.imagefolder, self.imgs[idx])
mask_path = os.path.join(self.root, self.maskfolder , self.masks[idx])
img = Image.open(img_path).convert("RGB")
# The problem is that augmentation could remove all the visible labels here
img, mask = run_augmentations(img, mask)
mask = Image.open(mask_path)
mask = np.array(mask)
obj_ids = np.unique(mask)
obj_ids = obj_ids[1:]
masks = mask == obj_ids[:, None, None]
num_objs = len(obj_ids)
boxes = []
for i in range(num_objs):
pos = np.where(masks[i])
xmin = np.min(pos[1])
xmax = np.max(pos[1])
ymin = np.min(pos[0])
ymax = np.max(pos[0])
if xmin == xmax or ymin == ymax:
print("WARNING ZERO SIZE BOUNDING BOX AFTER AUGMENTATION")
print(img_path)
boxes.append([xmin, ymin, xmax, ymax])
if len(boxes) == 0:
print("WARNING ZERO BOUNDING BOXES AFTER AUGMENTATION")
print(img_path)
...
编辑:如果在增强后没有标签,我的最佳尝试是返回没有任何增强的图像和掩码。您的
运行\u增强功能是什么?有些函数可能使用插值,这可能会弄乱离散的标签。@hkchengrex这只是torchvision.transforms.RandomRotation(180)
尝试添加resample=PIL.Image.NEAREST
到RandomRotation
?你的运行增强功能是什么?某些函数可能使用插值,这可能会弄乱离散的标签。@hkchengrex它只是torchvision.transforms.RandomRotation(180)
尝试添加resample=PIL.Image.NEAREST
到RandomRotation
?