Sets up a graph with feeds and fetches for partial run. This is EXPERIMENTAL and subject to change. Note that contrary to `run`, `feeds` only specifies the graph elements. The tensors will be supplied by the subsequent `partial_run` calls. Args: fetches: A single graph eleme
(self, fetches, feeds=None)
| 1021 | return self._run(handle, fetches, feed_dict, None, None) |
| 1022 | |
| 1023 | def partial_run_setup(self, fetches, feeds=None): |
| 1024 | """Sets up a graph with feeds and fetches for partial run. |
| 1025 | |
| 1026 | This is EXPERIMENTAL and subject to change. |
| 1027 | |
| 1028 | Note that contrary to `run`, `feeds` only specifies the graph elements. |
| 1029 | The tensors will be supplied by the subsequent `partial_run` calls. |
| 1030 | |
| 1031 | Args: |
| 1032 | fetches: A single graph element, or a list of graph elements. |
| 1033 | feeds: A single graph element, or a list of graph elements. |
| 1034 | |
| 1035 | Returns: |
| 1036 | A handle for partial run. |
| 1037 | |
| 1038 | Raises: |
| 1039 | RuntimeError: If this `Session` is in an invalid state (e.g. has been |
| 1040 | closed). |
| 1041 | TypeError: If `fetches` or `feed_dict` keys are of an inappropriate type. |
| 1042 | tf.errors.OpError: Or one of its subclasses if a TensorFlow error happens. |
| 1043 | """ |
| 1044 | |
| 1045 | def _feed_fn(feed): |
| 1046 | for tensor_type, _, _, feed_fn in _REGISTERED_EXPANSIONS: |
| 1047 | if isinstance(feed, tensor_type): |
| 1048 | return feed_fn(feed) |
| 1049 | raise TypeError('Feed argument %r has invalid type %r' % |
| 1050 | (feed, type(feed))) |
| 1051 | |
| 1052 | # Check session. |
| 1053 | if self._closed: |
| 1054 | raise RuntimeError('Attempted to use a closed Session.') |
| 1055 | if self.graph.version == 0: |
| 1056 | raise RuntimeError('The Session graph is empty. Add operations to the ' |
| 1057 | 'graph before calling run().') |
| 1058 | |
| 1059 | if feeds is None: |
| 1060 | feeds = [] |
| 1061 | # Create request. |
| 1062 | feed_list = [] |
| 1063 | |
| 1064 | # Validate and process feed_list. |
| 1065 | is_list_feed = isinstance(feeds, (list, tuple)) |
| 1066 | if not is_list_feed: |
| 1067 | feeds = [feeds] |
| 1068 | for feed in feeds: |
| 1069 | for subfeed in _feed_fn(feed): |
| 1070 | try: |
| 1071 | subfeed_t = self.graph.as_graph_element( |
| 1072 | subfeed, allow_tensor=True, allow_operation=False) |
| 1073 | # pylint: disable=protected-access |
| 1074 | feed_list.append(subfeed_t._as_tf_output()) |
| 1075 | # pylint: enable=protected-access |
| 1076 | except Exception as e: |
| 1077 | e.message = ('Cannot interpret feed_list key as Tensor: ' + e.message) |
| 1078 | e.args = (e.message,) |
| 1079 | raise e |
| 1080 |