Skip to main content

A python library to augment the images dataset aimed for a ML classification system

Project description

Table of Contents

Scope

The scope of this library is to augment the dataset for an image classification ML system.

Setup

Versions

The library is compatible with python 3.7.

Virtualenv

We suggest to isolate your installation via python virtualenv:

python3 -m venv .imgaug
...
source .imgaug/bin/activate

Installation

Update pip package manager:

pip install pip --upgrade
...
pip install -r requirements.txt

Tests

The library is covered, by fast, isolated unit and doc testing (the latter to grant reliable documentation):

python -m unittest discover -s imgaug -p '*'
...................
----------------------------------------------------------------------
Ran 19 tests in 0.898s

OK

Dataset

The system is aimed to work with images of different sizes, saved as PNG or JPG files (supporting RGBA conversion).

Labeller

The target label is extracted directly by inspecting the image name and trying to extract meaningful information (customisable).

lbl = Labeller()
lbl('resources/1096023906001-c-suit-veletta-albino.jpg')
'1096023906001'

Normalizer

The images are normalized by:

  • resizing them to the specified max size (default to 256 pixels)
  • optionally applying a squared, transparent canvas and centering the image on it, thus avoiding any deformation
norm = Normalizer(size=128, canvas=True)
img = norm('resources/bag.png')
img.shape
(128, 128, 4)

Augmenter

The number of images is augmented by three orders of magnitude (depending on the cutoff attribute) by applying different transformations to the original one.
Transformations are applied by using generators, thus saving memory consumption.

aug = Augmenter()
aug.count
1000

Persister

Images are persisted upon normalization and augmentation, by passing a BytesIO object to the specified action function. The persister can be iterated upon function return value and label.

def persist(name, data):
    filename = f'temp/{name}'
    with open(filename, 'wb') as f:
        f.write(data.getvalue())
    return filename

pers = Persister('resources/skirt.jpg', action=perist)
for label, filename in pers:
    print(label, filename)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image_augmenter-0.1.1.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

image_augmenter-0.1.1-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page