Skip to main content

A package to increase your data for your machine learning project

Project description



PyPI Supported Python Versions License

AUG-TOOL: Image Augmentation Tool for Machine Learning Projects

Aug Tool is a Python library available on PyPI that simplifies image data augmentation for machine learning tasks, compatible with TensorFlow, PyTorch, and the YOLO library.

Installation

pip install aug-tool

To install "aug-tool", you can use pip, the Python package manager. Open a terminal or command prompt and run the following command:

Features

  • Supports various image augmentation techniques suitable for real environment conditions, such as adding noise, scaling, shifting, and more.
  • Provides convenient integration with popular machine learning libraries such as TensorFlow, Keras, PyTorch, etc.
  • Allows augmentation of both images and their annotation files in formats such as XML, or TXT.
  • Customizable augmentation parameters, including rotation angle, scaling factor, flipping direction, and more.

Output examples

Labeled data With aug tool
Example 1 Alt Text Alt Text
Example 2 Alt Text Alt Text
Example 3 Alt Text Alt Text
Example 4 Alt Text Alt Text

Documentation

Simple usage:

from aug_tool import Augmentation

# Specify the input parameters
open_file_name = r"C:\Users\user.name\Desktop\datas\orginal" #Path to the data folder

save_file_name = r"C:\Users\user.name\Desktop\datas\augmented"#Path to the data folder

number_of_aug = 2 # Number of augmented data to generate

# Apply data augmentation using aug-tool
Augmentation(open_data_path=open_file_name,
        save_file_name=save_file_name,
        number_of_aug=number_of_aug,
        x_shift=15,
        y_shift=15)

 # Continue with further processing or analysis

Package Structure Diagram:

src/ #root file
└── aug_tool/ #main package
    ├── __init__.py
    ├── dataOpener/ #sub package1
       ├── __init__.py
       ├── dataOp.py
       ├── imgOp.py
       ├── annOp.py
       ├── xmlOp.py
       └── txtOp.py
    ├── dataAugmentor/ #sub package2
       ├── __init__.py
       ├── dataAug.py
       ├── imgAug.py
       ├── annAug.py
       ├── xmlAug.py
       └── txtAug.py
    ├── dataSaver/ #sub package3
       ├── __init__.py
       ├── dataSav.py
       ├── imgSav.py
       ├── annSav.pys
       ├── xmlSav.py
       └── txtSav.py
    └── augmentation.py

Class Diagram:



Augmentation Class Initialization:

class Augmentation(object):
    def __init__(self, open_data_path:str, save_file_name:str, number_of_aug:int, x_shift:int, y_shift:int) -> None:
        """
        This is an initialization function that takes in parameters for data augmentation and saves the
        augmented data and annotations to a specified file path.
        
        :param open_data_path: The path to the directory containing the original data to be augmented
        :type open_data_path: str
        :param save_file_name: The name of the folder where the augmented data will be saved
        :type save_file_name: str
        :param number_of_aug: The number of times the image and its corresponding annotation will be
        augmented
        :type number_of_aug: int
        :param x_shift: The amount of horizontal shift to apply during image augmentation
        :type x_shift: int
        :param y_shift: y_shift is a parameter that determines the maximum number of pixels by which an
        image can be shifted vertically during data augmentation
        :type y_shift: int
        """  

The __init__ method of the augmentation class performs the initialization and processing steps. This process can be divided into three parts:

Part 1: File and Folder Creation

In the first part, the method creates the necessary file names and initializes the folder structure for storing the augmented images. This ensures a well-organized output for the augmented data.

        # It creates a folder to save inside 
        self.create_dest_folder(self.target_file_name)
        
        # All the data in the file is taken and augmented in a loop
        for data_path in self.create_list_of_data(open_data_path = open_data_path):
            
            # The image and label file with the same name as image is opened once
            image = self.label_factory(data_path[:-4])
            label = self.image_factory(data_path)
            
            # The augmentation process is performed as much as the `number_of_aug` value  from the user
            for num in range(number_of_aug):
                
                # The name of new file that will be augmented is created
                data_name = data_path.split("\\")[-1][:-4] + "_aug" + str(num + 1))

Here, The self.create_dest_folder method is responsible for creating the output folder if it doesn't already exist. self.create_list_of_data stores the path of the files which will be augmented . The loop iterates over the files in the self.create_list_of_data list and obtains the paths to the corresponding image and label files. The self.label_factory and self.image_factory methods are responsible for opening the image and label files, respectively.

Part 2: Image Augmentation Processing

The second part of the __init__ method performs the actual augmentation processing of images. Within a nested loop, the augmentation techniques are applied to the image to generate multiple augmented versions of the data.

                # The augmented image is created acording values that given users
                aug_image = dataAugmentor.ImgAug(image=image,
                                                        x_shift=x_shift,
                                                        y_shift=y_shift).image_aug
                                
                # The augmented image is saved on target file   
                dataSaver.ImgSav(target_file_path = self.target_file_name,
                                    img_aug = aug_image,
                                    data_name=data_name)

Part 3: Label Augmentation Processing

The third part of the __init__ method performs the actual augmentation processing of labels. Within a nested loop, the augmentation techniques are applied to the label data to generate multiple augmented versions of the data.

                # If the extension of the read label file is '.xml', it is processed here
                if self.ann.ext == ".xml":
                    
                    ann_aug = dataAugmentor.XmlAug(name=data_name,
                                                annotate= label.data,
                                                x_shift=x_shift,
                                                y_shift=y_shift)
                    
                    dataSaver.XmlSav(target_file_path = self.target_file_name,
                                                                ann_aug=ann_aug.annotate,
                                                                data_name=data_name)

                # If the extension of the read label file is '.txt', it is processed here    
                elif self.ann.ext == ".txt":
                    
                    ann_aug = dataAugmentor.TxtAug(
                                                annotate= label.data,
                                                x_shift=x_shift,
                                                y_shift=y_shift,
                                                width=aug_image.width,
                                                height=aug_image.height).aug_anotate
                    
                    dataSaver.TxtSav(target_file_path = self.target_file_name,
                                     ann_aug=ann_aug,
                                    data_name=data_name)

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this library in accordance with the terms specified in the license.

Support

If you have any questions, suggestions, or need support, feel free to reach out to hakanaktas4541@gmail.com

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

aug_tool-0.2.tar.gz (453.1 kB view details)

Uploaded Source

Built Distribution

aug_tool-0.2-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file aug_tool-0.2.tar.gz.

File metadata

  • Download URL: aug_tool-0.2.tar.gz
  • Upload date:
  • Size: 453.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for aug_tool-0.2.tar.gz
Algorithm Hash digest
SHA256 0b11fc50ce96dd520e5a6e38004c1d129f2d946c5041cea18a76ebcb89411ccc
MD5 8b94be028e437d79a08c1200f8eb2bb5
BLAKE2b-256 0815fb60aa1569494046108e0d4e3b978ddd39498b938c0c848d2bc575601108

See more details on using hashes here.

File details

Details for the file aug_tool-0.2-py3-none-any.whl.

File metadata

  • Download URL: aug_tool-0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for aug_tool-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ba76d1ce87adc033c53104511dcb73983f3d1eddd7ac6b717e17589897b3184b
MD5 824c0855866acfd75740e10f9af4d95b
BLAKE2b-256 7b0b9bc57b65ddc2ed1c4a01faa0f834fc96d54e6326ef8297bd157942f685d0

See more details on using hashes here.

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