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

Function load_model_from_config

predict.py:202–219  ·  view source on GitHub ↗
(config, ckpt, verbose=False)

Source from the content-addressed store, hash-verified

200
201
202def load_model_from_config(config, ckpt, verbose=False):
203 print(f"Loading model from {ckpt}")
204 pl_sd = torch.load(ckpt, map_location="cpu")
205 if "global_step" in pl_sd:
206 print(f"Global Step: {pl_sd['global_step']}")
207 sd = pl_sd["state_dict"]
208 model = instantiate_from_config(config.model)
209 m, u = model.load_state_dict(sd, strict=False)
210 if len(m) > 0 and verbose:
211 print("missing keys:")
212 print(m)
213 if len(u) > 0 and verbose:
214 print("unexpected keys:")
215 print(u)
216
217 model.cuda()
218 model.eval()
219 return model
220
221
222def read_image(im_path):

Callers 1

setupMethod · 0.70

Calls 2

instantiate_from_configFunction · 0.90
loadMethod · 0.80

Tested by

no test coverage detected