Reference for ultralytics/data/loaders.py
Note
Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/data/loaders.py. Help us fix any issues you see by submitting a Pull Request 🛠️. Thank you 🙏!
ultralytics.data.loaders.SourceTypes
dataclass
ultralytics.data.loaders.LoadStreams
YOLOv8 streamloader, i.e. yolo predict source='rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP streams
.
Source code in ultralytics/data/loaders.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
__init__(sources='file.streams', imgsz=640, vid_stride=1, buffer=False)
Initialize instance variables and check for consistent input stream shapes.
Source code in ultralytics/data/loaders.py
__iter__()
__len__()
__next__()
Returns source paths, transformed and original images for processing.
Source code in ultralytics/data/loaders.py
close()
Close stream loader and release resources.
Source code in ultralytics/data/loaders.py
update(i, cap, stream)
Read stream i
frames in daemon thread.
Source code in ultralytics/data/loaders.py
ultralytics.data.loaders.LoadScreenshots
YOLOv8 screenshot dataloader, i.e. yolo predict source=screen
.
Source code in ultralytics/data/loaders.py
__init__(source, imgsz=640)
source = [screen_number left top width height] (pixels).
Source code in ultralytics/data/loaders.py
__iter__()
__next__()
mss screen capture: get raw pixels from the screen as np array.
Source code in ultralytics/data/loaders.py
ultralytics.data.loaders.LoadImages
YOLOv8 image/video dataloader, i.e. yolo predict source=image.jpg/vid.mp4
.
Source code in ultralytics/data/loaders.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
__init__(path, imgsz=640, vid_stride=1)
Initialize the Dataloader and raise FileNotFoundError if file not found.
Source code in ultralytics/data/loaders.py
__iter__()
__len__()
__next__()
Return next image, path and metadata from dataset.
Source code in ultralytics/data/loaders.py
ultralytics.data.loaders.LoadPilAndNumpy
Source code in ultralytics/data/loaders.py
__init__(im0, imgsz=640)
Initialize PIL and Numpy Dataloader.
Source code in ultralytics/data/loaders.py
__iter__()
__len__()
__next__()
Returns batch paths, images, processed images, None, ''.
ultralytics.data.loaders.LoadTensor
Source code in ultralytics/data/loaders.py
__iter__()
__len__()
ultralytics.data.loaders.autocast_list(source)
Merges a list of source of different types into a list of numpy arrays or PIL images
Source code in ultralytics/data/loaders.py
ultralytics.data.loaders.get_best_youtube_url(url, use_pafy=False)
Retrieves the URL of the best quality MP4 video stream from a given YouTube video.
This function uses the pafy or yt_dlp library to extract the video info from YouTube. It then finds the highest quality MP4 format that has video codec but no audio codec, and returns the URL of this video stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL of the YouTube video. |
required |
use_pafy |
bool
|
Use the pafy package, default=True, otherwise use yt_dlp package. |
False
|
Returns:
Type | Description |
---|---|
str
|
The URL of the best quality MP4 video stream, or None if no suitable stream is found. |