Static batch the data by `batch_size` Args: data: Iterable[{key, feat, label}] batch_size: batch size Returns: Iterable[List[{key, feat, label}]]
(data, batch_size=32)
| 373 | |
| 374 | |
| 375 | def static_batch(data, batch_size=32): |
| 376 | """ Static batch the data by `batch_size` |
| 377 | |
| 378 | Args: |
| 379 | data: Iterable[{key, feat, label}] |
| 380 | batch_size: batch size |
| 381 | |
| 382 | Returns: |
| 383 | Iterable[List[{key, feat, label}]] |
| 384 | """ |
| 385 | buf = [] |
| 386 | data_empty = True |
| 387 | for sample in data: |
| 388 | data_empty = False |
| 389 | buf.append(sample) |
| 390 | if len(buf) >= batch_size: |
| 391 | yield buf |
| 392 | buf = [] |
| 393 | if data_empty: |
| 394 | raise ValueError("data is empty") |
| 395 | if len(buf) > 0: |
| 396 | yield buf |
| 397 | |
| 398 | |
| 399 | def dynamic_batch(data, max_frames_in_batch=12000, mode='train'): |