Ensures that `tensor` is being traced by this tape. Args: tensor: a Tensor or list of Tensors. Raises: ValueError: if it encounters something that is not a tensor.
(self, tensor)
| 835 | pass |
| 836 | |
| 837 | def watch(self, tensor): |
| 838 | """Ensures that `tensor` is being traced by this tape. |
| 839 | |
| 840 | Args: |
| 841 | tensor: a Tensor or list of Tensors. |
| 842 | |
| 843 | Raises: |
| 844 | ValueError: if it encounters something that is not a tensor. |
| 845 | """ |
| 846 | for t in nest.flatten(tensor): |
| 847 | if not (pywrap_tensorflow.IsTensor(t) or |
| 848 | pywrap_tensorflow.IsVariable(t)): |
| 849 | raise ValueError("Passed in object of type {}, not tf.Tensor".format( |
| 850 | type(t))) |
| 851 | if not t.dtype.is_floating: |
| 852 | logging.log_first_n( |
| 853 | logging.WARN, "The dtype of the watched tensor must be " |
| 854 | "floating (e.g. tf.float32), got %r", 5, t.dtype) |
| 855 | if hasattr(t, "handle"): |
| 856 | # There are many variable-like objects, all of them currently have |
| 857 | # `handle` attribute that points to a tensor. If this changes, internals |
| 858 | # of watch_variable need to change as well. |
| 859 | tape.watch_variable(self._tape, t) |
| 860 | else: |
| 861 | tape.watch(self._tape, t) |
| 862 | |
| 863 | @tf_contextlib.contextmanager |
| 864 | def stop_recording(self): |