mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-08 16:04:50 +08:00
Compare commits
2 Commits
model-test
...
archive/nn
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35a616c235 | ||
|
|
a2f25897d2 |
@@ -5,12 +5,14 @@ This file is part of sunnypilot and is licensed under the MIT License.
|
||||
See the LICENSE.md file in the root directory for more details.
|
||||
"""
|
||||
import os
|
||||
import tomllib
|
||||
from difflib import SequenceMatcher
|
||||
|
||||
from opendbc.car import structs
|
||||
from openpilot.common.basedir import BASEDIR
|
||||
|
||||
TORQUE_NN_MODEL_PATH = os.path.join(BASEDIR, "sunnypilot", "neural_network_data", "neural_network_lateral_control")
|
||||
TORQUE_NN_MODEL_SUBSTITUTE_PATH = os.path.join(BASEDIR, "opendbc", "car", "torque_data/substitute.toml")
|
||||
MOCK_MODEL_PATH = os.path.join(TORQUE_NN_MODEL_PATH, "MOCK.json")
|
||||
|
||||
|
||||
@@ -19,6 +21,7 @@ def similarity(s1: str, s2: str) -> float:
|
||||
|
||||
|
||||
def get_nn_model_path(CP: structs.CarParams) -> tuple[str, str, bool]:
|
||||
exact_match = True
|
||||
car_fingerprint = CP.carFingerprint
|
||||
eps_fw = str(next((fw.fwVersion for fw in CP.carFw if fw.ecu == "eps"), ""))
|
||||
|
||||
@@ -46,12 +49,18 @@ def get_nn_model_path(CP: structs.CarParams) -> tuple[str, str, bool]:
|
||||
nn_candidate = car_fingerprint
|
||||
model_path, max_similarity = check_nn_path(nn_candidate)
|
||||
if 0.0 <= max_similarity < 0.8:
|
||||
model_path = MOCK_MODEL_PATH
|
||||
with open(TORQUE_NN_MODEL_SUBSTITUTE_PATH, 'rb') as f:
|
||||
sub = tomllib.load(f)
|
||||
sub_candidate = sub.get(car_fingerprint, car_fingerprint)
|
||||
|
||||
for candidate in [car_fingerprint, sub_candidate]:
|
||||
model_path, max_similarity = check_nn_path(candidate)
|
||||
|
||||
exact_match = False
|
||||
|
||||
if CP.steerControlType == structs.CarParams.SteerControlType.angle:
|
||||
model_path = MOCK_MODEL_PATH
|
||||
|
||||
model_name = os.path.splitext(os.path.basename(model_path))[0]
|
||||
exact_match = max_similarity >= 0.99
|
||||
|
||||
return model_path, model_name, exact_match
|
||||
|
||||
@@ -13,8 +13,8 @@ from openpilot.sunnypilot.selfdrive.car import interfaces as sunnypilot_interfac
|
||||
|
||||
class TestNNTorqueModel:
|
||||
|
||||
@parameterized.expand([(HONDA.HONDA_CIVIC, True), (TOYOTA.TOYOTA_RAV4, True), (HYUNDAI.HYUNDAI_SANTA_CRUZ_1ST_GEN, False)])
|
||||
def test_load_model(self, car_name, should_load_model):
|
||||
@parameterized.expand([HONDA.HONDA_CIVIC, TOYOTA.TOYOTA_RAV4, HYUNDAI.HYUNDAI_SANTA_CRUZ_1ST_GEN])
|
||||
def test_load_model(self, car_name):
|
||||
params = Params()
|
||||
params.put_bool("NeuralNetworkLateralControl", True)
|
||||
|
||||
@@ -29,4 +29,4 @@ class TestNNTorqueModel:
|
||||
|
||||
controller = LatControlTorque(CP.as_reader(), CP_SP.as_reader(), CI)
|
||||
|
||||
assert_equal(should_load_model, controller.extension.has_nn_model)
|
||||
assert controller.extension.has_nn_model
|
||||
|
||||
Reference in New Issue
Block a user