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

Function batch_norm_step

tensorflow/python/keras/custom_training_loop_test.py:92–112  ·  view source on GitHub ↗
(defun)

Source from the content-addressed store, hash-verified

90
91
92def batch_norm_step(defun):
93 optimizer = keras.optimizer_v2.adadelta.Adadelta()
94 model = testing_utils.get_model_from_layers([
95 keras.layers.BatchNormalization(momentum=0.9),
96 keras.layers.Dense(1, kernel_initializer='zeros', activation='softmax')
97 ],
98 input_shape=(10,))
99
100 def train_step(x, y):
101 with backprop.GradientTape() as tape:
102 y_pred = model(x, training=True)
103 loss = keras.losses.binary_crossentropy(y, y_pred)
104 gradients = tape.gradient(loss, model.trainable_weights)
105 optimizer.apply_gradients(zip(gradients, model.trainable_weights))
106 return loss, model(x, training=False)
107
108 if defun:
109 train_step = def_function.function(train_step)
110
111 x, y = array_ops.ones((10, 10)), array_ops.ones((10, 1))
112 return train_step(x, y)
113
114
115def add_metric_step(defun):

Callers

nothing calls this directly

Calls 3

onesMethod · 0.80
train_stepFunction · 0.70
functionMethod · 0.45

Tested by

no test coverage detected