MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / train_on_batch

Function train_on_batch

tensorflow/python/keras/engine/training_eager.py:281–319  ·  view source on GitHub ↗

Calculates the loss and gradient updates for one input batch. Arguments: model: Model whose loss has to be calculated. inputs: Input batch data. targets: Target batch data. sample_weights: Sample weight batch data. output_loss_metrics: List of metrics that are used t

(model,
                   inputs,
                   targets,
                   sample_weights=None,
                   output_loss_metrics=None)

Source from the content-addressed store, hash-verified

279
280
281def train_on_batch(model,
282 inputs,
283 targets,
284 sample_weights=None,
285 output_loss_metrics=None):
286 """Calculates the loss and gradient updates for one input batch.
287
288 Arguments:
289 model: Model whose loss has to be calculated.
290 inputs: Input batch data.
291 targets: Target batch data.
292 sample_weights: Sample weight batch data.
293 output_loss_metrics: List of metrics that are used to aggregated output
294 loss values.
295
296 Returns:
297 Dict with three items:
298 'total_loss': list with a single tensor for overall loss,
299 'output_losses': list of tensors for loss corresponding to each of the
300 model output. Could be a empty list when model has only one output.
301 'metrics': list of tensors for metric specified.
302 """
303 inputs = training_utils.cast_to_model_input_dtypes(inputs, model)
304 outs, total_loss, output_losses, masks = (
305 _process_single_batch(
306 model,
307 inputs,
308 targets,
309 sample_weights=sample_weights,
310 training=True,
311 output_loss_metrics=output_loss_metrics))
312 if not isinstance(outs, list):
313 outs = [outs]
314 metrics_results = _eager_metrics_fn(
315 model, outs, targets, sample_weights=sample_weights, masks=masks)
316 total_loss = nest.flatten(total_loss)
317 return {'total_loss': total_loss,
318 'output_losses': output_losses,
319 'metrics': metrics_results}
320
321
322def test_on_batch(model,

Callers

nothing calls this directly

Calls 3

_process_single_batchFunction · 0.85
_eager_metrics_fnFunction · 0.85
flattenMethod · 0.45

Tested by

no test coverage detected