Skip to content

Commit a6bf12d

Browse files
committed
1 parent c152b0c commit a6bf12d

File tree

10 files changed

+35
-72
lines changed

10 files changed

+35
-72
lines changed

selfdrive/controls/lib/lane_planner.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
else:
2828
CAMERA_OFFSET = 0.0 + CameraOffset / 100
2929

30-
3130
# print("New CAMERA_OFFSET value in M is:", CAMERA_OFFSET)
3231

3332
class LanePlanner:
@@ -53,26 +52,15 @@ def __init__(self, wide_camera=False):
5352
self.camera_offset = -CAMERA_OFFSET if wide_camera else CAMERA_OFFSET
5453
self.path_offset = -PATH_OFFSET if wide_camera else PATH_OFFSET
5554

56-
# self.CameraOffset = None
57-
# self.CameraOffset = None
58-
59-
# def update_sunny_set_offsets(self, camera_offset, path_offset):
60-
# if self.CameraOffset != camera_offset:
61-
# self.CameraOffset = camera_offset
62-
# self.camera_offset = camera_offset / 100
63-
64-
# if self.CameraOffset != path_offset:
65-
# self.CameraOffset = path_offset
66-
# self.path_offset = path_offset / 100
6755

6856
def parse_model(self, md):
6957
if len(md.laneLines) == 4 and len(md.laneLines[0].t) == TRAJECTORY_SIZE:
7058
self.ll_t = (np.array(md.laneLines[1].t) + np.array(md.laneLines[2].t))/2
7159
# left and right ll x is the same
7260
self.ll_x = md.laneLines[1].x
7361
# only offset left and right lane lines; offsetting path does not make sense
74-
self.lll_y = np.array(md.laneLines[1].y) - self.camera_offset
75-
self.rll_y = np.array(md.laneLines[2].y) - self.camera_offset
62+
self.lll_y = np.array(md.laneLines[1].y) + self.camera_offset
63+
self.rll_y = np.array(md.laneLines[2].y) + self.camera_offset
7664
self.lll_prob = md.laneLineProbs[1]
7765
self.rll_prob = md.laneLineProbs[2]
7866
self.lll_std = md.laneLineStds[1]
@@ -85,7 +73,7 @@ def parse_model(self, md):
8573
def get_d_path(self, v_ego, path_t, path_xyz):
8674
# Reduce reliance on lanelines that are too far apart or
8775
# will be in a few seconds
88-
path_xyz[:, 1] -= self.path_offset
76+
path_xyz[:, 1] += self.path_offset
8977
l_prob, r_prob = self.lll_prob, self.rll_prob
9078
width_pts = self.rll_y - self.lll_y
9179
prob_mods = []

selfdrive/modeld/SConscript

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
Import('env', 'arch', 'cereal', 'messaging', 'common', 'gpucommon', 'visionipc')
24
lenv = env.Clone()
35

@@ -67,11 +69,14 @@ common_model = lenv.Object(common_src)
6769
if use_thneed and arch in ("aarch64", "larch64"):
6870
fn = "../../models/big_supercombo" if use_extra else "../../models/supercombo"
6971
compiler = lenv.Program('thneed/compile', ["thneed/compile.cc"]+common_model, LIBS=libs)
70-
cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} ../../models/supercombo.dlc ../../models/supercombo.thneed --binary"
72+
cmd = f"cd {Dir('.').abspath} && {compiler[0].abspath} {fn}.dlc {fn}.thneed --binary"
7173

7274
lib_paths = ':'.join(Dir(p).abspath for p in lenv["LIBPATH"])
73-
cenv = Environment(ENV={'LD_LIBRARY_PATH': f"{lib_paths}:{lenv['ENV']['LD_LIBRARY_PATH']}"})
74-
cenv.Command("../../models/supercombo.thneed", ["../../models/supercombo.dlc", compiler], cmd)
75+
kernel_path = os.path.join(Dir('.').abspath, "thneed", "kernels")
76+
cenv = Environment(ENV={'LD_LIBRARY_PATH': f"{lib_paths}:{lenv['ENV']['LD_LIBRARY_PATH']}", 'KERNEL_PATH': kernel_path})
77+
78+
kernels = [os.path.join(kernel_path, x) for x in os.listdir(kernel_path) if x.endswith(".cl")]
79+
cenv.Command(fn + ".thneed", [fn + ".dlc", kernels, compiler], cmd)
7580

7681
lenv.Program('_dmonitoringmodeld', [
7782
"dmonitoringmodeld.cc",

selfdrive/modeld/models/driving.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,8 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, bool
270270
ModelOutput *model_eval_frame(ModelState* s, VisionBuf* buf, VisionBuf* buf_wide,
271271
const mat3 &transform, const mat3 &transform_wide, float *desire_in);
272272
void model_free(ModelState* s);
273-
void poly_fit(float *in_pts, float *in_stds, float *out);
274273
void model_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id, float frame_drop,
275274
const ModelOutput &net_outputs, uint64_t timestamp_eof,
276-
float model_execution_time, kj::ArrayPtr<const float> raw_pred);
275+
float model_execution_time, kj::ArrayPtr<const float> raw_pred, const bool valid);
277276
void posenet_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t vipc_dropped_frames,
278-
const ModelOutput &net_outputs, uint64_t timestamp_eof);
277+
const ModelOutput &net_outputs, uint64_t timestamp_eof, const bool valid);

selfdrive/modeld/runners/onnxmodel.cc

-1
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,3 @@ void ONNXModel::execute() {
129129
}
130130
pread(output, output_size);
131131
}
132-

selfdrive/modeld/runners/onnxmodel.h

-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ class ONNXModel : public RunModel {
3838
int pipein[2];
3939
int pipeout[2];
4040
};
41-

selfdrive/modeld/runners/snpemodel.cc

-1
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,3 @@ void SNPEModel::execute() {
239239
}
240240
#endif
241241
}
242-

selfdrive/modeld/runners/thneedmodel.cc

-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,3 @@ void ThneedModel::execute() {
7070
}
7171
}
7272
}
73-

selfdrive/modeld/runners/thneedmodel.h

-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ class ThneedModel : public RunModel {
2828
float *trafficConvention;
2929
float *desire;
3030
};
31-

selfdrive/test/openpilotci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def get_url(route_name, segment_num, log_type="rlog"):
1111
ext = "hevc" if log_type.endswith('camera') else "bz2"
12-
return BASE_URL + f"{route_name.replace('|', '/')}/{segment_num}/{log_type}.{ext}"
12+
return BASE_URL + "%s/%s/%s.%s" % (route_name.replace("|", "/"), segment_num, log_type, ext)
1313

1414
def upload_file(path, name):
1515
from azure.storage.blob import BlockBlobService # pylint: disable=import-error

selfdrive/test/process_replay/model_replay.py

+21-45
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
from typing import Any
77
from itertools import zip_longest
88

9-
from tqdm import tqdm
10-
119
import cereal.messaging as messaging
1210
from cereal.visionipc.visionipc_pyx import VisionIpcServer, VisionStreamType # pylint: disable=no-name-in-module, import-error
1311
from common.spinner import Spinner
1412
from common.timeout import Timeout
1513
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
1715
from selfdrive.hardware import PC, TICI
1816
from selfdrive.manager.process_config import managed_processes
1917
from selfdrive.test.openpilotci import BASE_URL, get_url
@@ -27,51 +25,25 @@
2725
TEST_ROUTE = "4cf7a6ad03080c90|2021-09-29--13-46-36"
2826
else:
2927
TEST_ROUTE = "303055c0002aefd1|2021-11-22--18-36-32"
28+
SEGMENT = 0
3029

31-
CACHE_DIR = os.getenv("CACHE_DIR", None)
30+
SEND_EXTRA_INPUTS = bool(os.getenv("SEND_EXTRA_INPUTS", "0"))
3231

3332
VIPC_STREAM = {"roadCameraState": VisionStreamType.VISION_STREAM_ROAD, "driverCameraState": VisionStreamType.VISION_STREAM_DRIVER,
3433
"wideRoadCameraState": VisionStreamType.VISION_STREAM_WIDE_ROAD}
3534

3635
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+
3838

3939
def replace_calib(msg, calib):
4040
msg = msg.as_builder()
4141
if calib is not None:
4242
msg.liveCalibration.extrinsicMatrix = get_view_frame_from_road_frame(*calib, 1.22).flatten().tolist()
4343
return msg
4444

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):
7547
spinner = Spinner()
7648
spinner.update("starting model replay")
7749

@@ -90,13 +62,16 @@ def model_replay(lr_list, frs):
9062
time.sleep(5)
9163
sm.update(1000)
9264

65+
log_msgs = []
9366
last_desire = None
9467
recv_cnt = defaultdict(lambda: 0)
9568
frame_idxs = defaultdict(lambda: 0)
9669

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)
10075

10176
msgs = defaultdict(list)
10277
for msg in lr:
@@ -157,15 +132,13 @@ def model_replay(lr_list, frs):
157132
managed_processes['modeld'].stop()
158133
managed_processes['dmonitoringmodeld'].stop()
159134

135+
160136
return log_msgs
161137

138+
162139
if __name__ == "__main__":
163140

164141
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-
169142
replay_dir = os.path.dirname(os.path.abspath(__file__))
170143
ref_commit_fn = os.path.join(replay_dir, "model_replay_ref_commit")
171144

@@ -178,12 +151,14 @@ def model_replay(lr_list, frs):
178151
if TICI:
179152
frs['wideRoadCameraState'] = FrameReader(get_url(TEST_ROUTE, SEGMENT, log_type="ecamera"))
180153

181-
lr_list = list(lr)
182-
log_msgs = model_replay(lr_list, frs)
154+
# run replay
155+
log_msgs = model_replay(lr, frs)
183156

157+
# get diff
184158
failed = False
185159
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()
187162
log_fn = get_log_fn(ref_commit)
188163
try:
189164
cmp_log = LogReader(BASE_URL + log_fn)
@@ -209,6 +184,7 @@ def model_replay(lr_list, frs):
209184
print(str(e))
210185
failed = True
211186

187+
# upload new refs
212188
if update or failed:
213189
from selfdrive.test.openpilotci import upload_file
214190

0 commit comments

Comments
 (0)