forked from Lightning-AI/litData
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpeg_array.py
More file actions
27 lines (20 loc) · 780 Bytes
/
Copy pathjpeg_array.py
File metadata and controls
27 lines (20 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""JpegArray: a list of JPEGs, stream a list of CHW tensors."""
import numpy as np
from litdata import Jpeg, JpegArray, StreamingDataset, optimize
def make_sample(index: int) -> dict:
frames = [np.random.randint(0, 256, (32, 32, 3), np.uint8) for _ in range(4)]
return {
"index": index,
"frames": JpegArray(images=[Jpeg(array=frame, quality=95) for frame in frames]),
}
if __name__ == "__main__":
optimize(
fn=make_sample,
inputs=list(range(8)),
output_dir="example_optimize_dataset/jpeg_array",
num_workers=2,
chunk_bytes="64MB",
)
sample = StreamingDataset("example_optimize_dataset/jpeg_array")[0]
images = sample["frames"] # list of Tensor CHW
print(len(images), images[0].shape)