import keras.backend as K // pylint: disable=import-error
if not loss:
num_outputs = len(model.outputs)
logger.error("You are trying to construct a training/validation"
"/testing model, but you haven\"t specified any loss "
"functions. Your model has %d outputs: %s. You need to "
"specify %d loss functions, one for each output.",
num_outputs, ", ".join(model.outputs), num_outputs)
raise ValueError("No loss functions were specified, but are "
"required for training, testing, and validation.")
if isinstance(loss, Loss):
loss = [loss]
output_only = set(model.outputs) - set(loss)
if output_only:
logger.debug("These layers will be output-only layers, without "
"loss functions attached: %s", ", ".join(output_only))
if isinstance(loss, (list, tuple)):
loss = {x.get("target") : x for x in loss}
if not isinstance(loss, (dict, OrderedDict)):
raise ValueError("Loss functions given to "compile" should be "