
    AVhUk                     "   d Z ddlZddlZ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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 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 Z	  e         e         edd       edg      ej@                  d4d                     Z!d5dZ"d Z# ed      ej@                  d               Z$ ejJ                  d      d        Z&d Z' edd      d6d       Z( edd       d7d!       Z) edd"      	 	 	 d7d#       Z* edd$      d6d%       Z+ edd&      ejX                  jZ                  fd'       Z.d( Z/ edd)      d6d*       Z0 ejb                  d+        ejb                  d,        ejb                  d-        ejb                  d.        ejb                  d/        ejb                  d0        ejb                  d1        ejb                  d2        ejb                  d3       y# e$ r Y w xY w)8zCLogging and Summary Operations.

API docstring: tensorflow.logging
    N)logging)
pywrap_tfe)dtypes)ops)sparse_tensor)tensor_util)gen_logging_ops)
string_ops)*)
tf_logging)dispatch)nest)
deprecated)	tf_exportc                  ,    t        j                          y N)r   %TFE_Py_EnableInteractivePythonLogging     Q/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/logging_ops.pyenable_interactive_loggingr   .   s    224r   z
2018-08-20a  Use tf.print instead of tf.Print. Note that tf.print returns a no-output operator that directly prints the output. Outside of defuns or eager mode, this operator will not be executed unless it is directly specified in session.run or used as a control dependency for other operators. This is only a concern in graph mode. Below is an example of how to ensure tf.print executes in graph mode:
Print)v1c                 6    t        j                  | |||||      S )a  Prints a list of tensors.

  This is an identity op (behaves like `tf.identity`) with the side effect
  of printing `data` when evaluating.

  Note: This op prints to the standard error. It is not currently compatible
    with jupyter notebook (printing to the notebook *server's* output, not into
    the notebook).

  @compatibility(TF2)
  This API is deprecated. Use `tf.print` instead. `tf.print` does not need the
  `input_` argument.

  `tf.print` works in TF2 when executing eagerly and inside a `tf.function`.

  In TF1-styled sessions, an explicit control dependency declaration is needed
  to execute the `tf.print` operation. Refer to the documentation of
  `tf.print` for more details.
  @end_compatibility

  Args:
    input_: A tensor passed through this op.
    data: A list of tensors to print out when op is evaluated.
    message: A string, prefix of the error message.
    first_n: Only log `first_n` number of times. Negative numbers log always;
      this is the default.
    summarize: Only print this many entries of each tensor. If None, then a
      maximum of 3 elements are printed per input tensor.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type and contents as `input_`.

    ```python
    sess = tf.compat.v1.Session()
    with sess.as_default():
        tensor = tf.range(10)
        print_op = tf.print(tensor)
        with tf.control_dependencies([print_op]):
          out = tf.add(tensor, tensor)
        sess.run(out)
    ```
  )r	   _print)input_datamessagefirst_n	summarizenames         r   r   r   C   s     l 
		gw	4	PPr   c                     |}t        j                  d      }|| v r#|t        |j                  dd            z   }|| v r#|S )z9Generate and return a string that does not appear in `x`.   r   	   )randomRandomstrrandint)xdefault_placeholderplaceholderrngs       r   _generate_placeholder_stringr-      sG    #+a#qCKK1$5 66K 	q	r   c                 H    t        | t              xr | j                  d      S )z-Returns True if output_stream is a file path.zfile://)
isinstancer'   
startswith)output_streams    r   _is_filepathr2      s    	M3	'	OM,D,DY,OOr   printc            	      z	   |j                  dt        j                        }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dt        j                        }|rt        d	|z        d}|r|d
z   }i t        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dt        j                   dt        j                  dt        j                  dt        j                  dt        j                  dt        j                  di}t#        |      r|}	n0|j%                  |      }	|	st        dt'        |      z   dz   dz         t)        |       dk(  rxt+        j,                  | d         r`t/        | d   t0        j2                        sC| d   j4                  j6                  dk(  r'| d   j8                  t:        j<                  k(  r| d   }
ng }g }g }| D ]i  }t/        |t>        j@                        r<|jC                  t?        j@                  tE        |jG                                            Y|jC                  |       k tI        jJ                  d |      }djM                  d |D              }tO        |      }| D ]$  }g }tI        jP                  |      D ]  }t/        |t0        j2                        rU|jS                  |jT                  |jV                  |jX                  g       |jC                  dj[                  |||             rt+        j,                  |      r#|jC                  |       |jC                  |       |jC                  |        t/        |t&              r|}n)t]        j^                  tI        j`                  ||            }|jC                  |       ' |jM                  |      }|jc                  d|z   dz   |      }te        jf                  |||||      }
ti        jj                  |
|	||      S )a  Print the specified inputs.

  A TensorFlow operator that prints the specified inputs to a desired
  output stream or logging level. The inputs may be dense or sparse Tensors,
  primitive python objects, data structures that contain tensors, and printable
  Python objects. Printed tensors will recursively show the first and last
  elements of each dimension to summarize.

  Example:
    Single-input usage:

    ```python
    tensor = tf.range(10)
    tf.print(tensor, output_stream=sys.stderr)
    ```

    (This prints "[0 1 2 ... 7 8 9]" to sys.stderr)

    Multi-input usage:

    ```python
    tensor = tf.range(10)
    tf.print("tensors:", tensor, {2: tensor * 2}, output_stream=sys.stdout)
    ```

    (This prints "tensors: [0 1 2 ... 7 8 9] {2: [0 2 4 ... 14 16 18]}" to
    sys.stdout)

    Changing the input separator:
    ```python
    tensor_a = tf.range(2)
    tensor_b = tensor_a * 2
    tf.print(tensor_a, tensor_b, output_stream=sys.stderr, sep=',')
    ```

    (This prints "[0 1],[0 2]" to sys.stderr)

    Usage in a `tf.function`:

    ```python
    @tf.function
    def f():
        tensor = tf.range(10)
        tf.print(tensor, output_stream=sys.stderr)
        return tensor

    range_tensor = f()
    ```

    (This prints "[0 1 2 ... 7 8 9]" to sys.stderr)

  *Compatibility usage in TF 1.x graphs*:

    In graphs manually created outside of `tf.function`, this method returns
    the created TF operator that prints the data. To make sure the
    operator runs, users need to pass the produced op to
    `tf.compat.v1.Session`'s run method, or to use the op as a control
    dependency for executed ops by specifying
    `with tf.compat.v1.control_dependencies([print_op])`.

    ```python
    tf.compat.v1.disable_v2_behavior()  # for TF1 compatibility only

    sess = tf.compat.v1.Session()
    with sess.as_default():
      tensor = tf.range(10)
      print_op = tf.print("tensors:", tensor, {2: tensor * 2},
                          output_stream=sys.stdout)
      with tf.control_dependencies([print_op]):
        tripled_tensor = tensor * 3

      sess.run(tripled_tensor)
    ```

    (This prints "tensors: [0 1 2 ... 7 8 9] {2: [0 2 4 ... 14 16 18]}" to
    sys.stdout)

  Note: In Jupyter notebooks and colabs, `tf.print` prints to the notebook
    cell outputs. It will not write to the notebook kernel's console logs.

  Args:
    *inputs: Positional arguments that are the inputs to print. Inputs in the
      printed output will be separated by spaces. Inputs may be python
      primitives, tensors, data structures such as dicts and lists that may
      contain tensors (with the data structures possibly nested in arbitrary
      ways), and printable python objects.
    output_stream: The output stream, logging level, or file to print to.
      Defaults to sys.stderr, but sys.stdout, tf.compat.v1.logging.info,
      tf.compat.v1.logging.warning, tf.compat.v1.logging.error,
      absl.logging.info, absl.logging.warning and absl.logging.error are also
      supported. To print to a file, pass a string started with "file://"
      followed by the file path, e.g., "file:///tmp/foo.out".
    summarize: The first and last `summarize` elements within each dimension are
      recursively printed per Tensor. If None, then the first 3 and last 3
      elements of each dimension are printed for each tensor. If set to -1, it
      will print all elements of every tensor.
    sep: The string to use to separate the inputs. Defaults to " ".
    end: End character that is appended at the end the printed string. Defaults
      to the newline character.
    name: A name for the operation (optional).

  Returns:
    None when executing eagerly. During graph tracing this returns
    a TF operator that prints the specified inputs in the specified output
    stream or logging level. This operator will be automatically executed
    except inside of `tf.compat.v1` graphs and sessions.

  Raises:
    ValueError: If an unsupported output stream is specified.
  r1   r!   Nr       sep endz/Unrecognized keyword arguments for tf.print: %s_formatstdoutstderrz	log(info)zlog(warning)z
log(error)z2Unsupported output stream, logging level, or file.zg. Supported streams are sys.stdout, sys.stderr, tf.logging.info, tf.logging.warning, tf.logging.error. z4File needs to be in the form of 'file://<filepath>'.   r   c                 4    t        j                  |       rdS | S )N )r   
is_tf_type)r)   s    r   <lambda>zprint_v2.<locals>.<lambda>O  s    ..q1" q r   c              3   F   K   | ]  }t        j                  |        y wr   )pprintpformat).0r)   s     r   	<genexpr>zprint_v2.<locals>.<genexpr>R  s      $:q$:s   !z-SparseTensor(indices={}, values={}, shape={})')inputstemplater+   r    r!   )r1   r!   r8   )6popsysr;   oslinesep
ValueErrorr:   r   INFOinfoWARNwarningwarnERRORerrorr   WARNINGr2   getr'   lenr   r?   r/   r   SparseTensorshapendimsdtyper   stringpy_collectionsOrderedDictappendsorteditemsr   map_structurejoinr-   flattenextendindicesvaluesdense_shapeformatrB   rC   pack_sequence_asreplacer
   string_formatr	   print_v2)rG   kwargsr1   r!   r    r6   r8   format_nameoutput_stream_to_constantoutput_stream_stringformatted_string	templatestensorsinputs_ordered_dicts_sortedr   tensor_free_structuretensor_free_templater+   placeholdersr)   cur_templaterH   s                         r   rm   rm      s   j **_cjj9-	FD	!$jja()

5##

5"**%#
FO
PP+	"K	jj(	jj( oo{ oo{	
 oo~ . oo~   llK llK llK oo~ llN oo~  llN!" mm\#$ mm\%* - (488GK=)*@@
 NN O O 
&kQ;11&)<fQi!;!;<ay!q	6==(Hay IG
 #% 3	FN66	7#**&&vflln'=>	@ 	$**623 !..8#% 88 $:#8$: :./CDK $%l
 ||F# !!a334
..!))QXXq}}=
>


=DD{K9: ##A&
..



k
*


a
 ! 
FC	   ~~!!&,79|$I$%V xx	"Hk 1C 7EH!// 
	!	!&:3
P Pr   c                 R    t        |      d gt        | j                        dz
  z  z   S )Nr<   )listrW   rG   )opgrads     r   
_PrintGradr~     s%    	dtfBII 23	33r   c                 F    ||}|D ]  }t        j                  ||         y r   )r   add_to_collection)valcollectionsdefault_collectionskeys       r   _Collectr     s,    %K $c#s#$r   z
2016-11-30zPlease switch to tf.summary.histogram. Note that tf.summary.histogram uses the node name instead of the tag. This means that TensorFlow will automatically de-duplicate summary names based on the scope they are created in.c                     t        j                  |d| |g      5 }t        j                  | ||      }t	        ||t         j
                  j                  g       ddd       |S # 1 sw Y   S xY w)a  Outputs a `Summary` protocol buffer with a histogram.

  This ops is deprecated. Please switch to tf.summary.histogram.

  For an explanation of why this op was deprecated, and information on how to
  migrate, look
  ['here'](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/deprecated/__init__.py)

  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:
    tag: A `string` `Tensor`. 0-D.  Tag to use for the summary value.
    values: A real numeric `Tensor`. Any shape. Values to use to build the
      histogram.
    collections: Optional list of graph collections keys. The new summary op is
      added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
    name: A name for the operation (optional).

  Returns:
    A scalar `Tensor` of type `string`. The serialized `Summary` protocol
    buffer.
  HistogramSummary)tagrg   r!   N)r   
name_scoper	   histogram_summaryr   	GraphKeys	SUMMARIES)r   rg   r   r!   scoper   s         r   r   r     sg    B ~~d.f> :%

+
+F
OCS+ 7 789: 
*: 
*   ?A##A-a  Please switch to tf.summary.image. Note that tf.summary.image uses the node name instead of the tag. This means that TensorFlow will automatically de-duplicate summary names based on the scope they are created in. Also, the max_images argument was renamed to max_outputs.c                     t        j                  |d| |g      5 }t        j                  | |||      }t	        ||t         j
                  j                  g       ddd       |S # 1 sw Y   S xY w)a  Outputs a `Summary` protocol buffer with images.

  For an explanation of why this op was deprecated, and information on how to
  migrate, look
  ['here'](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/deprecated/__init__.py)

  The summary has up to `max_images` summary values containing images. The
  images are built from `tensor` which must be 4-D with shape `[batch_size,
  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 images have the same number of channels as the input tensor. For float
  input, the values are normalized one image at a time to fit in the range
  `[0, 255]`.  `uint8` values are unchanged.  The op uses two different
  normalization algorithms:

  *  If the input values are all positive, they are rescaled so the largest one
     is 255.

  *  If any input value is negative, the values are shifted so input value 0.0
     is at 127.  They are then rescaled so that either the smallest value is 0,
     or the largest one is 255.

  The `tag` argument is a scalar `Tensor` of type `string`.  It is used to
  build the `tag` of the summary values:

  *  If `max_images` is 1, the summary value tag is '*tag*/image'.
  *  If `max_images` is greater than 1, the summary value tags are
     generated sequentially as '*tag*/image/0', '*tag*/image/1', etc.

  Args:
    tag: A scalar `Tensor` of type `string`. Used to build the `tag` of the
      summary values.
    tensor: A 4-D `uint8` or `float32` `Tensor` of shape `[batch_size, height,
      width, channels]` where `channels` is 1, 3, or 4.
    max_images: Max number of batch elements to generate images for.
    collections: Optional list of ops.GraphKeys.  The collections to add the
      summary to.  Defaults to [ops.GraphKeys.SUMMARIES]
    name: A name for the operation (optional).

  Returns:
    A scalar `Tensor` of type `string`. The serialized `Summary` protocol
    buffer.
  ImageSummary)r   tensor
max_imagesr!   N)r   r   r	   image_summaryr   r   r   )r   r   r   r   r!   r   r   s          r   r   r     sl    n ~~dNS&M: :e

'
':ECCS+ 7 789: 
*	: 
*s   A A$$A.zPlease switch to tf.summary.audio. Note that tf.summary.audio uses the node name instead of the tag. This means that TensorFlow will automatically de-duplicate summary names based on the scope they are created in.c                 0   t        j                  |d| |g      5 }t        j                  |t        j                  d      }t        j                  | ||||      }t        ||t         j                  j                  g       ddd       |S # 1 sw Y   S xY w)at  Outputs a `Summary` protocol buffer with audio.

  This op is deprecated. Please switch to tf.summary.audio.
  For an explanation of why this op was deprecated, and information on how to
  migrate, look
  ['here'](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/deprecated/__init__.py)

  The summary has up to `max_outputs` summary values containing audio. The
  audio is built from `tensor` which must be 3-D with shape `[batch_size,
  frames, channels]` or 2-D with shape `[batch_size, frames]`. The values are
  assumed to be in the range of `[-1.0, 1.0]` with a sample rate of
  `sample_rate`.

  The `tag` argument is a scalar `Tensor` of type `string`.  It is used to
  build the `tag` of the summary values:

  *  If `max_outputs` is 1, the summary value tag is '*tag*/audio'.
  *  If `max_outputs` is greater than 1, the summary value tags are
     generated sequentially as '*tag*/audio/0', '*tag*/audio/1', etc.

  Args:
    tag: A scalar `Tensor` of type `string`. Used to build the `tag` of the
      summary values.
    tensor: A 3-D `float32` `Tensor` of shape `[batch_size, frames, channels]`
      or a 2-D `float32` `Tensor` of shape `[batch_size, frames]`.
    sample_rate: A Scalar `float32` `Tensor` indicating the sample rate of the
      signal in hertz.
    max_outputs: Max number of batch elements to generate audio for.
    collections: Optional list of ops.GraphKeys.  The collections to add the
      summary to.  Defaults to [ops.GraphKeys.SUMMARIES]
    name: A name for the operation (optional).

  Returns:
    A scalar `Tensor` of type `string`. The serialized `Summary` protocol
    buffer.
  AudioSummarysample_rate)r[   r!   )r   r   max_outputsr   r!   N)
r   r   convert_to_tensorr   float32r	   audio_summary_v2r   r   r   )r   r   r   r   r   r!   r   r   s           r   audio_summaryr     s    ` ~~dNS&M: 	:e''6>>?K

*
*C S+ 7 789	: 
*	: 
*s   A'BBz"Please switch to tf.summary.merge.c                     t        j                  |d|       5  t        j                  | |      }t	        ||g        ddd       |S # 1 sw Y   S xY w)aq  Merges summaries.

  This op is deprecated. Please switch to tf.compat.v1.summary.merge, which has
  identical
  behavior.

  This op creates a
  [`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
  protocol buffer that contains the union of all the values in the input
  summaries.

  When the Op is run, it reports an `InvalidArgument` error if multiple values
  in the summaries to merge use the same tag.

  Args:
    inputs: A list of `string` `Tensor` objects containing serialized `Summary`
      protocol buffers.
    collections: Optional list of graph collections keys. The new summary op is
      added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
    name: A name for the operation (optional).

  Returns:
    A scalar `Tensor` of type `string`. The serialized `Summary` protocol
    buffer resulting from the merging.
  MergeSummary)rG   r!   N)r   r   r	   merge_summaryr   )rG   r   r!   r   s       r   r   r   ?  sP    8 ~~dNF3 #

'
'vD
ACS+r"# 
*# 
*s   %AAz&Please switch to tf.summary.merge_all.c                 H    t        j                  |       }|syt        |      S )a  Merges all summaries collected in the default graph.

  This op is deprecated. Please switch to tf.compat.v1.summary.merge_all, which
  has
  identical behavior.

  Args:
    key: `GraphKey` used to collect the summaries.  Defaults to
      `GraphKeys.SUMMARIES`.

  Returns:
    If no summaries were collected, returns None.  Otherwise returns a scalar
    `Tensor` of type `string` containing the serialized `Summary` protocol
    buffer resulting from the merging.
  N)r   get_collectionr   )r   summary_opss     r   merge_all_summariesr   a  s%    " ""3'+	%%r   c                      t        j                  t         j                  j                        } | 
| r| d   } nd} | :t	               } | .t        j
                  t         j                  j                  |        | S )a_  Returns a single Summary op that would run all summaries.

  Either existing one from `SUMMARY_OP` collection or merges all existing
  summaries.

  Returns:
    If no summaries were collected, returns None. Otherwise returns a scalar
    `Tensor` of type `string` containing the serialized `Summary` protocol
    buffer resulting from the merging.
  Nr   )r   r   r   
SUMMARY_OPr   r   )
summary_ops    r   get_summary_opr   y  si     !!#--":":;*a=jj$&J	CMM44jA	r   a-  Please switch to tf.summary.scalar. Note that tf.summary.scalar uses the node name instead of the tag. This means that TensorFlow will automatically de-duplicate summary names based on the scope they are created in. Also, passing a tensor or list of tags to a scalar summary op is no longer supported.c                     t        j                  |d| |g      5 }t        j                  | ||      }t	        ||t         j
                  j                  g       ddd       |S # 1 sw Y   S xY w)a  Outputs a `Summary` protocol buffer with scalar values.

  This ops is deprecated. Please switch to tf.summary.scalar.
  For an explanation of why this op was deprecated, and information on how to
  migrate, look
  ['here'](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/deprecated/__init__.py)

  The input `tags` and `values` must have the same shape.  The generated
  summary has a summary value for each tag-value pair in `tags` and `values`.

  Args:
    tags: A `string` `Tensor`.  Tags for the summaries.
    values: A real numeric Tensor.  Values for the summaries.
    collections: Optional list of graph collections keys. The new summary op is
      added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
    name: A name for the operation (optional).

  Returns:
    A scalar `Tensor` of type `string`. The serialized `Summary` protocol
    buffer.
  ScalarSummary)tagsrg   r!   N)r   r   r	   scalar_summaryr   r   r   )r   rg   r   r!   r   r   s         r   r   r     se    < ~~dOdF^< :

(
(d6
NCS+ 7 789: 
*: 
*r   r   r   r   AudioSummaryV2r   r   TensorSummaryTensorSummaryV2	Timestamp)NNNN)z{})NN)r5   NN)2__doc__r   r]   rK   rB   r%   rJ   abslr   tensorflow.pythonr   tensorflow.python.frameworkr   r   r   r   tensorflow.python.opsr	   r
   %tensorflow.python.ops.gen_logging_opstensorflow.python.platformr   tensorflow.python.utilr   r   "tensorflow.python.util.deprecationr    tensorflow.python.util.tf_exportr   r   get_ipython	NameErroradd_dispatch_supportr   r-   r2   rm   RegisterGradientr~   r   r   r   r   r   r   r   r   r   r   NotDifferentiabler   r   r   <module>r      s  
 % 	   
  ( . + 5 3 1 , 4 1 + ' 9 65- L B C wi	,Q  C,QdP 7	vP  vPx g4 4$  45
5
D  +,5,5p  45  "55
5p L>? @B LBCMM33 & D&.0  :   ( )   n %   n %   & '   n %   o &   o &   ' (   k "Q  s   .H HH