Creates a print op that will print when a tensor is accessed. Wraps the tensor passed in so that whenever that tensor is accessed, the message `message` is printed, along with the current value of the tensor `t` and an optional list of other tensors. Args: input_: A Tensor/SparseTensor
(input_,
data=None,
message=None,
first_n=None,
summarize=20,
print_tensor_name=True,
print_tensor_type=True,
print_shape=True,
summarize_indicator_vector=True,
name=None)
| 89 | |
| 90 | |
| 91 | def print_op(input_, |
| 92 | data=None, |
| 93 | message=None, |
| 94 | first_n=None, |
| 95 | summarize=20, |
| 96 | print_tensor_name=True, |
| 97 | print_tensor_type=True, |
| 98 | print_shape=True, |
| 99 | summarize_indicator_vector=True, |
| 100 | name=None): |
| 101 | """Creates a print op that will print when a tensor is accessed. |
| 102 | |
| 103 | Wraps the tensor passed in so that whenever that tensor is accessed, |
| 104 | the message `message` is printed, along with the current value of the |
| 105 | tensor `t` and an optional list of other tensors. |
| 106 | |
| 107 | Args: |
| 108 | input_: A Tensor/SparseTensor/TensorArray to print when it is evaluated. |
| 109 | data: A list of other tensors to print. |
| 110 | message: A string message to print as a prefix. |
| 111 | first_n: Only log `first_n` number of times. Negative numbers log always; |
| 112 | this is the default. |
| 113 | summarize: Print this number of elements in the tensor. |
| 114 | print_tensor_name: Print the tensor name. |
| 115 | print_tensor_type: Print the tensor type. |
| 116 | print_shape: Print the tensor's shape. |
| 117 | summarize_indicator_vector: Whether to print the index of the first true |
| 118 | value in an indicator vector (a Boolean tensor). |
| 119 | name: The name to give this op. |
| 120 | |
| 121 | Returns: |
| 122 | A Print op. The Print op returns `input_`. |
| 123 | |
| 124 | Raises: |
| 125 | ValueError: If the tensor `input_` is not a Tensor, SparseTensor or |
| 126 | TensorArray. |
| 127 | |
| 128 | """ |
| 129 | |
| 130 | message = message or "" |
| 131 | if input_ is None: |
| 132 | raise ValueError("input_ must be of type " |
| 133 | "Tensor, SparseTensor or TensorArray") |
| 134 | |
| 135 | tensor_list = _get_tensor_repr(input_, print_tensor_name, print_tensor_type, |
| 136 | print_shape, summarize_indicator_vector) |
| 137 | |
| 138 | if data is not None: |
| 139 | for t in data: |
| 140 | tensor_list.extend(_get_tensor_repr(t, print_tensor_name, |
| 141 | print_tensor_type, print_shape, |
| 142 | summarize_indicator_vector)) |
| 143 | |
| 144 | if isinstance(input_, ops.Tensor) or isinstance(input_, variables.Variable): |
| 145 | input_ = logging_ops.Print(input_, tensor_list, message, first_n, summarize, |
| 146 | name) |
| 147 | elif isinstance(input_, sparse_tensor.SparseTensor): |
| 148 | p = logging_ops.Print( |
no test coverage detected