| 57 | if '-' in i else [int(i)]) for i in s.split(',')), []) |
| 58 | |
| 59 | def unpack(args, idx, row): |
| 60 | #pprint(row) |
| 61 | path = f"{args.target_path}/{idx}" |
| 62 | Path(path).mkdir(parents=True, exist_ok=True) |
| 63 | for i, img in enumerate(row["images"]): |
| 64 | basename = f"{path}/images_{i:02d}" |
| 65 | ext = "null" if img is None else "jpg" |
| 66 | file = f"{basename}.{ext}" |
| 67 | with open(file, "w") as fh: |
| 68 | if img is not None: |
| 69 | img.save(fh, 'jpeg') |
| 70 | for i, txt in enumerate(row["texts"]): |
| 71 | basename = f"{path}/texts_{i:02d}" |
| 72 | ext = "null" if txt is None else "txt" |
| 73 | file = f"{basename}.{ext}" |
| 74 | with open(file, "w") as fh: |
| 75 | if txt is not None: |
| 76 | fh.write(txt) |
| 77 | |
| 78 | def dump_example_shapes(idx, row): |
| 79 | """ dump the row stats """ |