
    Wh                         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	dS )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                 d    t                                                       d | _        d | _        d S N)super__init___image_placeholder
_encode_opself	__class__s    ^/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/tensorboard/util/encoder.pyr	   z_TensorFlowPngEncoder.__init__(   s,    "&    c                     dd l mc m} |                    |j        d          | _        |j                            | j                  | _        d S )Nr   image_to_encodedtypename)	tensorflow.compat.v1compatv1placeholderuint8r
   image
encode_pngr   r   tfs     r   initialize_graphz&_TensorFlowPngEncoder.initialize_graph-   s`    )))))))))"$..(!2 #1 #
 #
 (--d.EFFr   c                     t          |t          j                  st          d|z            |j        t          j        k    rt          d|j        z            | 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   sy    %,, 	J@5HIII;"(""85;F   ##t/F.N#OOOr   __name__
__module____qualname____doc__r	   r   r(   __classcell__r   s   @r   r   r      sj             
G G GP P P P P P 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                 r    t                                                       d | _        d | _        d | _        d S r   )r   r	   _audio_placeholder_samples_per_second_placeholderr   r   s    r   r	   z_TensorFlowWavEncoder.__init__P   s4    "&/3,r   c                     dd l mc m} |                    |j        d          | _        |                    |j        d          | _        |j        	                    | j        | j                  | _
        d S )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   s    )))))))))"$..*#4 #1 #
 #
 02~~(!5 0> 0
 0
, (--#< . 
 
r   c                     t          |t          j                  st          d|z            t          |t                    st          d|z            | j        || j        |i}| 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     %,, 	J@5HIII,c22 	9<NN   #U02D
	 ##i#888r   r)   r/   s   @r   r1   r1   C   s`        
 
    
 
 
9 9 9 9 9 9 9r   r1   )
r-   numpyr$   tensorboard.utilr   PersistentOpEvaluatorr   r   r1   r;    r   r   <module>rB      s         ) ) ) ) ) )#P #P #P #P #PL> #P #P #PL #"$$
/9 /9 /9 /9 /9L> /9 /9 /9d #"$$


r   