jxu124 commited on
Commit
6fe49e6
1 Parent(s): 3ef7f59

[fix] remove image decoding

Browse files

Removed the code for image decoding. You should decode image manually using the following code.
```python
from io import BytesIO
from PIL import Image

Image.open(BytesIO(image_bytes))
```

Example:
```python
import datasets
ds = datasets.load_dataset("jxu124/OpenX-Embodiment", "fractal20220817_data", streaming=True, split='train', trust_remote_code=True) # IterDataset
for d in ds:
break
image_bytes = d['data.pickle']['steps'][0]['observation']['image']

from io import BytesIO
from PIL import Image
image_pil = Image.open(BytesIO(image_bytes))
```

Files changed (1) hide show
  1. OpenX-Embodiment.py +4 -9
OpenX-Embodiment.py CHANGED
@@ -15,20 +15,15 @@ except ImportError:
15
 
16
 
17
  def load_webdataset(filepath):
18
- def decode_image(data):
19
  if isinstance(data, dict):
20
- data = {k: decode_image(v) for k, v in data.items()}
21
  elif isinstance(data, tuple) or isinstance(data, list):
22
- data = [decode_image(v) for v in data]
23
  elif isinstance(data, np.ndarray): # wds to datasets
24
  data = data.tolist()
25
- elif isinstance(data, bytes):
26
- if len(data) > 1024:
27
- data = PILImage.open(BytesIO(data))
28
- else:
29
- data = data.decode()
30
  return data
31
- return wds.WebDataset(filepath).decode().map(decode_image)
32
 
33
 
34
  _OPENX_DATASETS = {
 
15
 
16
 
17
  def load_webdataset(filepath):
18
+ def decode_data(data):
19
  if isinstance(data, dict):
20
+ data = {k: decode_data(v) for k, v in data.items()}
21
  elif isinstance(data, tuple) or isinstance(data, list):
22
+ data = [decode_data(v) for v in data]
23
  elif isinstance(data, np.ndarray): # wds to datasets
24
  data = data.tolist()
 
 
 
 
 
25
  return data
26
+ return wds.WebDataset(filepath).decode().map(decode_data)
27
 
28
 
29
  _OPENX_DATASETS = {