OASIS icon indicating copy to clipboard operation
OASIS copied to clipboard

Random crop for ADE and COCO are not used in training

Open csyxwei opened this issue 3 years ago • 0 comments

When training the model, the dataloader_train and dataloader_val share the same option object. So opt.load_size is first assigned to 286 in dataloader_train, and then is replaced with 256 in dataloader_val.

class Ade20kDataset(torch.utils.data.Dataset):
    def __init__(self, opt, for_metrics):
        if opt.phase == "test" or for_metrics:
            opt.load_size = 256
        else:
            opt.load_size = 286

Finally, two dataloader have same opt.load_size (256), and the random crop augmentation for training are not used in this case.

# resize
new_width, new_height = (self.opt.load_size, self.opt.load_size)
image = TR.functional.resize(image, (new_width, new_height), Image.BICUBIC)
label = TR.functional.resize(label, (new_width, new_height), Image.NEAREST)
# crop
crop_x = random.randint(0, np.maximum(0, new_width -  self.opt.crop_size))
crop_y = random.randint(0, np.maximum(0, new_height - self.opt.crop_size))
image = image.crop((crop_x, crop_y, crop_x + self.opt.crop_size, crop_y + self.opt.crop_size))
label = label.crop((crop_x, crop_y, crop_x + self.opt.crop_size, crop_y + self.opt.crop_size))

csyxwei avatar Apr 05 '22 18:04 csyxwei