Import the module "models/[model_name]_model.py". In the file, the class called DatasetNameModel() will be instantiated. It has to be a subclass of BaseModel, and it is case-insensitive.
(model_name)
| 23 | |
| 24 | |
| 25 | def find_model_using_name(model_name): |
| 26 | """Import the module "models/[model_name]_model.py". |
| 27 | |
| 28 | In the file, the class called DatasetNameModel() will |
| 29 | be instantiated. It has to be a subclass of BaseModel, |
| 30 | and it is case-insensitive. |
| 31 | """ |
| 32 | model_filename = "models." + model_name + "_model" |
| 33 | modellib = importlib.import_module(model_filename) |
| 34 | model = None |
| 35 | target_model_name = model_name.replace('_', '') + 'model' |
| 36 | for name, cls in modellib.__dict__.items(): |
| 37 | if name.lower() == target_model_name.lower() \ |
| 38 | and issubclass(cls, BaseModel): |
| 39 | model = cls |
| 40 | |
| 41 | if model is None: |
| 42 | print("In %s.py, there should be a subclass of BaseModel with class name that matches %s in lowercase." % (model_filename, target_model_name)) |
| 43 | exit(0) |
| 44 | |
| 45 | return model |
| 46 | |
| 47 | |
| 48 | def get_option_setter(model_name): |
no outgoing calls
no test coverage detected