Datasets loader

It was developed because the way in which the data sets introduced in a network are presented can vary depending on the type of recognition (detection, classification or segmentation) and even the training mechanism of each network architecture varies, sometimes requiring special preprocessing. For these reasons in this module each file must contain a class that adapts the data set to be introduced in a neural network. Currently it hosts the YoloV3DatasetGenerator class, which takes the annotations of a file containing the locations of the images of the set, its bounding boxes and the class to which the object belongs and adapts them to the network for training and evaluation.

class py2vision.datasets_loader.yolov3_dataset_generator.YoloV3DatasetGenerator(annotations_path, class_file_name, batch_size=4, data_augmentation=True, input_shape=(416, 416, 3), strides=[8, 16, 32], anchors=[[[10, 13], [16, 30], [33, 23]], [[30, 61], [62, 45], [59, 119]], [[116, 90], [156, 198], [373, 326]]], anchor_per_scale=3, max_bbox_per_scale=100, images_to_ram=True)[source]

A generator compatible with YOLO V3 network.

Parameters:
  • annotations_path – a path where the annotations are saved.
  • class_file_name – a path with a .txt file where the classes are saved.
  • batch_size – an integer that corresponds with the number of image which we introduce in a network per iteration.
  • data_augmentation – a boolean that controls data augmentation which change original images in new ways.
  • input_shape – a tuple with the input images dimensions.
  • strides – a list with the strides in a yolo model.
  • anchors – these are the yolo anchors sizes.
  • anchor_per_scale – an integer with the number of anchor boxes per scale.
  • max_bbox_per_scale – nan integer with the number of bounding boxes per scale.
  • images_to_ram – a boolean to control when save images in ram which allow a faster training, but it needs more RAM.
delete_bad_annotation(bad_annotation)[source]

Delete an annotation from annotations file .txt.

Parameters:bad_annotation – a string with the path of an image
load_annotations()[source]

Returns annotations in array shape

parse_annotation(annotation, mAP=False)[source]

Convert an annotation in an image with their bounding boxes.

Parameters:
  • annotation – an annotation line (path bounding box 1, class bounding box 2, class, …)
  • mAP – when it’s true this method won’t resize images and bounding boxes, otherwise it will do.
Returns
images and their bounding boxes.
preprocess_true_boxes(bboxes)[source]

To prepare labels (true_boxes).

Parameters:bboxes – a bounding boxes array.
Returns:Ground true bounding boxes
random_crop(image, bboxes)[source]

There is a probability of 0.5 to make a crop.

Parameters:
  • image – it can be an image or a batch of images.
  • bboxes – this are corresponding bounding boxes.
Returns
images and their bounding boxes.
random_horizontal_flip(image, bboxes)[source]

There is a probability of 0.5 to make an horizontal flip

Parameters:
  • image – it can be an image or a batch of images.
  • bboxes – this are corresponding bounding boxes.
Returns
images and their bounding boxes.
random_translate(image, bboxes)[source]

There is a probability of 0.5 to shift in x and y images.

Parameters:
  • image – it can be an image or a batch of images.
  • bboxes – this are corresponding bounding boxes.
Returns
images and their bounding boxes.