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

1# utils/callback_from_string_converter.py 

2 

3from typing import Any, Type 

4from tensorflow.keras.callbacks import Callback, ReduceLROnPlateau, EarlyStopping 

5 

6from .base_from_string_converter import BaseFromStringConverter 

7 

8class CallbackFromStringConverter(BaseFromStringConverter): 

9 """ 

10 Converts string identifiers to Keras callback classes. 

11 

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 """ 

16 

17 def __init__(self, **kwargs: dict[str, Any]) -> None: 

18 """ 

19 Initializes the callback converter with options for callback configuration. 

20 

21 Parameters: 

22 **kwargs (dict[str, Any]): Optional parameters that will be passed to 

23 the constructor of the callback objects. 

24 """ 

25 

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 }