(model_name)
| 8 | |
| 9 | |
| 10 | def find_model_using_name(model_name): |
| 11 | # Given the option --model [modelname], |
| 12 | # the file "models/modelname_model.py" |
| 13 | # will be imported. |
| 14 | model_filename = "models." + model_name + "_model" |
| 15 | modellib = importlib.import_module(model_filename) |
| 16 | |
| 17 | # In the file, the class called ModelNameModel() will |
| 18 | # be instantiated. It has to be a subclass of torch.nn.Module, |
| 19 | # and it is case-insensitive. |
| 20 | model = None |
| 21 | target_model_name = model_name.replace('_', '') + 'model' |
| 22 | for name, cls in modellib.__dict__.items(): |
| 23 | if name.lower() == target_model_name.lower() \ |
| 24 | and issubclass(cls, torch.nn.Module): |
| 25 | model = cls |
| 26 | |
| 27 | if model is None: |
| 28 | print("In %s.py, there should be a subclass of torch.nn.Module with class name that matches %s in lowercase." % (model_filename, target_model_name)) |
| 29 | exit(0) |
| 30 | |
| 31 | return model |
| 32 | |
| 33 | |
| 34 | def get_option_setter(model_name): |
no outgoing calls
no test coverage detected