PureOne's picture
Release YEORIN-X v4 reproducible research and engineering package
871e4fa verified
Raw History Blame Contribute Delete
3.45 kB
"""Synthetic stress suite; truth is written separately and never read by replay.
v3 development seed 2718. Evaluation seeds are specified in config/frozen.json.
The camera function is a generator convenience, not a provided engine signal.
"""
import argparse,json
from pathlib import Path
import cv2
import numpy as np
import legacy_rgb_generator as legacy
SCENARIOS=['rotation','off_grid','fresh','occlusion','no_texture','camera_lock',
'zoom_change','scene_cut','gain_change','input_spike']
def make(path,scenario,frames=144,seed=3911):
if scenario not in SCENARIOS:raise ValueError('unknown scenario')
base=scenario if scenario in ['rotation','off_grid','fresh','occlusion','no_texture','camera_lock'] else 'rotation'
cfg=legacy.make(path,base,frames,seed)
path=Path(path)
with np.load(path/'observable.npz') as z:obs={k:z[k].copy() for k in z.files}
with np.load(path/'scoring_truth.npz') as z:truth={k:z[k].copy() for k in z.files}
if scenario=='zoom_change':
for k in range(frames//2,frames):
image=obs['frames'][k]
factor=1+min((k-frames//2)*.012,.3)
a=cv2.getRotationMatrix2D(((cfg['width']-1)/2,(cfg['height']-1)/2),0,factor)
obs['frames'][k]=cv2.warpAffine(image,a,(cfg['width'],cfg['height']))
if scenario=='scene_cut':
# Photometric appearance cut, with same stipulated camera geometry;
# no new translational scene ground truth is inferred.
for k in range(frames//2,frames):obs['frames'][k]=255-obs['frames'][k]
if scenario=='gain_change':
# Input-device scale switches; rendered camera and scoring poses are
# unchanged. A fixed-gain observer must detect or account for the switch.
t0=obs['receipt_times'][frames//2]
idx=np.searchsorted(obs['input_times'],t0)
anchor=obs['input_cumulative'][idx].copy()
obs['input_cumulative'][idx:]=anchor+1.8*(obs['input_cumulative'][idx:]-anchor)
if scenario=='input_spike':
# Deliberately violates the advertised derivative bound while the game
# ignores the extra offset; replay must detect rate-bound violation.
idx=np.searchsorted(obs['input_times'],obs['receipt_times'][frames//2])
obs['input_cumulative'][idx:,0]+=80.
cfg.update(scenario=scenario,seed=seed,version='3.0.0',observer='RGB only',
observation_error_rad=.0012,tracking_width=240,max_features=64,
source_pitch_cap_rad=.10,pixel_cap=cfg['width']*.0125,
correction_modes=['conditional_free_look','strict_unobservable'],
observer_service_s=.016,max_model_age_s=.035,assumed_warp_bound_s=.00025,assumed_control_bound_s=.002,
host_scope='modeled same-native-candidate laboratory',
exact_geometry_score_supported=scenario!='zoom_change')
if scenario in ['zoom_change','scene_cut','gain_change','input_spike']:
np.savez(path/'observable.npz',**obs)
# Truth is unchanged by the added observation/input stressors.
# The unmodified generator already wrote scoring_truth.npz.
(path/'config.json').write_text(json.dumps(cfg,indent=2))
return cfg
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('path');p.add_argument('--scenario',choices=SCENARIOS,default='rotation');p.add_argument('--seed',type=int,default=3911);p.add_argument('--frames',type=int,default=144)
a=p.parse_args();make(a.path,a.scenario,a.frames,a.seed)