Object detection
Last updated
Last updated
Object detection models identify something in an image, and object detection datasets are used for applications such as autonomous driving and detecting natural hazards like wildfire. This guide will show you how to apply transformations to an object detection dataset following the from .
To run these examples, make sure you have up-to-date versions of albumentations
and cv2
installed:
Copied
In this example, you’ll use the dataset for identifying medical personal protective equipment (PPE) in the context of the COVID-19 pandemic.
Load the dataset and take a look at an example:
Copied
The dataset has the following fields:
image
: PIL.Image.Image object containing the image.
image_id
: The image ID.
height
: The image height.
width
: The image width.
objects
: A dictionary containing bounding box metadata for the objects in the image:
id
: The annotation id.
area
: The area of the bounding box.
category
: The object’s category, with possible values including Coverall (0)
, Face_Shield (1)
, Gloves (2)
, Goggles (3)
and Mask (4)
.
Copied
With albumentations
, you can apply transforms that will affect the image while also updating the bboxes
accordingly. In this case, the image is resized to (480, 480), flipped horizontally, and brightened.
albumentations
expects the image to be in BGR format, not RGB, so you’ll have to convert the image before applying the transform.
Copied
Now when you visualize the result, the image should be flipped, but the bboxes
should still be in the right places.
Copied
Create a function to apply the transform to a batch of examples:
Copied
Copied
You can verify the transform works by visualizing the 10th example:
Copied
bbox
: The object’s bounding box (in the format).
You can visualize the bboxes
on the image using some internal torch utilities. To do that, you will need to reference the feature associated with the category IDs so you can look up the string labels:
Use the function to apply the transform on-the-fly which consumes less disk space. The randomness of data augmentation may return a different image if you access the same example twice. It is especially useful when training a model for several epochs.
Now that you know how to process a dataset for object detection, learn and use it for inference.