mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-21 13:33:47 +08:00
models: add big model to default model resolution (#1929)
* device
* sunnylink
* lint
* lfs?
* Revert "lfs?"
This reverts commit bcdaec6b4c.
* update path
* Scope the default big model down to the sunnylink schema
* Drop the mock-only default model test
* Move the default model resolver out to separate PR
---------
Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import hashlib
|
||||
|
||||
from openpilot.common.basedir import BASEDIR
|
||||
from openpilot.sunnypilot import get_file_hash
|
||||
from openpilot.sunnypilot.models.model_name import DEFAULT_MODEL
|
||||
from openpilot.sunnypilot.models.model_name import DEFAULT_MODEL, DEFAULT_BIG_MODEL
|
||||
|
||||
DEFAULT_MODEL_NAME_PATH = os.path.join(BASEDIR, "openpilot", "sunnypilot", "models", "model_name.py")
|
||||
MODEL_HASH_PATH = os.path.join(BASEDIR, "openpilot", "sunnypilot", "models", "tests", "model_hash")
|
||||
@@ -13,7 +13,6 @@ SUPERCOMBO_ONNX_PATH = os.path.join(BASEDIR, "openpilot", "selfdrive", "modeld",
|
||||
|
||||
def update_model_hash():
|
||||
supercombo_hash = get_file_hash(SUPERCOMBO_ONNX_PATH)
|
||||
|
||||
combined_hash = hashlib.sha256(supercombo_hash.encode()).hexdigest()
|
||||
|
||||
with open(MODEL_HASH_PATH, "w") as f:
|
||||
@@ -22,40 +21,28 @@ def update_model_hash():
|
||||
print(f"Generated and updated new combined model hash to {MODEL_HASH_PATH}")
|
||||
|
||||
|
||||
def get_current_default_model_name():
|
||||
print("[GET DEFAULT MODEL NAME]")
|
||||
name = DEFAULT_MODEL
|
||||
print(f'Current default model name: "{name}"')
|
||||
|
||||
return name
|
||||
|
||||
|
||||
def update_default_model_name(name: str):
|
||||
print("[CHANGE DEFAULT MODEL NAME]")
|
||||
def update_default_model_names(default_model_name: str, default_big_model_name: str):
|
||||
print("[CHANGE DEFAULT MODEL NAMES]")
|
||||
with open(DEFAULT_MODEL_NAME_PATH, "w") as f:
|
||||
f.write(f'DEFAULT_MODEL = "{name}"\n')
|
||||
print(f'New default model name: "{name}"')
|
||||
f.write(f'DEFAULT_MODEL = "{default_model_name}"\n')
|
||||
f.write(f'DEFAULT_BIG_MODEL = "{default_big_model_name}"\n')
|
||||
|
||||
print(f'New default small model name: "{default_model_name}"')
|
||||
print(f'New default big model name: "{default_big_model_name}"')
|
||||
print("[DONE]")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Update default model name and hash")
|
||||
parser.add_argument("--new_name", type=str, help="New default model name")
|
||||
parser = argparse.ArgumentParser(description="Update default model names and hash")
|
||||
parser.add_argument("--new_small_model_name", type=str, help="New default small model name")
|
||||
parser.add_argument("--new_big_model_name", type=str, help="New default big model name")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.new_name:
|
||||
print("Warning: No new default model name provided. Use --new_name to specify")
|
||||
print("Default model name and hash will not be updated! (aborted)")
|
||||
exit(0)
|
||||
if args.new_small_model_name is None and args.new_big_model_name is None:
|
||||
new_name = input(f'Enter new default small model name (current: "{DEFAULT_MODEL}", leave empty to keep): ').strip()
|
||||
new_big_model_name = input(f'Enter new default big model name (current: "{DEFAULT_BIG_MODEL}", leave empty to keep): ').strip()
|
||||
else:
|
||||
new_name, new_big_model_name = args.new_small_model_name, args.new_big_model_name
|
||||
|
||||
current_name = get_current_default_model_name()
|
||||
new_name = args.new_name
|
||||
if current_name == new_name:
|
||||
print(f'Proposed default model name: "{new_name}"')
|
||||
confirm = input("Proposed default model name is the same as the current default model name. Confirm? (y/n): ").upper().strip()
|
||||
if confirm != "Y":
|
||||
print("Default model name and hash will not be updated! (aborted)")
|
||||
exit(0)
|
||||
|
||||
update_default_model_name(new_name)
|
||||
update_default_model_names(new_name or DEFAULT_MODEL, new_big_model_name or DEFAULT_BIG_MODEL)
|
||||
update_model_hash()
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
DEFAULT_MODEL = "CD210"
|
||||
DEFAULT_BIG_MODEL = "Lebowski"
|
||||
|
||||
@@ -20,4 +20,4 @@ class TestDefaultModel(OpenpilotTestCase):
|
||||
with open(MODEL_HASH_PATH) as f:
|
||||
current_hash = f.read().strip()
|
||||
|
||||
assert combined_hash == current_hash, "Run sunnypilot/models/default_model.py to update the default model name and hash"
|
||||
assert combined_hash == current_hash, "Run openpilot/sunnypilot/models/default_model.py to update the default model name and hash"
|
||||
|
||||
Reference in New Issue
Block a user