Reputation: 1
This is my first time asking a question so go easy on me. I am trying to write a custom layer in python tensorflow/keras and in the layer I want to access the number of the current epoch of the model. I have extensively searched the tensorflow documentation to find something that could give me that. The best I could find is tensorflow.keras.backend.learning_phase()
which return whether it is the learning phase or not. Please help!
Upvotes: 0
Views: 410
Reputation:
You need to create a callback, check keras documentation
from tensorflow.keras.callbacks import Callback
class CustomEpoch(Callback):
def check_condition(self, epoch):
# TODO check if the condition is met
pass
def on_epoch_begin(self, epoch, logs=None):
if not self.check_condition(epoch):
return
# TODO do stuff
And make sure this is called somewhere:
model.fit(callbacks=[CustomEpoch()])
Upvotes: 1