File size: 942 Bytes
c38ca74 |
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 33 34 35 36 37 38 39 40 41 42 43 |
from pathlib import Path
import pandas as pd
import torch
import ujson
import webdataset as wds
from tqdm import tqdm
def load_json(json):
return ujson.loads(json)
load_map = {
'json': load_json,
}
def get_glob(path):
return sorted(Path('.').absolute().glob(path))
def chunker(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
def func(glob_path, combine_all=True):
glob = get_glob(glob_path)
for file in tqdm(glob, position=0):
ds = wds.WebDataset(str(file)).map_dict(**load_map).to_tuple('json')
metas = pd.DataFrame([meta[0]
for meta in tqdm(ds, position=1, leave=False)])
metas.to_parquet(f'{file.stem}.parquet')
if combine_all:
combined = pd.concat(pd.read_parquet(
f'{file.stem}.parquet') for file in tqdm(glob))
combined.to_parquet('combined_meta.parquet')
|