1616from otx .api .entities .model_template import ModelTemplate , parse_model_template
1717from otx .cli .registry import Registry as OTXRegistry
1818from otx .cli .utils .config import configure_dataset , override_parameters
19+ from otx .cli .utils .errors import (
20+ CliException ,
21+ ConfigValueError ,
22+ FileNotExistError ,
23+ NotSupportedError ,
24+ )
1925from otx .cli .utils .importing import get_otx_root_path
2026from otx .cli .utils .parser import gen_param_help , gen_params_dict_from_args
2127from otx .core .data .manager .dataset_manager import DatasetManager
@@ -112,7 +118,7 @@ def data_config_file_path(self) -> Path:
112118 if "data" in self .args and self .args .data :
113119 if Path (self .args .data ).exists ():
114120 return Path (self .args .data )
115- raise FileNotFoundError (f"Not found: { self .args .data } " )
121+ raise FileNotExistError (f"Not found: { self .args .data } " )
116122 return self .workspace_root / "data.yaml"
117123
118124 def check_workspace (self ) -> bool :
@@ -140,6 +146,8 @@ def configure_template(self, model: str = None) -> None:
140146 else :
141147 task_type = self .task_type
142148 if not task_type and not model :
149+ if not hasattr (self .args , "train_data_roots" ):
150+ raise ConfigValueError ("Can't find the argument 'train_data_roots'" )
143151 task_type = self .auto_task_detection (self .args .train_data_roots )
144152 self .template = self ._get_template (task_type , model = model )
145153 self .task_type = self .template .task_type
@@ -149,7 +157,7 @@ def configure_template(self, model: str = None) -> None:
149157 def _check_rebuild (self ):
150158 """Checking for Rebuild status."""
151159 if self .args .task and str (self .template .task_type ) != self .args .task .upper ():
152- raise NotImplementedError ("Task Update is not yet supported." )
160+ raise NotSupportedError ("Task Update is not yet supported." )
153161 result = False
154162 if self .args .model and self .template .name != self .args .model .upper ():
155163 print (f"[*] Rebuild model: { self .template .name } -> { self .args .model .upper ()} " )
@@ -189,7 +197,7 @@ def _get_train_type(self, ignore_args: bool = False) -> str:
189197 if hasattr (self .args , "train_type" ) and self .mode in ("build" , "train" ) and self .args .train_type :
190198 self .train_type = self .args .train_type .upper ()
191199 if self .train_type not in TASK_TYPE_TO_SUB_DIR_NAME :
192- raise ValueError (f"{ self .train_type } is not currently supported by otx." )
200+ raise NotSupportedError (f"{ self .train_type } is not currently supported by otx." )
193201 if self .train_type in TASK_TYPE_TO_SUB_DIR_NAME :
194202 return self .train_type
195203
@@ -202,7 +210,7 @@ def _get_train_type(self, ignore_args: bool = False) -> str:
202210 def auto_task_detection (self , data_roots : str ) -> str :
203211 """Detect task type automatically."""
204212 if not data_roots :
205- raise ValueError ("Workspace must already exist or one of {task or model or train-data-roots} must exist." )
213+ raise CliException ("Workspace must already exist or one of {task or model or train-data-roots} must exist." )
206214 self .data_format = self .dataset_manager .get_data_format (data_roots )
207215 return self ._get_task_type_from_data_format (self .data_format )
208216
@@ -225,7 +233,7 @@ def _get_task_type_from_data_format(self, data_format: str) -> str:
225233 self .task_type = task_key
226234 print (f"[*] Detected task type: { self .task_type } " )
227235 return task_key
228- raise ValueError (f"Can't find proper task. we are not support { data_format } format, yet." )
236+ raise ConfigValueError (f"Can't find proper task. we are not support { data_format } format, yet." )
229237
230238 def auto_split_data (self , data_roots : str , task : str ):
231239 """Automatically Split train data --> train/val dataset."""
@@ -372,7 +380,7 @@ def _get_template(self, task_type: str, model: Optional[str] = None) -> ModelTem
372380 if model :
373381 template_lst = [temp for temp in otx_registry .templates if temp .name .lower () == model .lower ()]
374382 if not template_lst :
375- raise ValueError (
383+ raise NotSupportedError (
376384 f"[*] { model } is not a type supported by OTX { task_type } ."
377385 f"\n [*] Please refer to 'otx find --template --task { task_type } '"
378386 )
@@ -426,7 +434,7 @@ def build_workspace(self, new_workspace_path: Optional[str] = None) -> None:
426434
427435 model_dir = template_dir .absolute () / train_type_rel_path
428436 if not model_dir .exists ():
429- raise ValueError (f"[*] { self .train_type } is not a type supported by OTX { self .task_type } " )
437+ raise NotSupportedError (f"[*] { self .train_type } is not a type supported by OTX { self .task_type } " )
430438 train_type_dir = self .workspace_root / train_type_rel_path
431439 train_type_dir .mkdir (exist_ok = True )
432440
@@ -479,7 +487,7 @@ def _copy_config_files(self, target_dir: Path, file_name: str, dest_dir: Path) -
479487 config = MPAConfig .fromfile (str (target_dir / file_name ))
480488 config .dump (str (dest_dir / file_name ))
481489 except Exception as exc :
482- raise ImportError (f"{ self .task_type } requires mmcv-full to be installed." ) from exc
490+ raise CliException (f"{ self .task_type } requires mmcv-full to be installed." ) from exc
483491 elif file_name .endswith ((".yml" , ".yaml" )):
484492 config = OmegaConf .load (str (target_dir / file_name ))
485493 (dest_dir / file_name ).write_text (OmegaConf .to_yaml (config ))
0 commit comments