@@ -125,8 +125,7 @@ def get_model_class(cls, name: str) -> Type:
125125 if name .lower () == subclass .__model__ .lower ():
126126 return subclass
127127 return cls .raise_error (
128- f"There is no model with name { name } in list: "
129- f"{ ', ' .join ([subclass .__model__ for subclass in subclasses ])} " ,
128+ f"There is no model with name { name } in list: { ', ' .join ([subclass .__model__ for subclass in subclasses ])} " ,
130129 )
131130
132131 @classmethod
@@ -195,12 +194,30 @@ def create_model(
195194 cache_dir = cache_dir ,
196195 )
197196 if model_type is None :
198- model_type = inference_adapter .get_rt_info (
199- ["model_info" , "model_type" ],
200- ).astype (str )
197+ try :
198+ model_type = inference_adapter .get_rt_info (
199+ ["model_info" , "model_type" ],
200+ ).astype (str )
201+ except RuntimeError :
202+ model_type = cls .detect_model_type (inference_adapter )
201203 Model = cls .get_model_class (model_type )
202204 return Model (inference_adapter , configuration , preload )
203205
206+ @classmethod
207+ def detect_model_type (cls , inference_adapter ) -> str :
208+ """Detects model type on available information"""
209+ input_layers = inference_adapter .get_input_layers ()
210+ output_layers = inference_adapter .get_output_layers ()
211+
212+ # Check for Anomalib model pattern: 1 input and specific output layer names
213+ if len (input_layers ) == 1 and len (output_layers ) == 4 :
214+ expected_outputs = {"pred_score" , "pred_label" , "anomaly_map" , "pred_mask" }
215+ actual_outputs = set (output_layers .keys ())
216+ if expected_outputs == actual_outputs :
217+ return "AnomalyDetection"
218+
219+ return "uknown"
220+
204221 @classmethod
205222 def get_subclasses (cls ) -> list [Any ]:
206223 """Retrieves all the subclasses of the model class given."""
0 commit comments