zamba.data.video¶
Classes¶
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 |
|
Attributes¶
cache_dir: Optional[Path] = None
class-attribute
¶
cleanup_cache: bool = False
class-attribute
¶
crop_bottom_pixels: Optional[int] = None
class-attribute
¶
early_bias: Optional[bool] = False
class-attribute
¶
ensure_total_frames: Optional[bool] = True
class-attribute
¶
evenly_sample_total_frames: Optional[bool] = False
class-attribute
¶
fps: Optional[float] = None
class-attribute
¶
frame_indices: Optional[List[int]] = None
class-attribute
¶
frame_selection_height: Optional[int] = None
class-attribute
¶
frame_selection_width: Optional[int] = None
class-attribute
¶
i_frames: Optional[bool] = False
class-attribute
¶
megadetector_lite_config: Optional[MegadetectorLiteYoloXConfig] = None
class-attribute
¶
model_input_height: Optional[int] = None
class-attribute
¶
model_input_width: Optional[int] = None
class-attribute
¶
pix_fmt: Optional[str] = 'rgb24'
class-attribute
¶
scene_threshold: Optional[float] = None
class-attribute
¶
total_frames: Optional[int] = None
class-attribute
¶
Classes¶
Config
¶
Functions¶
check_early_bias_compatibility(values)
¶
Source code in zamba/data/video.py
259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
check_evenly_sample_total_frames_compatibility(values)
¶
Source code in zamba/data/video.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
check_fps_compatibility(values)
¶
Source code in zamba/data/video.py
241 242 243 244 245 246 247 248 249 |
|
check_frame_indices_compatibility(values)
¶
Source code in zamba/data/video.py
273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
check_height_and_width(values)
¶
Source code in zamba/data/video.py
229 230 231 232 233 234 235 236 237 238 239 |
|
check_i_frame_compatibility(values)
¶
Source code in zamba/data/video.py
251 252 253 254 255 256 257 |
|
check_megadetector_lite_compatibility(values)
¶
Source code in zamba/data/video.py
287 288 289 290 291 292 293 294 295 |
|
validate_total_frames(values)
¶
Source code in zamba/data/video.py
314 315 316 317 318 319 320 321 322 323 324 325 |
|
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 |
|
VideoMetadata
¶
Bases: BaseModel
Source code in zamba/data/video.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
Attributes¶
duration_s: float
class-attribute
¶
fps: int
class-attribute
¶
height: int
class-attribute
¶
n_frames: int
class-attribute
¶
width: int
class-attribute
¶
Functions¶
from_video(path: os.PathLike)
classmethod
¶
Source code in zamba/data/video.py
134 135 136 137 138 139 140 141 142 143 |
|
npy_cache
¶
Source code in zamba/data/video.py
328 329 330 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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
Attributes¶
cache_path = cache_path
instance-attribute
¶
cleanup = cleanup
instance-attribute
¶
Functions¶
__init__(cache_path: Optional[Path] = None, cleanup: bool = False)
¶
Source code in zamba/data/video.py
329 330 331 |
|
Functions¶
ensure_frame_number(arr, total_frames: int)
¶
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 |
np.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 |
|
ffprobe(path: os.PathLike) -> pd.Series
¶
Source code in zamba/data/video.py
28 29 30 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 |
|
get_frame_time_estimates(path: os.PathLike)
¶
Source code in zamba/data/video.py
122 123 124 |
|
get_video_stream(path: Union[os.PathLike, S3Path]) -> dict
¶
Source code in zamba/data/video.py
58 59 60 61 62 63 64 |
|
load_video_frames(filepath: os.PathLike, config: Optional[VideoLoaderConfig] = None, **kwargs)
¶
Loads frames from videos using fast ffmpeg commands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
os.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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 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 |
|
num_frames(stream_or_path: Union[dict, os.PathLike, S3Path]) -> Optional[int]
¶
Source code in zamba/data/video.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|