I decided to switch from keras to tf.keras (as recommended here). Therefore I installed tf.__version__=2.0.0
and tf.keras.__version__=2.2.4-tf
. In an older version of my code (using some older Tensorflow version tf.__version__=1.x.x
) I used a callback to compute custom metrics on the entire validation data at the end of each epoch. The idea to do so was taken from here. However, it seems as if the "validation_data" attribute is deprecated so that the following code is not working any longer.
class ValMetrics(Callback):
def on_train_begin(self, logs={}):
self.val_all_mse = []
def on_epoch_end(self, epoch, logs):
val_predict = np.asarray(self.model.predict(self.validation_data[0]))
val_targ = self.validation_data[1]
val_epoch_mse = mse_score(val_targ, val_predict)
self.val_epoch_mse.append(val_epoch_mse)
# Add custom metrics to the logs, so that we can use them with
# EarlyStop and csvLogger callbacks
logs["val_epoch_mse"] = val_epoch_mse
print(f"\nEpoch: {epoch + 1}")
print("-----------------")
print("val_mse: {:+.6f}".format(val_epoch_mse))
return
My current workaround is the following. I simply gave validation_data as an argument to the ValMetrics
class :
class ValMetrics(Callback):
def __init__(self, validation_data):
super(Callback, self).__init__()
self.X_val, self.y_val = validation_data
Still I have some questions: Is the "validation_data" attribute really deprecated or can it be found elsewhere? Is there a better way to access the validation data at the end of each epoch than with the above workaround?
Thanks a lot!