As in lesson 7
We have seen that we are creating label for crappy images from the folder of original images .
I am trying that with different data 0000.png,0001.png,0002.png …
And my code is
from PIL import Image,ImageDraw,ImageFont
import fastai
from fastai.vision import *
from fastai.callbacks import *
from fastai.vision.gan import *
path_to_data = './data'
path_to_crapy_images = './crappy'
def crappyify(fn,i):
dest = path_to_crapy_images/fn.relative_to(path_to_data)
dest.parent.mkdir(parents = True,exist_ok=True)
img = PIL.Image.open(fn)
targ_sz = resize_to(img,96,use_min=True)
img = img.resize(targ_sz,resample=PIL.Image.BILINEAR).convert('RGB')
w,h = img.size
q = random.randint(15,70)
ImageDraw.Draw(img).text((random.randint(0,w//2),random.randint(0,h//2)),str(q),fill=(255,255,1))
img.save(dest,quality=q)
il = ImageList.from_folder(path_to_data)
parallel(crappyify,il.items)
bs,size = 32,128
arch = models.resnet34
src = ImageImageList.from_folder(path_to_crapy_images).split_by_rand_pct(0.1, seed=42)
def get_data(bs,size):
data = (src.label_from_func(lambda x: f'{path_to_data}/{x.name}')
.transform(get_transforms(max_zoom=2.), size=size, tfm_y=True)
.databunch(bs=bs).normalize(imagenet_stats, do_y=True))
data.c = 3
return data
data_gen = get_data(bs,size)
data_gen.show_batch(4,figsize=(5,5))
But the problem is when i do data_gen.show_batch(4,figsize=(5,5))
label image also got blurred.
I want to turn of the y rotation so when i do tfm_y =False
some error through up .
RuntimeError: stack expects each tensor to be equal size, but got [3, 1100, 850] at entry 0 and [3, 923, 578] at entry 2