File size: 3,448 Bytes
871e4fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""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)