if model_config is None:
raise ValueError("No model found in config file.")
model_config = json.loads(model_config.decode("utf-8"))
model = model_from_config(model_config, custom_objects=custom_objects)
// set weights
topology.load_weights_from_hdf5_group(f["model_weights"], model.layers)
// Early return if compilation is not required.
if not compile:
f.close()
return model
// instantiate optimizer
training_config = f.attrs.get("training_config")
if training_config is None:
warnings.warn("No training configuration found in save file: "
"the model was *not* compiled. Compile it manually.")
f.close()
return model
training_config = json.loads(training_config.decode("utf-8"))
optimizer_config = training_config["optimizer_config"]
optimizer = optimizers.deserialize(optimizer_config,
custom_objects=custom_objects)
// Recover loss functions and metrics.
loss = convert_custom_objects(training_config["loss"])
metrics = convert_custom_objects(training_config["metrics"])
sample_weight_mode = training_config["sample_weight_mode"]
loss_weights = training_config["loss_weights"]
// Compile model.
model.compile(optimizer=optimizer,
loss=loss,
metrics=metrics,
loss_weights=loss_weights,
sample_weight_mode=sample_weight_mode)
// Set optimizer weights.
if "optimizer_weights" in f:
// Build train function (to get weight updates).