
    ajE                     X   d dl Z d dlZd dlZd dlmZ d dlZd dlZd dlm	Z	 d dl
mZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d
dlmZ d
dlmZmZ g dZ ej        e          Z de!de"fdZ#de"de!fdZ$dej%        de&e"         fdZ'dej%        de&e!         fdZ(dej%        de&e         fdZ)i ej*        dde'fej+        dde'fej,        dde'fej-        dde)fej!        dde)fej.        dde)fej/        dde)fej0        dde)fej1        d de)fej2        d de)fej3        d!de)fej4        d!de)fej"        d"de)fej5        d"de)fej6        d"de)fej7        d#d$e)fej8        d%d&e(fej9        d%d&e(fej:        d'd&e(fej;        d'd&e(fej<        d(d)e)fej=        d*d+e(fej>        d*d+e(fej1        d d,e)fej?        d d,e)fej@        d d,e)fi	ZAde"fd-ZB	 	 	 dLd0ZCdMd1ZDdNd3ZEd4 ZFd5 ZGdOd6ZHdOd7ZIdPd9ZJ	 dQd;ZKdOd<ZLdRd=ZMdSd?ZNd@ ZOdTdBZPdC ZQdD ZR	 dUdFZSdUdGZTdVdHZUdI ZVdJ ZW	 dVdKZXdS )W    N)Any)
struct_pb2)HistogramProtoSummarySummaryMetadata)TensorProto)TensorShapeProto)
layout_pb2)PrCurvePluginData)TextPluginData   )make_np)_prepare_videoconvert_to_HWC)half_to_intint_to_halfhparamsscalarhistogram_raw	histogrammake_histogramimageimage_boxes
draw_boxes
make_imagevideo
make_videoaudiocustom_scalarstexttensor_protopr_curve_rawpr_curvecompute_curvemeshfreturnc                 b    t          j        d|           }t          j        d|          d         S )aA  Casts a half-precision float value into an integer.

    Converts a half precision floating point value, such as `torch.half` or
    `torch.bfloat16`, into an integer value which can be written into the
    half_val field of a TensorProto for storage.

    To undo the effects of this conversion, use int_to_half().

    r&   ir   structpackunpack)r&   bufs     d/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/torch/utils/tensorboard/summary.pyr   r   6   s,     +c1

C=c""1%%    r)   c                 b    t          j        d|           }t          j        d|          d         S )zCasts an integer value to a half-precision float.

    Converts an integer value obtained from half_to_int back into a floating
    point value.

    r)   r&   r   r*   )r)   r.   s     r/   r   r   C   s,     +c1

C=c""1%%r0   tc                 b    d |                                                                  D             S )Nc                 ,    g | ]}t          |          S  )r   .0xs     r/   
<listcomp>z'_tensor_to_half_val.<locals>.<listcomp>N   s    999qKNN999r0   flattentolistr2   s    r/   _tensor_to_half_valr>   M   s*    99AIIKK$6$6$8$89999r0   c                 r    t          j        |                                                                           S N)torchview_as_realr;   r<   r=   s    r/   _tensor_to_complex_valrC   P   s+    a  ((**11333r0   c                 N    |                                                                  S r@   r:   r=   s    r/   _tensor_to_listrE   S   s    99;;r0   DT_HALFhalf_valDT_BFLOAT16DT_FLOAT	float_val	DT_DOUBLE
double_valDT_INT8int_valDT_UINT8DT_INT16DT_INT32DT_INT64	int64_valDT_COMPLEX32scomplex_valDT_COMPLEX64DT_BOOLbool_valDT_COMPLEX128dcomplex_val
uint32_valc                     t          | t          j                  s|                                 n| }|j        t          j        k    rdndS )Nr      )
isinstancenpndarraynumpydtypeuint8)tensor	converteds     r/   _calc_scale_factorrf   u   s<    &0&D&DP&I28++114r0   black   c	                    ddl m}	m}
 |
                                }|	                    |           }||||f\  }}}}|                    ||f||f||f||f||fg||           |r|}|                    |          \  }}}}||z
  ||z
  }}t          j        d|z            }|	                    |||z
  d|z  z
  f||z   |fg|           |
                    ||z   ||z
  |z
  f|||           | S )Nr   )	ImageDraw	ImageFont)widthfillg?rh   )rm   )rm   font)PILrj   rk   load_defaultDrawlinegetbboxr_   ceil	rectangler    )r   xminyminxmaxymaxdisplay_strcolor
color_text	thicknessrj   rk   rn   drawleftrighttopbottomtext_bottom_left_top_right_bottom
text_widthtext_heightmargins                            r/   _draw_single_boxr   z   sq    )(((((((!!##D>>%  D"&dD!9T5#vII
tVnufos|dC[Q    
  
'+||K'@'@$tVW"(5.'D.K
+,,{[01v:=>
"K0  	 	
 	
 	
 			F]K+5>?	 	 	
 	
 	
 Lr0   c           	      	    ddl }ddlm}m}m}mmm} ddlm	}m
}	m}
m}m} ddlm}m}m} t%           t&                    s)t(                              d           t-          d          t%          |t&                    s)t(                              d           t-          d          |pi }t%          |t&                    st-          d          |                                D ]P\  } vs1t%          |t0                    rt3           fd	|D                       st-          d
 d d          Qg } |            }                                 D ](\  }|	t%          |t4          t6          f          rs||j                 _        |v r&t=          j        d |         D                       }nd}|                      ||!                    d          |                     t%          |tD                    rt||j                 _#        |v r&t=          j        d |         D                       }nd}|                      ||!                    d          |                     !t%          |tH                    rt||j                 _%        |v r&t=          j        d |         D                       }nd}|                      ||!                    d          |                     t%          ||j&                  r\tO          |          d         }||j                 _        |                      ||!                    d                               tQ          d           |||	          }tS          tS          j*        |
|+                                                    }tY          tY          j!        ||          g          }fd|D             } |||          } |||	          }tS          tS          j*        |
|+                                                    }tY          tY          j!        ||          g          } ||!                    d                     } |||	!          }tS          tS          j*        |
|+                                                    }tY          tY          j!        ||          g          }|||fS )"a2  Output three `Summary` protocol buffers needed by hparams plugin.

    `Experiment` keeps the metadata of an experiment, such as the name of the
      hyperparameters and the name of the metrics.
    `SessionStartInfo` keeps key-value pairs of the hyperparameters
    `SessionEndInfo` describes status of the experiment e.g. STATUS_SUCCESS

    Args:
      hparam_dict: A dictionary that contains names of the hyperparameters
        and their values.
      metric_dict: A dictionary that contains names of the metrics
        and their values.
      hparam_domain_discrete: (Optional[Dict[str, List[Any]]]) A dictionary that
        contains names of the hyperparameters and all discrete values they can hold

    Returns:
      The `Summary` protobufs for Experiment, SessionStartInfo and
        SessionEndInfo
    r   N)DataType
Experiment
HParamInfo
MetricInfo
MetricNameStatus)EXPERIMENT_TAGPLUGIN_DATA_VERSIONPLUGIN_NAMESESSION_END_INFO_TAGSESSION_START_INFO_TAG)HParamsPluginDataSessionEndInfoSessionStartInfoz>parameter: hparam_dict should be a dictionary, nothing logged.z>parameter: metric_dict should be a dictionary, nothing logged.zIparameter: hparam_domain_discrete should be a dictionary, nothing logged.c              3   ^   K   | ]'}t          |t                                       V  (d S r@   )r^   type)r7   dhparam_dictks     r/   	<genexpr>zhparams.<locals>.<genexpr>   s9      FFqz!T+a.%9%9::FFFFFFr0   z"parameter: hparam_domain_discrete[z/] should be a list of same type as hparam_dict[z].c                 8    g | ]}t          j        |           S ))number_valuer   Valuer7   r   s     r/   r9   zhparams.<locals>.<listcomp>   6        #(a888  r0   )valuesDATA_TYPE_FLOAT64)namer   domain_discretec                 8    g | ]}t          j        |           S ))string_valuer   r   s     r/   r9   zhparams.<locals>.<listcomp>  r   r0   DATA_TYPE_STRINGc                 8    g | ]}t          j        |           S ))
bool_valuer   r   s     r/   r9   zhparams.<locals>.<listcomp>*  s6        #(A666  r0   DATA_TYPE_BOOL)r   r   z=value should be one of int, float, str, bool, or torch.Tensor)session_start_infoversionplugin_namecontentplugin_data)tagmetadatavaluec                 <    g | ]}  |                     S )r   )r   r5   )r7   r   r   r   s     r/   r9   zhparams.<locals>.<listcomp>P  s3    
C
C
C!::::!,,,---
C
C
Cr0   )hparam_infosmetric_infos)
experimentr   STATUS_SUCCESS)status)session_end_infor   )-rA   #tensorboard.plugins.hparams.api_pb2r   r   r   r   r   r   $tensorboard.plugins.hparams.metadatar   r   r   r   r   +tensorboard.plugins.hparams.plugin_data_pb2r   r   r   r^   dictloggerwarning	TypeErroritemslistallintfloatr   r   r   	ListValueappendr   strr   boolr   Tensorr   
ValueErrorr   
PluginDataSerializeToStringr   )r   metric_dicthparam_domain_discreterA   r   r   r   r   r   r   r   r   r   r   r   r   vhpsssir   r   smdmtsexpseir   r   r   s   `                        @@@r/   r   r      s   ( LLL                                      k4(( 
WXXXL
 
 	
 k4(( 
WXXXL
 
 	
 49r,d33 
W
 
 	
 ',,..  1[  a&& !FFFFFAFFFFF ! lQllghlll  	 ! C



C!!## P
 P
19a#u&& 	*+CKN'***?I?S !7!:  @ @ @ #'JJ
!(;<<$3	     a 	*+CKN'***","6 !7!:  # # # #'JJ
!(:;;$3	     a 	()CKN%***","6 !7!:  # # # #'JJ
!(899$3	     a&& 	

1A*+CKN'JJzzqx~~>Q/R/RSSSTTTK
 
 	
  3@STTTG
#.#W-F-F-H-H
 
 
  C +ACPPPQ
R
R
RC
C
C
C
C
C{
C
C
CC
*#C
8
8
8C38KLLLG
#.#W-F-F-H-H
 
 
  C >CHHHI
J
J
JC .-= > >
?
?
?C>QRRRG
#.#W-F-F-H-H
 
 
  C +?#NNNO
P
P
PCS=r0   Fc                    t          |                                          }|j        dk    r t          d|j         d|j         d          t          |          }|rqt          |gd          }|rt          |gd          }t          j        d	
          }t          |          }t          t          j
        | ||          g          S t          t          j
        | |          g          S )a  Output a `Summary` protocol buffer containing a single scalar value.

    The generated Summary has a Tensor.proto containing the input Tensor.
    Args:
      name: A name for the generated node. Will also serve as the series name in
        TensorBoard.
      tensor: A real numeric Tensor containing a single value.
      collections: Optional list of graph collections keys. The new summary op is
        added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
      new_style: Whether to use new style (tensor field) or old style (simple_value
        field). New style could lead to faster data loading.
    Returns:
      A scalar `Tensor` of type `string`. Which contains a `Summary` protobuf.
    Raises:
      ValueError: If tensor has the wrong shape or type.
    r   zNTensor should contain one element (0 dimensions).             Was given size: z and z dimensions.rI   )rJ   rb   rK   )rL   rb   scalarsr   r   r   rd   r   r   )r   simple_value)r   squeezendimAssertionErrorsizer   r   r   r   r   r   )	r   rd   collections	new_styledouble_precisionr   r!   r   r   s	            r/   r   r   m  s7   " V__$$&&F{a I#[I I/5{I I I J J 	J 6]]F M"fXZHHH 	O&6(+NNNL &0YGGG+666 '   	
 	
 	
 		
 gm6JJJKLLLLr0   c                    |                                 |j        z  dk    rt          d          |j        t          v rOt          |j                 \  }}}t          di d|dt          d |j        D                       | ||          i}nt          |  d|j                   t          j	        d	          }t          |
          }t          t          j        | ||          g          S )a  Outputs a `Summary` protocol buffer containing the full tensor.
    The generated Summary has a Tensor.proto containing the input Tensor.
    Args:
      tag: A name for the generated node. Will also serve as the series name in
        TensorBoard.
      tensor: Tensor to be converted to protobuf
    Returns:
      A tensor protobuf in a `Summary` protobuf.
    Raises:
      ValueError: If tensor is too big to be converted to protobuf, or
                     tensor data type is not supported
    l        zAtensor is bigger than protocol buffer's hard limit of 2GB in sizerb   tensor_shapec                 8    g | ]}t          j        |           S )r   )r	   Dimr6   s     r/   r9   z tensor_proto.<locals>.<listcomp>  s'    LLL!)-1555LLLr0   dimz has unsupported tensor dtype rd   r   r   r   r   rd   r   r5   )numelitemsizer   rb   _TENSOR_TYPE_MAPr   r	   shaper   r   r   r   )r   rd   rb   
field_nameconversion_fnr!   r   r   s           r/   r!   r!     s    ||~~'G44O
 
 	
 |'''+;FL+I(z=" 	
 	
 0LLv|LLL! ! ! MM&11	
 	
 CMMv|MMNNN ",BBBK
k
2
2
2C'-C#lSSSTUUUUr0   c           	      x    t          |||||||          }t          t          j        | |          g          S )a  Output a `Summary` protocol buffer with a histogram.

    The generated
    [`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
    has one summary value containing a histogram for `values`.
    Args:
      name: A name for the generated node. Will also serve as a series name in
        TensorBoard.
      min: A float or int min value
      max: A float or int max value
      num: Int number of values
      sum: Float or int sum of all values
      sum_squares: Float or int sum of squares for all values
      bucket_limits: A numeric `Tensor` with upper value per bucket
      bucket_counts: A numeric `Tensor` with number of values per bucket
    Returns:
      A scalar `Tensor` of type `string`. The serialized `Summary` protocol
      buffer.
    minmaxnumsumsum_squaresbucket_limitbucketr   histor   )r   r   r   )	r   r   r   r   r   r  bucket_limitsbucket_countshists	            r/   r   r     sR    * "  D '-D===>????r0   c                     t          |          }t          |                    t                    ||          }t	          t	          j        | |          g          S )ad  Output a `Summary` protocol buffer with a histogram.

    The generated
    [`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
    has one summary value containing a histogram for `values`.
    This op reports an `InvalidArgument` error if any value is not finite.
    Args:
      name: A name for the generated node. Will also serve as a series name in
        TensorBoard.
      values: A real numeric `Tensor`. Any shape. Values to use to
        build the histogram.
    Returns:
      A scalar `Tensor` of type `string`. The serialized `Summary` protocol
      buffer.
    r  r   )r   r   astyper   r   r   )r   r   binsmax_binsr  s        r/   r   r     sO    " V__F&--..h??D'-D===>????r0   c           
         | j         dk    rt          d          |                     d          } t          j        | |          \  }}t          |          }|||k    r||z  }||z  }|dk    rt          j        |d||z
  ggdd          }|                    d|                              d          }t          j        |j         d	z   f|j	                  }|dd|         |dd<   |d         |d<   |}t          j
        t          j        |d                    }	t          j        |	d|	d         d	z
  gd
          \  }
}t          |
          }
t          |          d	z   }~	|
dk    r||
d	z
  |         nt          j        dg|d|         g          }||
|d	z            }|j         dk    s|j         dk    rt          d          |                     |           }t!          |                                 |                                 t          |           |                                 ||                                |                                          S )zDConvert values into a histogram proto using logic from histogram.cc.r   zThe input has no element.)r  Nconstant)	pad_widthmodeconstant_values)axisr   r   )sidez1The histogram is empty, please file a bug report.r   )r   r   reshaper_   r   lenpadr   emptyrb   cumsumgreatersearchsortedr   concatenatedotr   r   r   r<   )r   r  r  countslimitsnum_binssubsamplingsubsampling_remainder
new_limits
cum_countsstartendsum_sqs                r/   r   r     sd   {a4555^^BF\&t444NFF6{{H8 3 3(* (; 6 A%%V{-BBCD !	  F K0044"4==Xv{Q0&,??
 "[1
3B3
2 2:fa0011JaB!1C-D7SSSJE3JJE
c((Q,C $)199uqy3".1#vdsd|AT2U2U  EC!GO$F{a6;!++LMMMZZFJJLLJJLLKKJJLL]]__}}   r0   NCHWc                 t   t          |          }t          ||          }t          |          }|                    t          j                  }||z                      dd                              t          j                  }t          ||          }t          t          j
        | |          g          S )aJ  Output a `Summary` protocol buffer with images.

    The summary has up to `max_images` summary values containing images. The
    images are built from `tensor` which must be 3-D with shape `[height, width,
    channels]` and where `channels` can be:
    *  1: `tensor` is interpreted as Grayscale.
    *  3: `tensor` is interpreted as RGB.
    *  4: `tensor` is interpreted as RGBA.
    The `name` in the outputted Summary.Value protobufs is generated based on the
    name, with a suffix depending on the max_outputs setting:
    *  If `max_outputs` is 1, the summary value tag is '*name*/image'.
    *  If `max_outputs` is greater than 1, the summary value tags are
       generated sequentially as '*name*/image/0', '*name*/image/1', etc.
    Args:
      tag: A name for the generated node. Will also serve as a series name in
        TensorBoard.
      tensor: A 3-D `uint8` or `float32` `Tensor` of shape `[height, width,
        channels]` where `channels` is 1, 3, or 4.
        'tensor' can either have values in [0, 1] (float32) or [0, 255] (uint8).
        The image() function will scale the image values to [0, 255] by applying
        a scale factor of either 1 (uint8) or 255 (float32). Out-of-range values
        will be clipped.
    Returns:
      A scalar `Tensor` of type `string`. The serialized `Summary` protocol
      buffer.
    r   r]   )rescaler   r   r   )r   r   rf   r
  r_   float32cliprc   r   r   r   )r   rd   r*  dataformatsscale_factorr   s         r/   r   r   4  s    6 V__FFK00F%f--L]]2:&&F|#))!S1188BBFvw///E'-Cu===>????r0   CHWc                    t          |          }t          ||          }t          |          }|                    t          j                  t          |          z  }t          |                    dd                              t          j                  |||          }t          t          j
        | |          g          S )z/Output a `Summary` protocol buffer with images.r   r]   )r*  roislabelsr+  r   )r   r   r
  r_   r,  rf   r   r-  rc   r   r   )r   tensor_imagetensor_boxesr*  r.  r3  r   s          r/   r   r   Z  s     <((L!,<<L<((L&&rz225G5U5UUL!S!!((22	  E '-Cu===>????r0   c           
          |j         d         }t          |          }|D ]B}t          | ||df         ||df         ||df         ||df         |d n||         d          } C| S )Nr   r   rh      Red)rz   r{   )r   ranger   )
disp_imageboxesr3  	num_boxeslist_gtr)   s         r/   r   r   l  s    AIIG 	
 	
%!Q$K!Q$K!Q$K!Q$K &F1I
 
 


 r0   c                    ddl m} | j        \  }}}t          ||z            }t          ||z            }	|                    |           }
|t          |
||          }
|j        j        }|
                    |	|f|          }
ddl	}|
                                }|
                    |d           |                                }|                                 t          j        ||||          S )z=Convert a numpy representation of an image to Image protobuf.r   )ImageN)r3  PNG)formatheightrl   
colorspaceencoded_image_string)ro   r?  r   r   	fromarrayr   
ResamplingLANCZOSresizeioBytesIOsavegetvaluecloser   )rd   r*  r2  r3  r?  rC  rl   channelscaled_heightscaled_widthr   	ANTIALIASrJ  outputimage_strings                  r/   r   r   }  s    #\FE7())Muw''LOOF##E5$v666 (ILL,6	BBEIIIZZ\\F	JJveJ$$$??$$L
LLNNN=)	   r0      c                 p   t          |          }t          |          }t          |          }|                    t          j                  }||z                      dd                              t          j                  }t          ||          }t          t          j
        | |          g          S )Nr   r]   r+  r   )r   r   rf   r
  r_   r,  r-  rc   r   r   r   )r   rd   fpsr/  r   s        r/   r   r     s    V__FF##F%f--L]]2:&&F|#))!S1188BBFvs##E'-Cu===>????r0   c                    	 dd l }n # t          $ r t          d           Y d S w xY w	 ddl m} n!# t          $ r t          dd           Y d S w xY wdd l}| j        \  }}}}|                    t          |           |          }	|                    d          5 }
|
j	        }	 |	
                    |d	d 
           nQ# t          $ rD 	 |	
                    |d	d	           n'# t          $ r |	
                    |d	           Y nw xY wY nw xY w|
                    d           |
                                }t          j        ||||          cd d d            S # 1 swxY w Y   d S )Nr   zadd_video needs package moviepy)editorz6moviepy is installed, but can't import moviepy.editor.z2Some packages could be missing [imageio, requests])rW  z.gif)suffixF)verboser   )r[  progress_bar)r[  rB  )moviepyImportErrorprintrY  tempfiler   ImageSequenceClipr   NamedTemporaryFiler   	write_gifr   seekreadr   r?  )rd   rW  r]  mpyr`  _thwcr-  r&   filenametensor_strings                r/   r   r     s#      /000)))))))   D@	
 	
 	
 	 OOO,KB1a   f3 77D		$	$F	$	3	3 
q6	8NN8U4N@@@@ 	8 	8 	88xUKKKK 8 8 8x777778	8 	
q			 }A!-
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sv    $$/ AAE#B<;E<
D
C D
 !DD
DD
E	D

AEE!ED  c                    t          |          }|                                }t          |                                          dk    r%t	          d           |                    dd          }|j        dk    rt          d          |t          j	        t          j
                  j        z                      d          }dd l}dd l}|                                }|                    |d          5 }|                    d           |                    d           |                    |           |                    |j                   d d d            n# 1 swxY w Y   |                                }|                                 t/          j        |d|j        d         |d	
          }	t/          t/          j        | |	          g          S )Nr   z4warning: audio amplitude out of range, auto clipped.r  z%input tensor should be 1 dimensional.z<i2r   wbrh   z	audio/wav)sample_ratenum_channelslength_framesencoded_audio_stringcontent_type)r   r   r   )r   r   absr   r_  r-  r   r   r_   iinfoint16r
  rJ  waverK  opensetnchannelssetsampwidthsetframeratewriteframesdatarM  rN  r   Audior   r   )
r   rd   rp  arrayrJ  rx  fio
wave_writeaudio_stringr   s
             r/   r   r     s   FOOEMMOOE
5zz~~!DEEE

2q!!zQDEEERXbh''++33E::EIIIKKK
**,,C	3		 +"""""",,,uz***	+ + + + + + + + + + + + + + +
 <<>>LIIKKKMk"o)   E '-Cu===>????s   3AEE Ec           
         g }|                                  D ] \  }}g }|                                 D ]\  }}|d         }|d         dk    rt          |          dk    rt          d          t          j        t          j                            |d         |d         |d                   g          }t          j        ||	          }	n+t          j        |
          }
t          j        ||
          }	|                    |	           |                    t          j	        ||                     "t          j
        |          } t          j        d          }t          |          }t          d|                                 gt                                }t!          t!          j        d||          g          S )Nr   r   Marginr7  zlen(tags) != 3rh   )r   lowerupper)series)titler   r   )r  	multiline)r  chart)categoryr   r   r   	DT_STRINGrb   
string_valr   custom_scalars__config__r   r   )r   r  r   r
   MarginChartContentSeriesChartMultilineChartContentr   CategoryLayoutr   r   r   r   r	   r   r   )layout
categoriesr   r   charts
chart_namechart_metadatatagsmgccr  mlccr   r   rd   s                 r/   r   r     s   J F F1*+'')) 	! 	!&J!!$Da H,,t99>>()9:::!4 #5<<"&q'aQ =     #(z$GGG!7DAAA"(zTJJJMM%    *-AVDDDEEEE
333F!,9IJJJK
k
2
2
2C,,../%''  F
  M8RUVVV
   r0   c           	      r   t          j        dt          d                                                    }t          |          }t	          d|                    d          gt          t          j        d	
          g                    }t          t          j	        | dz   ||          g          S )Nr    r   )r   r   r   r  utf_8)encodingr   r   r   r  z/text_summaryr   r   )
r   r   r   r   r   encoder	   r   r   r   )r   r    r   r   rd   s        r/   r    r      s    !,N1$=$=$=$O$O$Q$Q  K k
2
2
2CKKK112%+;+?Q+G+G+G*HIII	  F }!6VTTTU   r0      c	                 *   |dk    rd}t          j        ||||||f          }	t          d|                                          }
t	          j        d|
          }t	          |          }t          d|	                    d                                          t          t          j
        |	j        d         	          t          j
        |	j        d
         	          g                    }t          t          j        | ||          g          S )Nr  r   r   num_thresholds	pr_curvesr   r   rI   r  r   r   r   rb   rJ   r   r   r   )r_   stackr   r   r   r   r   r  r<   r	   r   r   r   r   )r   tpfptnfn	precisionrecallr  weightsr~  pr_curve_plugin_datar   r   rd   s                 r/   r"   r"   )  s)    8RRY788D,.    ",)=  K k
2
2
2C,,r""))++% !$$*Q-888 $$*Q-888	
 
 
  F '-C#fMMMNOOOOr0   c                 ,   t          |d          }t          ||||          }t          d|                                          }t	          j        d|          }t	          |          }t          d|                    d	                                          t          t          j
        |j        d         
          t          j
        |j        d         
          g                    }	t          t          j        | ||	          g          S )Nr  )r  r  r   r  r  r   r   rI   r  r   r   r   r  r   r   )r   r$   r   r   r   r   r   r  r<   r	   r   r   r   r   )
r   r3  predictionsr  r  r~  r  r   r   rd   s
             r/   r#   r#   G  s)   --NNG  D -.    ",)=  K k
2
2
2C,,r""))++% !$$*Q-888 $$*Q-888	
 
 
  F '-C#fMMMNOOOOr0   c                    d}|d}t          j        t          j        ||dz
  z                      }|                     t           j                  }d|dz
  f}t          j        |||||z            \  }}	t          j        |||d|z
  |z            \  }
}	t          j        |d d d                   d d d         }t          j        |
d d d                   d d d         }|d         |z
  }|d         |z
  }|t          j        |||z             z  }|t          j        |||z             z  }t          j        ||||||f          S )NgHz>g      ?r   r   )r  r9  r  r  )	r_   int32floorr
  float64r   r  maximumr  )r3  r  r  r  _MINIMUM_COUNTbucket_indicesfloat_labelshistogram_range
tp_buckets_
fp_bucketsr  r  r  r  r  r  s                    r/   r$   r$   f  sl   N Xbh{nq6H'IJJKKN==,,L.1,-OLw&  MJ L|#w.  MJ 
:ddd#	$	$TTrT	*B	:ddd#	$	$TTrT	*B	AB	ABRZR888I"*^R"W555F8RRY7888r0   c                    ddl }ddlm}  |j        |          }|                    | ||||j        ||          }	t          d|                    d                                          t          t          j
        |j        d                   t          j
        |j        d                   t          j
        |j        d	                   g
                    }t          j        |                    | |          ||	          }
|
S )a  Create a tensor summary with summary metadata.

    Args:
      name: Uniquely identifiable name of the summary op. Could be replaced by
        combination of name and type to make it unique even outside of this
        summary.
      display_name: Will be used as the display name in TensorBoard.
        Defaults to `name`.
      description: A longform readable description of the summary data. Markdown
        is supported.
      tensor: Tensor to display in summary.
      content_type: Type of content inside the Tensor.
      components: Bitmask representing present parts (vertices, colors, etc.) that
        belong to the summary.
      json_config: A string, JSON-serialized dictionary of ThreeJS classes
        configuration.

    Returns:
      Tensor summary with metadata.
    r   Nr   )json_configrI   r  r   r   rh   r   r  r   )rA   tensorboard.plugins.meshr   	as_tensorcreate_summary_metadatar   r   r  r<   r	   r   r   r   get_instance_name)r   display_namedescriptionrd   rt  
componentsr  rA   r   tensor_metadatatensor_summarys              r/   _get_tensor_summaryr    s,   . LLL111111U_V$$F66 7  O ..$$++--% !$&,q/::: $&,q/::: $&,q/:::	
 	
 	
  F  ]&&t\::   N r0   c                 :    d}| t          j        | d          }|S )z5Parse and returns JSON string from python dictionary.z{}NT)	sort_keys)jsondumps)config_dictr  s     r/   _get_json_configr    s'    Kj===r0   c                 F   ddl m} ddlm} t	          |          }	g }
||j        f||j        f||j        fg}d |D             }|                    d |D                       }|D ]-\  }}|
	                    t          | ||||||	                     .t          |
          S )a'  Output a merged `Summary` protocol buffer with a mesh/point cloud.

    Args:
      tag: A name for this summary operation.
      vertices: Tensor of shape `[dim_1, ..., dim_n, 3]` representing the 3D
        coordinates of vertices.
      faces: Tensor of shape `[dim_1, ..., dim_n, 3]` containing indices of
        vertices within each triangle.
      colors: Tensor of shape `[dim_1, ..., dim_n, 3]` containing colors for each
        vertex.
      display_name: If set, will be used as the display name in TensorBoard.
        Defaults to `name`.
      description: A longform readable description of the summary data. Markdown
        is supported.
      config_dict: Dictionary with ThreeJS classes names and configuration.

    Returns:
      Merged summary for mesh/point cloud representation.
    r   r  )MeshPluginDatac                 "    g | ]}|d          
|S )r   r5   )r7   rd   s     r/   r9   zmesh.<locals>.<listcomp>  s!    EEE&vay/Dv/D/D/Dr0   c                     g | ]\  }}|S r5   r5   )r7   rd   rt  s      r/   r9   zmesh.<locals>.<listcomp>  s    <<<06<<<<r0   r   )r  r   (tensorboard.plugins.mesh.plugin_data_pb2r  r  VERTEXFACECOLORget_components_bitmaskr   r  r   )r   verticescolorsfacesr  r  r  r   r  r  	summariestensorsr  rd   rt  s                  r/   r%   r%     s   , 211111GGGGGG";//KI 
>()	#$	%&G FEGEEEG00<<G<<< J !( 
 
 
	
 
	
 
	
 
	
 ####r0   )rg   rg   rh   )NNN)NFFr@   )r   r(  )r   r0  N)r   NN)rU  )rm  )r  N)NN)Yr  loggingr+   typingr   rA   ra   r_   google.protobufr   $tensorboard.compat.proto.summary_pb2r   r   r   #tensorboard.compat.proto.tensor_pb2r   )tensorboard.compat.proto.tensor_shape_pb2r	   !tensorboard.plugins.custom_scalarr
   ,tensorboard.plugins.pr_curve.plugin_data_pb2r   (tensorboard.plugins.text.plugin_data_pb2r   _convert_npr   _utilsr   r   __all__	getLogger__name__r   r   r   r   r   r   r   r>   rC   rE   halffloat16bfloat16r,  r  doubleint8rc   qint8rw  shortr  qint32int64	complex32chalf	complex64cfloatr   
complex128cdoublequint8quint4x2r   rf   r   r   r   r!   r   r   r   r   r   r   r   r   r   r   r   r    r"   r#   r$   r  r  r%   r5   r0   r/   <module>r      s                 ' & & & & &         
 < ; ; ; ; ; F F F F F F 8 8 8 8 8 8 J J J J J J C C C C C C             2 2 2 2 2 2 2 2  0 
	8	$	$&5 &S & & & &&3 &5 & & & &:5< :DI : : : :4el 4tE{ 4 4 4 4 u|  S	        	JJ(;<	MIz+>? 
N]J0CD 
MJ_=	
 
K*k?; 
MK? 
L;o> 
JI7 
K*i9 
K*i9 
K*i9 
K*i9 
I
I7 
K*i9 
L:y/:  
K*k?;!" 
Onn6LM#$ 
K..2HI	Onn6LM	L>>3IJ	JJ8	8NO	MO^5KL	K*lO<	L:|_=	NZ?5  <5# 5 5 5 5 ( ( ( (VE E E EP+M +M +M +M\%V %V %VP@ @ @D@ @ @ @.5 5 5 5p#@ #@ #@ #@N KO@ @ @ @$   "   6	@ 	@ 	@ 	@%
 %
 %
P@ @ @ @D& & &R  & IMP P P P<P P P P>"9 "9 "9 "9J< < <~   OS6$ 6$ 6$ 6$ 6$ 6$r0   