
    &Vf                     |    d dl Zd dlmZ d dlmZ d dlmZ d dlm	Z	  ed           G d de                      Z
dS )	    N)backend)keras_export)Callback)io_utilsz%keras.callbacks.LearningRateSchedulerc                   4     e Zd ZdZd fd	ZddZddZ xZS )	LearningRateSchedulera#  Learning rate scheduler.

    At the beginning of every epoch, this callback gets the updated learning
    rate value from `schedule` function provided at `__init__`, with the current
    epoch and current learning rate, and applies the updated learning rate on
    the optimizer.

    Args:
        schedule: A function that takes an epoch index (integer, indexed from 0)
            and current learning rate (float) as inputs and returns a new
            learning rate as output (float).
        verbose: Integer. 0: quiet, 1: log update messages.

    Example:

    >>> # This function keeps the initial learning rate for the first ten epochs
    >>> # and decreases it exponentially after that.
    >>> def scheduler(epoch, lr):
    ...     if epoch < 10:
    ...         return lr
    ...     else:
    ...         return lr * ops.exp(-0.1)
    >>>
    >>> model = keras.models.Sequential([keras.layers.Dense(10)])
    >>> model.compile(keras.optimizers.SGD(), loss='mse')
    >>> round(model.optimizer.learning_rate, 5)
    0.01

    >>> callback = keras.callbacks.LearningRateScheduler(scheduler)
    >>> history = model.fit(np.arange(100).reshape(5, 20), np.zeros(5),
    ...                     epochs=15, callbacks=[callback], verbose=0)
    >>> round(model.optimizer.learning_rate, 5)
    0.00607

    r   c                 d    t                                                       || _        || _        d S N)super__init__scheduleverbose)selfr   r   	__class__s      h/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/callbacks/learning_rate_scheduler.pyr   zLearningRateScheduler.__init__/   s+         Nc                 &   t          | j        j        d          st          d          	 t	          t          j        | j        j        j                            }|                     ||          }n%# t          $ r |                     |          }Y nw xY wt          |t          t          j        t          j        f          st          d|           || j        j        _        | j        dk    r t          j        d|dz    d| d           d S d S )	Nlearning_ratez0Optimizer must have a "learning_rate" attribute.z>The output of the `schedule` function should be a float. Got: r   z
Epoch    z1: LearningRateScheduler setting learning rate to .)hasattrmodel	optimizer
ValueErrorfloatr   convert_to_numpyr   r   	TypeError
isinstancenpfloat32float64r   r   	print_msg)r   epochlogsr   s       r   on_epoch_beginz$LearningRateScheduler.on_epoch_begin4   sG   tz+_== 	QOPPP	1!()=)KLL M !MM%??MM 	1 	1 	1 MM%00MMM	1 -%RZ)HII 	(%( (  
 .;
*<!,519 , ,(, , ,     s   AA2 2BBc                 t    |pi }t          t          j        | j        j        j                            |d<   d S )Nr   )r   r   r   r   r   r   )r   r#   r$   s      r   on_epoch_endz"LearningRateScheduler.on_epoch_endM   s;    zr %$TZ%9%GHH!
 !
_r   )r   r
   )__name__
__module____qualname____doc__r   r%   r'   __classcell__)r   s   @r   r   r   	   sp        " "H     
   2
 
 
 
 
 
 
 
r   r   )numpyr   	keras.srcr   keras.src.api_exportr   keras.src.callbacks.callbackr   keras.src.utilsr   r    r   r   <module>r3      s              - - - - - - 1 1 1 1 1 1 $ $ $ $ $ $ 566G
 G
 G
 G
 G
H G
 G
 76G
 G
 G
r   