Data Handling and Preparation
Data handling and preparation are crucial steps in the workflow of our Object Detection App. This process involves importing images, annotating them with bounding boxes, augmenting the data for diversity, and exporting the prepared data for further use. The prepared data can then be used to train the model <./_model/user.html> that will be selected later. Each of these tasks is designed to ensure the quality and suitability of the data for object detection tasks, providing a seamless workflow from data import to model training.
Importation
a. Local Importation
The FilesHandler class Handles a collection of files, separating them by type and performing default handling.
Remove empty Method: remove_empty : Removes empty files from the list of files.
Pair Method: pair : Pairs image and label files based on their names.
Separate files by type Method: separate_files_by_type : Separates files into two lists based on their types: images and labels.
Default handling Method: default_handling : Performs default handling of files:
Removes empty files.
Separates files by type (images and labels).
Pairs images and labels based on names.
b. External Importation
The FileCsvHandler class Handles CSV files containing image links and labels.
Fetch Images Method: fetch_images : Fetches images from the provided image links.
Pair Method: pair : Pairs images with labels and handles empty labels.
Remove Empty Method: remove_empty : Removes pairs with empty images or labels.
Default Handling Method: default_handling : Performs default handling of the CSV file:
Note
In this module, as well as in others, processed files are required to furnish their names. Consequently, an extended file-like class has been implemented to facilitate this handling.
- class NamedBytesIO(BytesIO)
A subclass of BytesIO with an additional ‘name’ attribute.
- param initial_bytes:
Initial bytes for the BytesIO.
- type initial_bytes:
bytes, optional
- param name:
The name associated with the BytesIO object.
- type name:
str, optional
- ivar name:
The name associated with the BytesIO object
Image Handling
a. Image Transformation
The ImageTrans class is designed for transforming and annotating images with bounding boxes.
Get image boxes Method: get_image_boxes : Extracts image and bounding box information from input data.
Bounding box method: bounding_box : Draws bounding boxes on the image.
Show Method: show : Displays the image with bounding boxes using OpenCV.
Get annotated image Method: get_annotated_image : Returns an annotated image with bounding boxes.
b. Showing Images
The ImageShow class is designed for displaying a grid of images.
Show Method: show : Displays a grid of images using Matplotlib.
Note
The Matplotlib library is used for creating plots and displaying images. For more information, refer to the Matplotlib documentation.
Note
The PIL (Python Imaging Library) is used for handling image data. For more information, refer to the PIL Documentation.
Data Augmentation
The Augmenter class is designed for data augmentation on images and bounding boxes.
Augment Method: augment : Applies specified augmentations to the image and bounding boxes.
Get Augmented Files Method: get_augmented_files : Returns augmented image and label as NamedBytesIO objects.
Get Annotated Image Method: get_annotated_image : Returns annotated image with bounding boxes.
Data Exportation
The Exporter Class for exporting paired image and label data to a local directory.
Augment Method: split_data : Splits the paired data into training, validation, and test sets.
Get Augmented Files Method: export_local : Exports the paired data to a local directory.
Get Annotated Image Method: default_handling : Performs the default handling of data export.