Cropping random locations

Hi,
I would like to crop different locations of my images, not just the center and I am using Jeremy’s code. Any suggestions for modifications or even a new custom transformation?

load valid set

src = ImageImageList.from_folder(valid_lr).split_by_rand_pct(0.1, seed = 48)

trying to get crop_pad OR rand_crop working

tfms = [zoom(scale = 4, p = 1.), crop_pad (row_pct = torch.randn(1, 1), col_pct = torch.randn(1, 1)]


tfm = [zoom(scale = 4, p = 1.), rand_crop(p = 1)]

Jeremy’s function

def get_data(bs, size):
data = (src.label_from_func(lambda x: valid_lr/x.name)
.transform(tfms, size = size)
.databunch(bs = bs).normalize(imagenet_stats, do_y = True))

data.c = 1
return data

The current output image:

Thanks


FIXED:

tfm = [rand_zoom(4.), rand_crop(p = 1)]

Problem is you are using zoom and that will zoom to center, so by the time crop runs there is not much to choose from. Try either rand_zoom or combine both with zoom_crop(4, p=1, do_rand=True)

2 Likes

Thank you for your comment on order, I got it all right now!