JosephCatrambone / PyTorchTextOverlayDataset

A PyTorch Dataset Adapter to Composite Text and Images
MIT License
1 stars 1 forks source link

Examples from the readme don't work #3

Open wendlerc opened 1 year ago

wendlerc commented 1 year ago

`# Augmenting the text and making it harder to read by blurring, rotating, etc.

from text_overlay_dataset import TextOverlayDataset from torchtext.datasets import IMDB # A text dataset should be mappable. from torchvision.datasets.fakedata import FakeData # Any mappable image dataset is fine, or just a list of Images.

image_dataset = FakeData(size=100, image_size=(3, 256, 256),)

text_dataset_iter = IMDB(split='train') text_dataset = [label_text[1] for label_text in text_dataset_iter]

ds = TextOverlayDataset( image_dataset, text_dataset, font_directory="./fonts/", maximum_font_translation_percent=0.5, maximum_font_rotation_percent=0.25, maximum_font_blur=3.0 )`

There are multiple errors:

FakeData returns tuples: so changing the image dataset to image_dataset = [d[0] for d in image_dataset] would make sense. When doing that I still get an error:

`522 text_color_block.putalpha(result.text_rasterization) 523 img_pil.paste(text_color_block, (0, 0), result.text_rasterization) 524 result.image = img_pil

AttributeError: 'NoneType' object has no attribute 'text_rasterization`

wendlerc commented 1 year ago

aha... this error is caused by the strings being too long