Download code/training_admin/portable_dataset.py from FrontRear/VideoObjectMover: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/FrontRear/VideoObjectMover/resolve/8cdc6af0ea8b0d1b2994d79fe9d182bfbb55e08e/code/training_admin/portable_dataset.py
- Command line
-
hf download hf://datasets/FrontRear/VideoObjectMover@8cdc6af0ea8b0d1b2994d79fe9d182bfbb55e08e/code/training_admin/portable_dataset.py
-
curl -L -o portable_dataset.py https://huggingface.co/datasets/FrontRear/VideoObjectMover/resolve/8cdc6af0ea8b0d1b2994d79fe9d182bfbb55e08e/code/training_admin/portable_dataset.py
1.17 kB
| """Relocatable loader: source/target/joint RGB and float32 physical lights.""" | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| from PIL import Image | |
| from float_fields import load_video | |
| class PortableDataset: | |
| def __init__(self,root,manifest): | |
| self.root=Path(root);self.rows=json.loads(Path(manifest).read_text()) | |
| assert self.rows and all(r['ready_for_training'] for r in self.rows) | |
| assert len({r['sample_id'] for r in self.rows})==len(self.rows) | |
| def __len__(self):return len(self.rows) | |
| def __getitem__(self,i): | |
| r=self.rows[i];data={} | |
| for k in ('source','target','joint'): | |
| paths=sorted((self.root/r[k]).glob('*.png'));assert len(paths)==49 | |
| frames=[] | |
| for p in paths: | |
| with Image.open(p) as im:assert im.size==(640,352);frames.append(np.asarray(im.convert('RGB'))) | |
| data[k]=np.stack(frames) | |
| for k in ('color','intensity'):data[k]=load_video(self.root/r[k],k) | |
| assert all(v.shape==(49,352,640,3) for v in data.values()) | |
| data.update(prompt=r['prompt'],ambient=float(r['ambient']),sample_id=r['sample_id']) | |
| return data | |