These two posts helped me get closer to the right answer, but I’m still running into an error:
My goal:
Randomly mask a portion of one side of the input image, and leave the target image unchanged, like the screenshot below from the output of my data.summary(main_path, bs=8, show_batch=True), which appears to be right, but isn’t working with the learner:
My Code:
class PILImageInput(PILImage): pass
class PILImageOutput(PILImage): pass
class crappifier(Transform):
def __init__(self):
pass
def encodes(self, img:PILImageInput):
w,h = img.size
coords = self.get_random_direction(w,h)
ImageDraw.Draw(img).rectangle(coords, fill='green')
return img
def get_random_direction(self, w,h):
direction = random.randint(1, 4)
perc = random.uniform(.2, .5)
if direction == 1:
return [(0, 0), (w, h*perc)]
if direction == 2:
return [(w-w*perc, 0), (w, h)]
if direction == 3:
return [(0, h), (w, h -h*perc)]
if direction == 4:
return [(0, 0), (w*perc, h)]
data = DataBlock(blocks=(ImageBlock(cls=PILImageInput), ImageBlock()),
get_items=get_image_files,
get_y=lambda x: main_path/x.name,
n_inp=1,
splitter=RandomSplitter(),
item_tfms=[Resize((400,300)), crappifier()]
)
learn_gen = unet_learner(data.dataloaders(main_path), arch, wd=wd, norm_type=NormType.Weight,
self_attention=True, y_range=y_range, loss_func=loss_gen)
My Code:
`AssertionError: ‘n_out’ is not defined, and could not be inferred from data, set ‘dls.c’ or pass ‘n_out’
I’ve tried setting n_out to no avail, and I fear I am misunderstanding a fundamental component of DataBlocks or DataLoaders.
Any help would be much appreciated!