Contribution / Self-promotion: OCR Text/Image Dataset Package for YOU!

JosephC: <p>Hi folks,<br>
I’ve been putting together a small Pypi package that takes a text dataset and an image dataset and squishes them together to do a faux OCR dataset.  Initially this was done for some folks at LAION but I realized I should probably be showing it off to perhaps a wider group because (a) people here are more familiar with PyTorch best practices and (b) it’s probably useful to more than just two or three individuals.</p>
<p>It’s pip-installable right now as version 0.0.10.  I expect there will be changes before 0.1.0.</p>
<p>tl;dr:</p>
<pre data-code-wrap="python"><code class="lang-python"># %pip install text-overlay-dataset
from text_overlay_dataset import TextOverlayDataset
from PIL import Image

ds = TextOverlayDataset(
    image_dataset = [Image.new("RGB", (256, 256)), ], 
    text_dataset = ["Hello", "World"], 
    fonts="&lt;path to ttf dir&gt;"
)

composite_image, text, more = ds[0]
</code></pre>
<p>The “simple thing” is made to be easy.  The “hard thing” is made to be possible.  Here, just randomly generating augmented text overlays is pretty trivial, but the library also has support for random translations, rotations, quad distortion, and text blurring.</p>
<p>The font sizes are configurable and it’s possible to tell the library to favor larger fonts first.</p>
<p>All of the different configurations for the generator are in the docstring of the TextOverlayDataset class constructor.</p>
<p>My two biggest focuses for the immediate future are automatic text wrapping and streaming datasets.  Right now it assumes both datasets have random access, but for big image datasets that’s not always doable and most of the examples in TorchText are streaming, too.</p>
<p>Here’s a screenshot from a notebook:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/1/d12f2c21c09bd62fa7a419c9864b29770e5c5706.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/d12f2c21c09bd62fa7a419c9864b29770e5c5706" title="chrome_2023-04-29_08-28-25"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d12f2c21c09bd62fa7a419c9864b29770e5c5706_2_213x250.jpeg" alt="chrome_2023-04-29_08-28-25" data-base62-sha1="tQwRb0J03shEABMwXuPoa9A4eGy" width="213" height="250" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d12f2c21c09bd62fa7a419c9864b29770e5c5706_2_213x250.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d12f2c21c09bd62fa7a419c9864b29770e5c5706_2_319x375.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d12f2c21c09bd62fa7a419c9864b29770e5c5706_2_426x500.jpeg 2x" data-dominant-color="727762"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">chrome_2023-04-29_08-28-25</span><span class="informations">532×624 58.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>It’s MIT licensed and available on <a href="https://github.com/JosephCatrambone/PyTorchTextOverlayDataset" class="inline-onebox" rel="noopener nofollow ugc">GitHub - JosephCatrambone/PyTorchTextOverlayDataset: A PyTorch Dataset Adapter to Composite Text and Images</a></p>
<p><a class="hashtag-cooked" href="/c/vision/5" data-type="category" data-slug="vision" data-id="5"><span class="hashtag-icon-placeholder"><svg class="fa d-icon d-icon-square-full svg-icon svg-node"><use href="#square-full"></use></svg></span><span>vision</span></a> <a class="hashtag-cooked" href="/c/data/37" data-type="category" data-slug="data" data-id="37"><span class="hashtag-icon-placeholder"><svg class="fa d-icon d-icon-square-full svg-icon svg-node"><use href="#square-full"></use></svg></span><span>data</span></a></p>