Skip to content

Commit

Permalink
Update datasets.py comments (ultralytics#5088)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Oct 7, 2021
1 parent a5c92b5 commit ce6249e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ce6249e

Please sign in to comment.