MCPcopy Create free account
hub / github.com/IceClear/StableSR / load_model_from_config

Function load_model_from_config

scripts/generate_vqgan_data.py:119–136  ·  view source on GitHub ↗
(config, ckpt, verbose=False)

Source from the content-addressed store, hash-verified

117
118
119def load_model_from_config(config, ckpt, verbose=False):
120 print(f"Loading model from {ckpt}")
121 pl_sd = torch.load(ckpt, map_location="cpu")
122 if "global_step" in pl_sd:
123 print(f"Global Step: {pl_sd['global_step']}")
124 sd = pl_sd["state_dict"]
125 model = instantiate_from_config(config.model)
126 m, u = model.load_state_dict(sd, strict=False)
127 if len(m) > 0 and verbose:
128 print("missing keys:")
129 print(m)
130 if len(u) > 0 and verbose:
131 print("unexpected keys:")
132 print(u)
133
134 model.cuda()
135 model.eval()
136 return model
137
138
139def load_img(path):

Callers 1

mainFunction · 0.70

Calls 2

instantiate_from_configFunction · 0.90
loadMethod · 0.80

Tested by

no test coverage detected