
    1Vh                         d Z ddlZddlmZ ddlmZ ddlmZ  G d dej                  j                  j                        Z	y)ztKeras integration for TensorBoard hparams.

Use `tensorboard.plugins.hparams.api` to access this module's contents.
    N)api_pb2)summary)
summary_v2c                   .    e Zd ZdZddZd ZddZddZy)CallbackzwCallback for logging hyperparameters to TensorBoard.

    NOTE: This callback only works in TensorFlow eager mode.
    Nc                 B   t        |      | _        || _        t        j                  | j                  | j                         |t        d      t        |t              r9t        j                  j                  j                  j                  |      | _        y|| _        y)a'  Create a callback for logging hyperparameters to TensorBoard.

        As with the standard `tf.keras.callbacks.TensorBoard` class, each
        callback object is valid for only one call to `model.fit`.

        Args:
          writer: The `SummaryWriter` object to which hparams should be
            written, or a logdir (as a `str`) to be passed to
            `tf.summary.create_file_writer` to create such a writer.
          hparams: A `dict` mapping hyperparameters to the values used in
            this session. Keys should be the names of `HParam` objects used
            in an experiment, or the `HParam` objects themselves. Values
            should be Python `bool`, `int`, `float`, or `string` values,
            depending on the type of the hyperparameter.
          trial_id: An optional `str` ID for the set of hyperparameter
            values used in this trial. Defaults to a hash of the
            hyperparameters.

        Raises:
          ValueError: If two entries in `hparams` share the same
            hyperparameter name.
        trial_idNz3writer must be a `SummaryWriter` or `str`, not None)dict_hparams	_trial_idr   
hparams_pb	TypeError
isinstancestrtfcompatv2r   create_file_writer_writer)selfwriterhparamsr
   s       R/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/plugins/hparams/_keras.py__init__zCallback.__init__"   sv    4 W!dmmdnnE>E  $99<<//BB6JDL!DL    c                     | j                   t        d      t        j                         st        d      | j                   S )Nz@hparams Keras callback cannot be reused across training sessionsz>hparams Keras callback only supported in TensorFlow eager mode)r   RuntimeErrorr   executing_eagerly)r   s    r   _get_writerzCallback._get_writerH   sF    <<R  ##%P  ||r   c                     ~| j                         j                         5  t        j                  | j                  | j
                         d d d        y # 1 sw Y   y xY w)Nr	   )r    
as_defaultr   r   r   r   )r   logss     r   on_train_beginzCallback.on_train_beginS   sK    **, 	Gt}}t~~F	G 	G 	Gs   ,AAc                 l   ~| j                         j                         5  t        j                  t        j
                        }|j                         }t        j                  j                  j                  j                  j                  |d       d d d        d | _        y # 1 sw Y   d | _        y xY w)Nr   )step)r    r"   r   session_end_pbr   STATUS_SUCCESSSerializeToStringr   r   r   experimentalwrite_raw_pbr   )r   r#   pbraw_pbs       r   on_train_endzCallback.on_train_endX   s    **, 	K''(>(>?B))+FIILL  --::6:J	K 		K s   A3B##B3)N)__name__
__module____qualname____doc__r   r    r$   r.    r   r   r   r      s    
$"L	G
r   r   )
r2   
tensorflowr   tensorboard.plugins.hparamsr   r   r   keras	callbacksr   r3   r   r   <module>r8      s6     / / 2Brxx!!** Br   