lld / lld.py
Diwank Singh Tomer
fix: Fix loader
6e98d95
"""Dataset class for LLD dataset."""
import os
import datasets as ds
from datasets.features.image import image_to_bytes
import pandas as pd
import PIL.Image as Img
from sklearn.model_selection import train_test_split
_HOMEPAGE = "https://huggingface.co/datasets/diwank/lld"
_LICENSE = "MIT"
_DESCRIPTION = """
Designing a logo for a new brand is a lengthy and tedious back-and-forth process between a designer and a client. In this paper we explore to what extent machine learning can solve the creative task of the designer. For this, we build a dataset -- LLD -- of 600k+ logos crawled from the world wide web. Training Generative Adversarial Networks (GANs) for logo synthesis on such multi-modal data is not straightforward and results in mode collapse for some state-of-the-art methods. We propose the use of synthetic labels obtained through clustering to disentangle and stabilize GAN training. We are able to generate a high diversity of plausible logos and we demonstrate latent space exploration techniques to ease the logo design task in an interactive manner. Moreover, we validate the proposed clustered GAN training on CIFAR 10, achieving state-of-the-art Inception scores when using synthetic labels obtained via clustering the features of an ImageNet classifier. GANs can cope with multi-modal data by means of synthetic labels achieved through clustering, and our results show the creative potential of such techniques for logo synthesis and manipulation.
"""
_CITATION = """
@misc{sage2017logodataset,
author={Sage, Alexander and Agustsson, Eirikur and Timofte, Radu and Van Gool, Luc},
title = {LLD - Large Logo Dataset - version 0.1},
year = {2017},
"""
_URL = "https://huggingface.co/datasets/diwank/lld/resolve/main/data/lld-processed.h5"
class LLD(ds.GeneratorBasedBuilder):
"""LLD Images dataset."""
def _info(self):
return ds.DatasetInfo(
description=_DESCRIPTION,
features=ds.Features(
{
"image": ds.Image(),
"description": ds.Value("string"),
}
),
supervised_keys=("image", "description"),
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
# Load dataframe
use_local = os.environ.get("USE_LOCAL")
print(f"local: {bool(use_local)}")
archive_path = (
"./data/lld-processed.h5" if use_local else dl_manager.download(_URL)
)
df = pd.read_hdf(archive_path)
X = df.pop("description")
y = df.pop("images")
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
return [
ds.SplitGenerator(
name=ds.Split.TRAIN,
gen_kwargs={
"description": X_train,
"images": y_train,
},
),
ds.SplitGenerator(
name=ds.Split.TEST,
gen_kwargs={
"description": X_test,
"images": y_test,
},
),
]
def _generate_examples(self, description, images):
"""Generate images and description splits."""
for i, (desc, imgs) in enumerate(zip(description.values, images.values)):
for j, img in enumerate(imgs):
img_ = Img.fromarray(img)
bytes_ = image_to_bytes(img_)
yield f"{i}-{j}", {
"image": {"bytes": bytes_},
"description": desc,
}