Bingsu commited on
Commit
6813784
1 Parent(s): 1cd04b2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -20
README.md CHANGED
@@ -75,30 +75,29 @@ img2dataset을 통해 다운로드에 성공한 [Bingsu/laion2B-multi-korean-sub
75
 
76
  ```python
77
  import io
 
78
  from PIL import Image
79
- from torch.utils.data import IterableDataset
80
-
81
- class MyDataset(IterableDataset):
82
- def __init__(self, dataset):
83
- self.dataset = dataset
84
-
85
- def __iter__(self):
86
- for img, meta in self.dataset:
87
- data = {
88
- "image": Image.open(io.BytesIO(img)),
89
- "text": meta["caption"],
90
- "width": meta["width"],
91
- "height": meta["height"],
92
- }
93
- yield data
94
  ```
95
 
96
  ```python
97
- >>> my_dataset = MyDataset(dataset)
98
- >>> next(iter(my_dataset))
99
- {'image': <PIL.WebPImagePlugin.WebPImageFile image mode=RGB size=455x256>,
100
- 'text': '마운트존 광유계진공펌프오일 hiren77p 피스톤 타입…',
101
- 'width': 455,
102
  'height': 256}
103
  ```
104
 
 
75
 
76
  ```python
77
  import io
78
+ import webdataset as wds
79
  from PIL import Image
80
+
81
+ def preprocess(data):
82
+ webp, jsn = data
83
+ img = Image.open(io.BytesIO(webp))
84
+ out = {
85
+ "image": img,
86
+ "text": jsn["caption"],
87
+ "width": jsn["width"],
88
+ "height": jsn["height"]
89
+ }
90
+ return out
91
+
92
+ url = "https://huggingface.co/datasets/Bingsu/laion2b_multi_korean_subset_with_image/resolve/main/data/{00000..02122}.tar"
93
+ dataset = wds.WebDataset(url).shuffle(1000).decode("pil").to_tuple("webp", "json").map(preprocess)
 
94
  ```
95
 
96
  ```python
97
+ >>> next(iter(dataset))
98
+ {'image': <PIL.WebPImagePlugin.WebPImageFile image mode=RGB size=427x256>,
99
+ 'text': '[따블리에]유아동 미술가운, 미술 전신복',
100
+ 'width': 427,
 
101
  'height': 256}
102
  ```
103