
    2Vh
                         d dl Z d dlZd dlZd dlmZ d dlmZ 	 d dlZ ed       G d de             Z
y# e	$ r dZY  w xY w)    N)keras_export)Callbackzkeras.callbacks.RemoteMonitorc                   6     e Zd ZdZ	 	 	 	 	 d fd	ZddZ xZS )RemoteMonitora  Callback used to stream events to a server.

    Requires the `requests` library.
    Events are sent to `root + '/publish/epoch/end/'` by default. Calls are
    HTTP POST, with a `data` argument which is a
    JSON-encoded dictionary of event data.
    If `send_as_json=True`, the content type of the request will be
    `"application/json"`.
    Otherwise the serialized JSON will be sent within a form.

    Args:
        root: String; root url of the target server.
        path: String; path relative to `root` to which the events will be sent.
        field: String; JSON field under which the data will be stored.
            The field is used only if the payload is sent within a form
            (i.e. when `send_as_json=False`).
        headers: Dictionary; optional custom HTTP headers.
        send_as_json: Boolean; whether the request should be
            sent as `"application/json"`.
    c                 h    t         |           || _        || _        || _        || _        || _        y N)super__init__rootpathfieldheaderssend_as_json)selfr   r   r   r   r   	__class__s         R/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/callbacks/remote_monitor.pyr
   zRemoteMonitor.__init__&   s4     			
(    c                    t         t        d      |xs i }i }||d<   |j                         D ]H  \  }}t        |t        j
                  t        j                  f      r|j                         ||<   D|||<   J 	 | j                  r:t        j                  | j                  | j                  z   || j                         y t        j                  | j                  | j                  z   | j                  t        j                  |      i| j                         y # t         j                   j"                  $ r' t%        j&                  d| j                   d       Y y w xY w)Nz.RemoteMonitor requires the `requests` library.epoch)jsonr   )r   z-Could not reach RemoteMonitor root server at    )
stacklevel)requestsImportErroritems
isinstancenpndarraygenericitemr   postr   r   r   r   r   dumps
exceptionsRequestExceptionwarningswarn)r   r   logssendkvs         r   on_epoch_endzRemoteMonitor.on_epoch_end6   s   NOOzrWJJL 	DAq !bjj"**56&&(QQ		  II		)dll II		)ZZD!12 LL
 ""33 	MM?		{K	s   ;AD AD AEE)zhttp://localhost:9000z/publish/epoch/end/dataNFr   )__name__
__module____qualname____doc__r
   r+   __classcell__)r   s   @r   r   r      s#    . %") r   r   )r   r%   numpyr   keras.src.api_exportr   keras.src.callbacks.callbackr   r   r   r    r   r   <module>r6      sV       - 1
 -.CH C /C  Hs   5 ??