MCPcopy Create free account
hub / github.com/NVlabs/SPADE / find_model_using_name

Function find_model_using_name

models/__init__.py:10–31  ·  view source on GitHub ↗
(model_name)

Source from the content-addressed store, hash-verified

8
9
10def 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
34def get_option_setter(model_name):

Callers 2

get_option_setterFunction · 0.85
create_modelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected