Ali Abdul Hussain
Ali Abdul Hussain

Reputation: 1

Number of the current epoch in custom layer tensorflow python

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

Answers (1)

user12690225
user12690225

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

Related Questions