6
6
from typing import Any
7
7
from itertools import zip_longest
8
8
9
- from tqdm import tqdm
10
-
11
9
import cereal .messaging as messaging
12
10
from cereal .visionipc .visionipc_pyx import VisionIpcServer , VisionStreamType # pylint: disable=no-name-in-module, import-error
13
11
from common .spinner import Spinner
14
12
from common .timeout import Timeout
15
13
from common .transformations .camera import get_view_frame_from_road_frame , eon_f_frame_size , tici_f_frame_size , \
16
- eon_d_frame_size , tici_d_frame_size
14
+ eon_d_frame_size , tici_d_frame_size
17
15
from selfdrive .hardware import PC , TICI
18
16
from selfdrive .manager .process_config import managed_processes
19
17
from selfdrive .test .openpilotci import BASE_URL , get_url
27
25
TEST_ROUTE = "4cf7a6ad03080c90|2021-09-29--13-46-36"
28
26
else :
29
27
TEST_ROUTE = "303055c0002aefd1|2021-11-22--18-36-32"
28
+ SEGMENT = 0
30
29
31
- CACHE_DIR = os .getenv ("CACHE_DIR " , None )
30
+ SEND_EXTRA_INPUTS = bool ( os .getenv ("SEND_EXTRA_INPUTS " , "0" ) )
32
31
33
32
VIPC_STREAM = {"roadCameraState" : VisionStreamType .VISION_STREAM_ROAD , "driverCameraState" : VisionStreamType .VISION_STREAM_DRIVER ,
34
33
"wideRoadCameraState" : VisionStreamType .VISION_STREAM_WIDE_ROAD }
35
34
36
35
def get_log_fn (ref_commit ):
37
- return "%s_%s_%s.bz2" % (TEST_ROUTE , "model_tici" if TICI else "model" , ref_commit )
36
+ return f"{ TEST_ROUTE } _{ 'model_tici' if TICI else 'model' } _{ ref_commit } .bz2"
37
+
38
38
39
39
def replace_calib (msg , calib ):
40
40
msg = msg .as_builder ()
41
41
if calib is not None :
42
42
msg .liveCalibration .extrinsicMatrix = get_view_frame_from_road_frame (* calib , 1.22 ).flatten ().tolist ()
43
43
return msg
44
44
45
- def process_frame (msg , pm , sm , log_msgs , vipc_server , spinner , frs , frame_idxs , last_desire ):
46
- if msg .which () == "roadCameraState" and last_desire is not None :
47
- dat = messaging .new_message ('lateralPlan' )
48
- dat .lateralPlan .desire = last_desire
49
- pm .send ('lateralPlan' , dat )
50
-
51
- f = msg .as_builder ()
52
- pm .send (msg .which (), f )
53
-
54
- img = frs [msg .which ()].get (frame_idxs [msg .which ()], pix_fmt = "yuv420p" )[0 ]
55
- if msg .which == "roadCameraState" :
56
- vipc_server .send (VisionStreamType .VISION_STREAM_ROAD , img .flatten ().tobytes (), f .roadCameraState .frameId ,
57
- f .roadCameraState .timestampSof , f .roadCameraState .timestampEof )
58
- else :
59
- vipc_server .send (VisionStreamType .VISION_STREAM_DRIVER , img .flatten ().tobytes (), f .driverCameraState .frameId ,
60
- f .driverCameraState .timestampSof , f .driverCameraState .timestampEof )
61
- with Timeout (seconds = 15 ):
62
- log_msgs .append (messaging .recv_one (sm .sock [packet_from_camera [msg .which ()]]))
63
-
64
- frame_idxs [msg .which ()] += 1
65
- if frame_idxs [msg .which ()] >= frs [msg .which ()].frame_count :
66
- return None
67
- update_spinner (spinner , frame_idxs ['roadCameraState' ], frs ['roadCameraState' ].frame_count ,
68
- frame_idxs ['driverCameraState' ], frs ['driverCameraState' ].frame_count )
69
- return 0
70
-
71
- def update_spinner (s , fidx , fcnt , didx , dcnt ):
72
- s .update ("replaying models: road %d/%d, driver %d/%d" % (fidx , fcnt , didx , dcnt ))
73
-
74
- def model_replay (lr_list , frs ):
45
+
46
+ def model_replay (lr , frs ):
75
47
spinner = Spinner ()
76
48
spinner .update ("starting model replay" )
77
49
@@ -90,13 +62,16 @@ def model_replay(lr_list, frs):
90
62
time .sleep (5 )
91
63
sm .update (1000 )
92
64
65
+ log_msgs = []
93
66
last_desire = None
94
67
recv_cnt = defaultdict (lambda : 0 )
95
68
frame_idxs = defaultdict (lambda : 0 )
96
69
97
- cal = [msg for msg in lr if msg .which () == "liveCalibration" ]
98
- for msg in cal [:5 ]:
99
- pm .send (msg .which (), replace_calib (msg , None ))
70
+ # init modeld with valid calibration
71
+ cal_msgs = [msg for msg in lr if msg .which () == "liveCalibration" ]
72
+ for _ in range (5 ):
73
+ pm .send (cal_msgs [0 ].which (), cal_msgs [0 ].as_builder ())
74
+ time .sleep (0.1 )
100
75
101
76
msgs = defaultdict (list )
102
77
for msg in lr :
@@ -157,15 +132,13 @@ def model_replay(lr_list, frs):
157
132
managed_processes ['modeld' ].stop ()
158
133
managed_processes ['dmonitoringmodeld' ].stop ()
159
134
135
+
160
136
return log_msgs
161
137
138
+
162
139
if __name__ == "__main__" :
163
140
164
141
update = "--update" in sys .argv
165
-
166
- if TICI :
167
- os .system ('sudo mount -o remount,size=200M /tmp' ) # c3 hevcs are 75M each
168
-
169
142
replay_dir = os .path .dirname (os .path .abspath (__file__ ))
170
143
ref_commit_fn = os .path .join (replay_dir , "model_replay_ref_commit" )
171
144
@@ -178,12 +151,14 @@ def model_replay(lr_list, frs):
178
151
if TICI :
179
152
frs ['wideRoadCameraState' ] = FrameReader (get_url (TEST_ROUTE , SEGMENT , log_type = "ecamera" ))
180
153
181
- lr_list = list ( lr )
182
- log_msgs = model_replay (lr_list , frs )
154
+ # run replay
155
+ log_msgs = model_replay (lr , frs )
183
156
157
+ # get diff
184
158
failed = False
185
159
if not update :
186
- ref_commit = open (ref_commit_fn ).read ().strip ()
160
+ with open (ref_commit_fn ) as f :
161
+ ref_commit = f .read ().strip ()
187
162
log_fn = get_log_fn (ref_commit )
188
163
try :
189
164
cmp_log = LogReader (BASE_URL + log_fn )
@@ -209,6 +184,7 @@ def model_replay(lr_list, frs):
209
184
print (str (e ))
210
185
failed = True
211
186
187
+ # upload new refs
212
188
if update or failed :
213
189
from selfdrive .test .openpilotci import upload_file
214
190
0 commit comments