torchsig.image_datasets.datasets.yolo_datasets.YOLODatum¶
- class torchsig.image_datasets.datasets.yolo_datasets.YOLODatum(img=None, labels=[])[source]¶
Bases:
objectA class for wrapping YOLO data; contains a single datum for a YOLO dataset, with image and label data together. This class can be treated as a tuple of (image_data, labels/class_id), and can be returned in datasets. If no labels are provided, a class_id can be supplied, and the datum will be represented as (image_data, class_id), otherwise it will be (image_data, labels). A YOLODatum with a class_id and no labels is assumed to have one label at [class_id, 0.5, 0.5, 1, 1].
Methods
adds new labels to the list of labels; Inputs: new_labels: either a list of tuples to add, a single tuple of (class_id, cx, cy, width, height), or an int class_id, in which case (class_id, 0.5, 0.5, 1.0, 1.0) will be added
A function for adding YOLO labels for boxes in one image to the appropriate labels for the same boxes in a larger composite image containing the smaller image; automatically deletes labels for boxes which do not fall entirely inside of the larger image. this object will be modified to contain the labels from yolo_datum, trasposed appropriately. Inputs: yolo_datum: the pair (img1, old_labels), where img1 is the smaller image on which old_labels are accurate as a torch [n_channels, height, width] tensor top_left: the coordinates of the top left corner of img1 within img2, as (y,x). such that img2[:,y,x] is the top left corner of img1.
A function for composing this YOLODatum with another YOLODatum, such that the resulting image composes the two image with yolo_datum.img starting at top_left in self.img,
A function for transposing YOLO labels for boxes in one image to the appropriate labels for the same boxes in a larger composite image containing the smaller image; Inputs: yolo_datum: the pair (img1, old_labels), where img1 is the smaller image on which old_labels are accurate as a torch [n_channels, height, width] tensor top_left: the coordinates of the top left corner of img1 within self.img, as (x,y). such that self.img[:,y,x] is the top left corner of img1 Outputs: new_labels: the new YOLO labels which describe the boxes from old_labels in self.img.
Attributes
- append_labels(new_labels)[source]¶
adds new labels to the list of labels; Inputs:
new_labels: either a list of tuples to add, a single tuple of (class_id, cx, cy, width, height), or an int class_id, in which case (class_id, 0.5, 0.5, 1.0, 1.0) will be added
- transpose_yolo_labels(yolo_datum, top_left)[source]¶
A function for transposing YOLO labels for boxes in one image to the appropriate labels for the same boxes in a larger composite image containing the smaller image; Inputs:
yolo_datum: the pair (img1, old_labels), where img1 is the smaller image on which old_labels are accurate as a torch [n_channels, height, width] tensor top_left: the coordinates of the top left corner of img1 within self.img, as (x,y). such that self.img[:,y,x] is the top left corner of img1
- Outputs:
new_labels: the new YOLO labels which describe the boxes from old_labels in self.img
- append_yolo_labels(yolo_datum, top_left)[source]¶
A function for adding YOLO labels for boxes in one image to the appropriate labels for the same boxes in a larger composite image containing the smaller image; automatically deletes labels for boxes which do not fall entirely inside of the larger image. this object will be modified to contain the labels from yolo_datum, trasposed appropriately. Inputs:
yolo_datum: the pair (img1, old_labels), where img1 is the smaller image on which old_labels are accurate as a torch [n_channels, height, width] tensor top_left: the coordinates of the top left corner of img1 within img2, as (y,x). such that img2[:,y,x] is the top left corner of img1
- compose_yolo_data(yolo_datum, top_left, image_composition_mode='add')[source]¶
- A function for composing this YOLODatum with another YOLODatum, such that the resulting image composes the two image with yolo_datum.img starting at top_left in self.img,
and the resulting labels contain labels from both YOLODatum objects
- Inputs:
yolo_datum: the datum to compose into this datum top_left: the top left corner as (x,y) in which to append yolo_datum.img image_composition_mode: a string denoting the mode in which to compose the image data from the two images; either ‘replace’, ‘max’, or ‘add’; ‘add’ by default;