Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random crop for ADE and COCO are not used in training #22

Open
csyxwei opened this issue Apr 5, 2022 · 0 comments
Open

Random crop for ADE and COCO are not used in training #22

csyxwei opened this issue Apr 5, 2022 · 0 comments

Comments

@csyxwei
Copy link

csyxwei commented Apr 5, 2022

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 csyxwei changed the title Random crop for ADE and COCO are not used in training. Random crop for ADE and COCO are not used in training Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant