MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / create_model

Function create_model

timm/models/factory.py:25–86  ·  view source on GitHub ↗

Create a model Args: model_name (str): name of model to instantiate pretrained (bool): load pretrained ImageNet-1k weights if true checkpoint_path (str): path of checkpoint to load after model is initialized scriptable (bool): set layer config so that model is ji

(
        model_name,
        pretrained=False,
        checkpoint_path='',
        scriptable=None,
        exportable=None,
        no_jit=None,
        **kwargs)

Source from the content-addressed store, hash-verified

23
24
25def create_model(
26 model_name,
27 pretrained=False,
28 checkpoint_path='',
29 scriptable=None,
30 exportable=None,
31 no_jit=None,
32 **kwargs):
33 """Create a model
34
35 Args:
36 model_name (str): name of model to instantiate
37 pretrained (bool): load pretrained ImageNet-1k weights if true
38 checkpoint_path (str): path of checkpoint to load after model is initialized
39 scriptable (bool): set layer config so that model is jit scriptable (not working for all models yet)
40 exportable (bool): set layer config so that model is traceable / ONNX exportable (not fully impl/obeyed yet)
41 no_jit (bool): set layer config so that model doesn't utilize jit scripted layers (so far activations only)
42
43 Keyword Args:
44 drop_rate (float): dropout rate for training (default: 0.0)
45 global_pool (str): global pool type (default: 'avg')
46 **: other kwargs are model specific
47 """
48 source_name, model_name = split_model_name(model_name)
49
50 # Only EfficientNet and MobileNetV3 models have support for batchnorm params or drop_connect_rate passed as args
51 is_efficientnet = is_model_in_modules(model_name, ['efficientnet', 'mobilenetv3'])
52 if not is_efficientnet:
53 kwargs.pop('bn_tf', None)
54 kwargs.pop('bn_momentum', None)
55 kwargs.pop('bn_eps', None)
56
57 # handle backwards compat with drop_connect -> drop_path change
58 drop_connect_rate = kwargs.pop('drop_connect_rate', None)
59 if drop_connect_rate is not None and kwargs.get('drop_path_rate', None) is None:
60 print("WARNING: 'drop_connect' as an argument is deprecated, please use 'drop_path'."
61 " Setting drop_path to %f." % drop_connect_rate)
62 kwargs['drop_path_rate'] = drop_connect_rate
63
64 # Parameters that aren't supported by all models or are intended to only override model defaults if set
65 # should default to None in command line args/cfg. Remove them if they are present and not set so that
66 # non-supporting models don't break and default args remain in effect.
67 kwargs = {k: v for k, v in kwargs.items() if v is not None}
68
69 if source_name == 'hf_hub':
70 # For model names specified in the form `hf_hub:path/architecture_name#revision`,
71 # load model weights + default_cfg from Hugging Face hub.
72 hf_default_cfg, model_name = load_model_config_from_hf(model_name)
73 kwargs['external_default_cfg'] = hf_default_cfg # FIXME revamp default_cfg interface someday
74
75 if is_model(model_name):
76 create_fn = model_entrypoint(model_name)
77 else:
78 raise RuntimeError('Unknown model (%s)' % model_name)
79
80 with set_layer_config(scriptable=scriptable, exportable=exportable, no_jit=no_jit):
81 model = create_fn(pretrained=pretrained, **kwargs)
82

Callers

nothing calls this directly

Calls 8

split_model_nameFunction · 0.85
is_model_in_modulesFunction · 0.85
is_modelFunction · 0.85
model_entrypointFunction · 0.85
set_layer_configClass · 0.85
load_checkpointFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected