Saving layer weights at each epoch during training into a numpy type/array? Converting TensorFlow Variable to numpy array? Saving layer weights at each epoch during training into a numpy type/array? Converting TensorFlow Variable to numpy array? python-3.x python-3.x

Saving layer weights at each epoch during training into a numpy type/array? Converting TensorFlow Variable to numpy array?


I have found that I need to use the method keras.model.layer.get_weights() to get the weights as numpy arrays.

For instance my callback would change to something like

def on_epoch_end(self, epoch, logs={}):    logs = logs or {}    self.epoch.append(epoch)    for k, v in logs.items():        self.history.setdefault(k, []).append(v)    modelWeights = []    for layer in model.layers:        layerWeights = []        for weight in layer.get_weights():            layerWeights.append(weight)        modelWeights.append(layerWeights)    self.weights.append(modelWeights)