kaylode / theseus

General template for most Pytorch projects
MIT License
34 stars 6 forks source link

Implement independent Callbacks class #19

Closed kaylode closed 2 years ago

kaylode commented 2 years ago

For example:

Source: tensorflow - keras

class CustomCallback(keras.callbacks.Callback):
    def on_train_begin(self, logs=None):
        keys = list(logs.keys())
        print("Starting training; got log keys: {}".format(keys))

    def on_train_end(self, logs=None):
        keys = list(logs.keys())
        print("Stop training; got log keys: {}".format(keys))

    def on_epoch_begin(self, epoch, logs=None):
        keys = list(logs.keys())
        print("Start epoch {} of training; got log keys: {}".format(epoch, keys))

    def on_epoch_end(self, epoch, logs=None):
        keys = list(logs.keys())
        print("End epoch {} of training; got log keys: {}".format(epoch, keys))
trainer = ClassificationTrainer(..., callbacks = List[Callbacks])
kaylode commented 2 years ago

https://github.com/keras-team/keras/blob/v2.8.0/keras/callbacks.py#L650-L653

kaylode commented 2 years ago

https://github.com/ultralytics/yolov5/blob/e6e36aac109794999f1dafab244b9ec4887a33d1/utils/callbacks.py#L7