Currently I´m trying to train a model for OCR with fastai. I´ve read most of the posts in the forum but couldnt´t find anything for my problem. I´ve created the dataset myself from a dictionary and I´m using a csv-file to save the labels. The text will always be horizontal and easy to read and will be passed as an image file, containing just the text, so nothing to fancy is needed.
Here’s what I’ve got so far:
!pip install -Uqq fastbook
os.environ[‘CUDA_LAUNCH_BLOCKING’] = “1”
from fastbook import *
from fastai.vision.all import *
path_images = untar_data(‘https://nnpsegn7.gradient.paperspace.com/edit/storage/archive/images.zip’)
df = pd.read_csv(’/storage/data/words.csv’)
dblock = DataBlock()
dsets = dblock.datasets(df)
def get_x( r): return path_images/r[‘Filename’]
def get_y( r): return r[‘labels’].split(’ ')
train = df.index[~df[‘is_valid’]].tolist()
valid = df.index[df[‘is_valid’]].tolist()
dblock = DataBlock(blocks=(ImageBlock, MultiCategoryBlock),
item_tfms = Resize(256, ResizeMethod.Pad, pad_mode=‘zeros’))
dls = dblock.dataloaders(df)
So the problem is, that the labels get switched to alphabetical order and multiples get deleted. Is there a way to change this with Datablocks? Or do I need a completely different way of doing it?
I found a post where someone had a similar problem and seemed to have fixed it but I believe this doesn’t work anymore with current fastai versions.
It would be amazing if someone had any ideas and could help me. Thank you!