
    1Vh                         d Z ddlZddlmZ  G d dej
                        Z e       Z G d dej
                        Z e       Z	y)zCTensorBoard encoder helper module.

Encoder depends on TensorFlow.
    N)op_evaluatorc                   .     e Zd ZdZ fdZd Zd Z xZS )_TensorFlowPngEncoderab  Encode an image to PNG.

    This function is thread-safe, and has high performance when run in
    parallel. See `encode_png_benchmark.py` for details.

    Arguments:
      image: A numpy array of shape `[height, width, channels]`, where
        `channels` is 1, 3, or 4, and of dtype uint8.

    Returns:
      A bytestring with PNG-encoded data.
    c                 >    t         |           d | _        d | _        y N)super__init___image_placeholder
_encode_opself	__class__s    H/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/util/encoder.pyr	   z_TensorFlowPngEncoder.__init__(   s    "&    c                     dd l mc m} |j                  |j                  d      | _        |j                  j                  | j
                        | _        y )Nr   image_to_encodedtypename)	tensorflow.compat.v1compatv1placeholderuint8r
   image
encode_pngr   r   tfs     r   initialize_graphz&_TensorFlowPngEncoder.initialize_graph-   sF    ))"$..((!2 #1 #
 ((--d.E.EFr   c                    t        |t        j                        st        d|z        |j                  t        j
                  k7  rt        d|j                  z        | j                  j                  | j                  |i      S )Nz!'image' must be a numpy array: %rz&'image' dtype must be uint8, but is %r	feed_dict)	
isinstancenpndarray
ValueErrorr   r   r   evalr
   )r   r   s     r   runz_TensorFlowPngEncoder.run6   so    %,@5HII;;"(("85;;F  ##t/F/F.N#OOr   __name__
__module____qualname____doc__r	   r   r(   __classcell__r   s   @r   r   r      s    
GPr   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )_TensorFlowWavEncodera!  Encode an audio clip to WAV.

    This function is thread-safe and exhibits good parallel performance.

    Arguments:
      audio: A numpy array of shape `[samples, channels]`.
      samples_per_second: A positive `int`, in Hz.

    Returns:
      A bytestring with WAV-encoded data.
    c                 L    t         |           d | _        d | _        d | _        y r   )r   r	   _audio_placeholder_samples_per_second_placeholderr   r   s    r   r	   z_TensorFlowWavEncoder.__init__P   s%    "&/3,r   c                 
   dd l mc m} |j                  |j                  d      | _        |j                  |j                  d      | _        |j                  j                  | j
                  | j                        | _
        y )Nr   r   r   samples_per_second)sample_rate)r   r   r   r   float32r3   int32r4   audio
encode_wavr   r   s     r   r   z&_TensorFlowWavEncoder.initialize_graphV   sy    ))"$..**#4 #1 #
 02~~((!5 0> 0
, ((--##<< . 
r   c                     t        |t        j                        st        d|z        t        |t              st        d|z        | j
                  || j                  |i}| j                  j                  |      S )Nz!'audio' must be a numpy array: %rz''samples_per_second' must be an int: %rr!   )	r#   r$   r%   r&   intr3   r4   r   r'   )r   r:   r6   r"   s       r   r(   z_TensorFlowWavEncoder.rune   s~     %,@5HII,c29<NN  ##U002D
	 ##i#88r   r)   r/   s   @r   r1   r1   C   s    

9r   r1   )
r-   numpyr$   tensorboard.utilr   PersistentOpEvaluatorr   r   r1   r;    r   r   <module>rB      sN     )#PL>> #PL #$
/9L>> /9d #$
r   