From e0362d6763d60ec963e116ac4700ab3e8b98eb04 Mon Sep 17 00:00:00 2001 From: Tim Wilson Date: Mon, 16 Dec 2024 12:36:32 -0700 Subject: [PATCH] NNFF: use substitute.toml for fallback model lookup --- selfdrive/car/interfaces.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 4871ff5a426171..c0d3b96b272648 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -179,18 +179,29 @@ def check_nn_path(check_model): model_path = os.path.join(TORQUE_NN_MODEL_PATH, f) return model_path, max_similarity - if len(eps_firmware) > 3: - eps_firmware = eps_firmware.replace("\\", "") - check_model = f"{car} {eps_firmware}" - else: - check_model = car - model_path, max_similarity = check_nn_path(check_model) - if car not in model_path or 0.0 <= max_similarity < 0.9: - check_model = car + def check_candidate(car, eps_firmware): + if len(eps_firmware) > 3: + eps_firmware = eps_firmware.replace("\\", "") + check_model = f"{car} {eps_firmware}" + else: + check_model = car model_path, max_similarity = check_nn_path(check_model) if car not in model_path or 0.0 <= max_similarity < 0.9: - model_path = None - return model_path + check_model = car + model_path, max_similarity = check_nn_path(check_model) + if car not in model_path or 0.0 <= max_similarity < 0.9: + model_path = None + return model_path, max_similarity + + with open(TORQUE_SUBSTITUTE_PATH, 'rb') as f: + sub = tomllib.load(f) + sub_candidate = sub.get(car, car) + + for candidate in [car, sub_candidate]: + model, similarity_score = check_candidate(candidate, eps_firmware) + if model is not None: + return model + return None def get_nn_model(car, eps_firmware) -> tuple[FluxModel | None, float]: model = get_nn_model_path(car, eps_firmware)