@@ -430,9 +430,9 @@ def deploy(self, model_type: str, model_path: str) -> None:
430430
431431 if not any (supported_model in model_type for supported_model in supported_models ):
432432 raise (ValueError (f"Model type { model_type } not supported. Supported models are" f" { supported_models } " ))
433-
433+
434434 if "yolonas" in model_type :
435- self .deploy_yolonas (model_path )
435+ self .deploy_yolonas (model_type , model_path )
436436 return
437437
438438 if "yolov8" in model_type :
@@ -521,15 +521,15 @@ def deploy(self, model_type: str, model_path: str) -> None:
521521
522522 torch .save (model ["model" ].state_dict (), os .path .join (model_path , "state_dict.pt" ))
523523
524- lista_files = [
524+ list_files = [
525525 "results.csv" ,
526526 "results.png" ,
527527 "model_artifacts.json" ,
528528 "state_dict.pt" ,
529529 ]
530530
531531 with zipfile .ZipFile (os .path .join (model_path , "roboflow_deploy.zip" ), "w" ) as zipMe :
532- for file in lista_files :
532+ for file in list_files :
533533 if os .path .exists (os .path .join (model_path , file )):
534534 zipMe .write (
535535 os .path .join (model_path , file ),
@@ -554,34 +554,47 @@ def deploy_yolonas(self, model_type: str, model_path: str) -> None:
554554 model = torch .load (os .path .join (model_path , "weights/best.pt" ), map_location = "cpu" )
555555 class_names = model ["processing_params" ]["class_names" ]
556556
557+ opt_path = os .path .join (model_path , "opt.yaml" )
558+ if not os .path .exists (opt_path ):
559+ raise RuntimeError (
560+ f"You must create an opt.yaml file at { os .path .join (model_path , '' )} of the format:\n "
561+ f"imgsz: <resolution of model>\n "
562+ f"batch_size: <batch size of inference model>\n "
563+ f"architecture: <one of [yolo_nas_s, yolo_nas_m, yolo_nas_l]."
564+ f"s, m, l refer to small, medium, large architecture sizes, respectively>\n "
565+ )
557566 with open (os .path .join (model_path , "opt.yaml" ), "r" ) as stream :
558567 opts = yaml .safe_load (stream )
568+ required_keys = ["imgsz" , "batch_size" , "architecture" ]
569+ for key in required_keys :
570+ if key not in opts :
571+ raise RuntimeError (f"{ opt_path } lacks required key { key } . Required keys: { required_keys } " )
559572
560573 model_artifacts = {
561574 "names" : class_names ,
562575 "nc" : len (class_names ),
563576 "args" : {
564577 "imgsz" : opts ["imgsz" ] if "imgsz" in opts else opts ["img_size" ],
565578 "batch" : opts ["batch_size" ],
579+ "architecture" : opts ["architecture" ],
566580 },
567581 "model_type" : model_type ,
568582 }
569583
570584 with open (os .path .join (model_path , "model_artifacts.json" ), "w" ) as fp :
571585 json .dump (model_artifacts , fp )
572586
573- shutil .copy (os .path .join (model_path , "weights/best.pt" ),
574- os .path .join (model_path , "state_dict.pt" ))
587+ shutil .copy (os .path .join (model_path , "weights/best.pt" ), os .path .join (model_path , "state_dict.pt" ))
575588
576- lista_files = [
589+ list_files = [
577590 "results.json" ,
578591 "results.png" ,
579592 "model_artifacts.json" ,
580593 "state_dict.pt" ,
581594 ]
582595
583596 with zipfile .ZipFile (os .path .join (model_path , "roboflow_deploy.zip" ), "w" ) as zipMe :
584- for file in lista_files :
597+ for file in list_files :
585598 if os .path .exists (os .path .join (model_path , file )):
586599 zipMe .write (
587600 os .path .join (model_path , file ),
@@ -591,7 +604,7 @@ def deploy_yolonas(self, model_type: str, model_path: str) -> None:
591604 else :
592605 if file in ["model_artifacts.json" , "best.pt" ]:
593606 raise (ValueError (f"File { file } not found. Please make sure to provide a" " valid model path." ))
594-
607+
595608 self .upload_zip (model_type , model_path )
596609
597610 def upload_zip (self , model_type : str , model_path : str ):
0 commit comments