Coverage for source/utils/callback_from_string_converter.py: 100%
7 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-30 15:13 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-30 15:13 +0000
1# utils/callback_from_string_converter.py
3from typing import Any, Type
4from tensorflow.keras.callbacks import Callback, ReduceLROnPlateau, EarlyStopping
6from .base_from_string_converter import BaseFromStringConverter
8class CallbackFromStringConverter(BaseFromStringConverter):
9 """
10 Converts string identifiers to Keras callback classes.
12 This class implements a specific string-to-object conversion for Keras callback
13 classes. It maps string names like 'reduce_rl_on_plateau' to their corresponding
14 callback implementations like ReduceLROnPlateau.
15 """
17 def __init__(self, **kwargs: dict[str, Any]) -> None:
18 """
19 Initializes the callback converter with options for callback configuration.
21 Parameters:
22 **kwargs (dict[str, Any]): Optional parameters that will be passed to
23 the constructor of the callback objects.
24 """
26 self._kwargs: dict[str, Any] = kwargs
27 self._value_map: dict[str, Type[Callback]] = {
28 'reduce_rl_on_plateau': ReduceLROnPlateau,
29 'early_stopping': EarlyStopping
30 }