Download code/training_admin/float_fields.py from FrontRear/VideoObjectMover: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/datasets/FrontRear/VideoObjectMover/resolve/52dcbcdd3fa287d989e9e79d480ffc8748ffda88/code/training_admin/float_fields.py
- Command line
-
hf download hf://datasets/FrontRear/VideoObjectMover@52dcbcdd3fa287d989e9e79d480ffc8748ffda88/code/training_admin/float_fields.py
-
curl -L -o float_fields.py https://huggingface.co/datasets/FrontRear/VideoObjectMover/resolve/52dcbcdd3fa287d989e9e79d480ffc8748ffda88/code/training_admin/float_fields.py
1.83 kB
| """Lossless float32 light field I/O; deliberately no PIL/uint8/BF16 path.""" | |
| from pathlib import Path | |
| import numpy as np | |
| FORMAT='physical_sphere_area_float32_roi.v001' | |
| def save_frame(path,coverage,origin,linear_rgb,intensity,intensity_max=5000,width=640,height=352): | |
| coverage=np.asarray(coverage,np.float32) | |
| color=(coverage[...,None]*np.asarray(linear_rgb,np.float32)).astype(np.float32) | |
| intensity_field=np.repeat((coverage*np.float32(intensity/intensity_max))[...,None],3,axis=-1) | |
| assert np.isfinite(color).all() and np.isfinite(intensity_field).all() | |
| np.savez_compressed(path,color=color,intensity=intensity_field,origin_xy=np.asarray(origin,np.int32),full_shape_hwc=np.asarray([height,width,3],np.int32)) | |
| def load_frame(path,field): | |
| if field not in ('color','intensity'):raise ValueError(field) | |
| with np.load(path,allow_pickle=False) as record: | |
| a=record[field] | |
| assert a.dtype==np.float32,'Only float32 fields; reject quantized input' | |
| x,y=record['origin_xy'].tolist();shape=tuple(record['full_shape_hwc'].tolist()) | |
| assert len(shape)==3 and shape[2]==3 and a.ndim==3 and a.shape[2]==3 | |
| assert 0<=x<=shape[1] and 0<=y<=shape[0] and x+a.shape[1]<=shape[1] and y+a.shape[0]<=shape[0] | |
| assert np.isfinite(a).all() and (a>=0).all() and (a<=1).all() | |
| full=np.zeros(shape,np.float32) | |
| full[y:y+a.shape[0],x:x+a.shape[1]]=a | |
| return full | |
| def load_video(folder,field,indices=None): | |
| paths=sorted(Path(folder).glob('*.npz')) | |
| assert len(paths)==49, 'full49 fields required' | |
| if indices is not None:paths=[paths[i] for i in indices] | |
| return np.stack([load_frame(p,field) for p in paths]).astype(np.float32,copy=False) | |
| def normalize_for_vae(array): | |
| assert array.dtype==np.float32 | |
| return array*np.float32(2)-np.float32(1) | |