-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathpil.py
More file actions
32 lines (24 loc) · 825 Bytes
/
Copy pathpil.py
File metadata and controls
32 lines (24 loc) · 825 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
28
29
30
31
32
"""Pil: uncompressed pixels, stream a PIL.Image.
Use Image / Jpeg for training photos. Use Pil when you need lossless pixels.
"""
import numpy as np
from PIL import Image as PILImage
from litdata import Pil, StreamingDataset, optimize
def make_sample(index: int) -> dict:
hwc = np.random.randint(0, 256, (64, 64, 3), np.uint8)
return {
"index": index,
# Pil(path="a.png")
"image": Pil(image=PILImage.fromarray(hwc), mode="RGB"),
}
if __name__ == "__main__":
optimize(
fn=make_sample,
inputs=list(range(8)),
output_dir="example_optimize_dataset/pil",
num_workers=2,
chunk_bytes="64MB",
)
sample = StreamingDataset("example_optimize_dataset/pil")[0]
pil_img = sample["image"] # PIL.Image
print(pil_img.size, pil_img.mode)