zamba.data.video¶
VideoLoaderConfig
¶
Bases: BaseModel
Configuration for load_video_frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
crop_bottom_pixels |
int
|
Number of pixels to crop from the bottom of the video
(prior to resizing to |
required |
i_frames |
bool
|
Only load the I-Frames. See https://en.wikipedia.org/wiki/Video_compression_picture_types#Intra-coded_(I)frames/slices(key_frames) |
required |
scene_threshold |
float
|
Only load frames that correspond to scene changes. See http://www.ffmpeg.org/ffmpeg-filters.html#select_002c-aselect |
required |
megadetector_lite_config |
MegadetectorLiteYoloXConfig
|
Configuration of MegadetectorLiteYoloX frame selection model. |
required |
frame_selection_height |
int
|
Resize the video to this height in pixels, prior to frame selection. If None, the full size video will be used for frame selection. Using full size images (setting to None) is recommended for MegadetectorLite, especially if your species of interest are smaller. |
required |
frame_selection_width |
int
|
Resize the video to this width in pixels, prior to frame selection. |
required |
total_frames |
int
|
Number of frames that should ultimately be returned. |
required |
ensure_total_frames |
bool
|
Selecting the number of frames by resampling may result in one more or fewer frames due to rounding. If True, ensure the requested number of frames is returned by either clipping or duplicating the final frame. Raises an error if no frames have been selected. Otherwise, return the array unchanged. |
required |
fps |
float
|
Resample the video evenly from the entire duration to a specific number of frames per second. |
required |
early_bias |
bool
|
Resamples to 24 fps and selects 16 frames biased toward the front (strategy used by competition winner). |
required |
frame_indices |
list(int)
|
Select specific frame numbers. Note: frame selection is done after any resampling. |
required |
evenly_sample_total_frames |
bool
|
Reach the total number of frames specified by evenly sampling from the duration of the video. Defaults to False. |
required |
pix_fmt |
str
|
ffmpeg pixel format, defaults to 'rgb24' for RGB channels; can be changed to 'bgr24' for BGR. |
required |
model_input_height |
int
|
After frame selection, resize the video to this height in pixels. |
required |
model_input_width |
int
|
After frame selection, resize the video to this width in pixels. |
required |
cache_dir |
Path
|
Cache directory where preprocessed videos will be saved upon first load. Alternatively, can be set with VIDEO_CACHE_DIR environment variable. Defaults to None, which means videos will not be cached. Provided there is enough space on your machine, it is highly encouraged to cache videos for training as this will speed up all subsequent epochs. If you are predicting on the same videos with the same video loader configuration, this will save time on future runs. |
required |
cleanup_cache |
bool
|
Whether to delete the cache dir after training or predicting ends. Defaults to False. |
required |
Source code in zamba/data/video.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 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 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
validate_video_cache_dir(cache_dir)
¶
Set up cache directory for preprocessed videos. Config argument takes precedence over environment variable.
Source code in zamba/data/video.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
ensure_frame_number(arr, total_frames)
¶
Ensures the array contains the requested number of frames either by clipping frames from the end or dulpicating the last frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr |
ndarray
|
Array of video frames with shape (frames, height, width, channel). |
required |
total_frames |
int
|
Desired number of frames in output array. |
required |
Source code in zamba/data/video.py
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 |
|
get_cached_array_path(vid_path, config)
¶
Get the path to where the cached array would be, if it exists.
vid_path: string path to the video, or Path config: VideoLoaderConfig
returns: Path object to the cached data
Source code in zamba/data/video.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
load_video_frames(filepath, config=None, **kwargs)
¶
Loads frames from videos using fast ffmpeg commands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
PathLike
|
Path to the video. |
required |
config |
VideoLoaderConfig
|
Configuration for video loading. |
None
|
**kwargs |
Optionally, arguments for VideoLoaderConfig can be passed in directly. |
{}
|
Returns:
Type | Description |
---|---|
np.ndarray: An array of video frames with dimensions (time x height x width x channels). |
Source code in zamba/data/video.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|