diff --git a/utils/datasets.py b/utils/datasets.py index a54e29fd2908..cff6dc550900 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -155,7 +155,8 @@ def __iter__(self): yield from iter(self.sampler) -class LoadImages: # for inference +class LoadImages: + # YOLOv5 image/video dataloader, i.e. `python detect.py --source image.jpg/vid.mp4` def __init__(self, path, img_size=640, stride=32, auto=True): p = str(Path(path).resolve()) # os-agnostic absolute path if '*' in p: @@ -237,6 +238,7 @@ def __len__(self): class LoadWebcam: # for inference + # YOLOv5 local webcam dataloader, i.e. `python detect.py --source 0` def __init__(self, pipe='0', img_size=640, stride=32): self.img_size = img_size self.stride = stride @@ -277,7 +279,8 @@ def __len__(self): return 0 -class LoadStreams: # multiple IP or RTSP cameras +class LoadStreams: + # YOLOv5 streamloader, i.e. `python detect.py --source 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP streams` def __init__(self, sources='streams.txt', img_size=640, stride=32, auto=True): self.mode = 'stream' self.img_size = img_size @@ -365,7 +368,8 @@ def img2label_paths(img_paths): return [sb.join(x.rsplit(sa, 1)).rsplit('.', 1)[0] + '.txt' for x in img_paths] -class LoadImagesAndLabels(Dataset): # for training/testing +class LoadImagesAndLabels(Dataset): + # YOLOv5 train_loader/val_loader, loads images and labels for training and validation cache_version = 0.5 # dataset labels *.cache version def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False, @@ -659,8 +663,7 @@ def load_image(self, i): def load_mosaic(self, index): - # loads images in a 4-mosaic - + # YOLOv5 4-mosaic loader. Loads 1 image + 3 random images into a 4-image mosaic labels4, segments4 = [], [] s = self.img_size yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border] # mosaic center x, y @@ -717,8 +720,7 @@ def load_mosaic(self, index): def load_mosaic9(self, index): - # loads images in a 9-mosaic - + # YOLOv5 9-mosaic loader. Loads 1 image + 8 random images into a 9-image mosaic labels9, segments9 = [], [] s = self.img_size indices = [index] + random.choices(self.indices, k=8) # 8 additional image indices