Skip to content

Commit

Permalink
NNFF: use substitute.toml for fallback model lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
twilsonco committed Dec 16, 2024
1 parent 1042a55 commit e0362d6
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e0362d6

Please sign in to comment.