Perform either run or partial_run, depending the presence of `handle`.
(self, handle, fetches, feed_dict, options, run_metadata)
| 1098 | final_targets) |
| 1099 | |
| 1100 | def _run(self, handle, fetches, feed_dict, options, run_metadata): |
| 1101 | """Perform either run or partial_run, depending the presence of `handle`.""" |
| 1102 | |
| 1103 | def _feed_fn(feed, feed_val): |
| 1104 | for tensor_type, _, feed_fn, _ in _REGISTERED_EXPANSIONS: |
| 1105 | if isinstance(feed, tensor_type): |
| 1106 | return feed_fn(feed, feed_val) |
| 1107 | raise TypeError('Feed argument %r has invalid type %r' % |
| 1108 | (feed, type(feed))) |
| 1109 | |
| 1110 | # Check session. |
| 1111 | if self._closed: |
| 1112 | raise RuntimeError('Attempted to use a closed Session.') |
| 1113 | if self.graph.version == 0: |
| 1114 | raise RuntimeError('The Session graph is empty. Add operations to the ' |
| 1115 | 'graph before calling run().') |
| 1116 | |
| 1117 | # Create request. |
| 1118 | feed_dict_tensor = object_identity.ObjectIdentityDictionary() |
| 1119 | feed_map = {} |
| 1120 | |
| 1121 | # Validate and process feed_dict. |
| 1122 | feed_handles = {} |
| 1123 | if feed_dict: |
| 1124 | feed_dict = nest.flatten_dict_items(feed_dict) |
| 1125 | for feed, feed_val in feed_dict.items(): |
| 1126 | for subfeed, subfeed_val in _feed_fn(feed, feed_val): |
| 1127 | try: |
| 1128 | subfeed_t = self.graph.as_graph_element( |
| 1129 | subfeed, allow_tensor=True, allow_operation=False) |
| 1130 | except Exception as e: |
| 1131 | raise TypeError('Cannot interpret feed_dict key as Tensor: ' + |
| 1132 | e.args[0]) |
| 1133 | |
| 1134 | if isinstance(subfeed_val, ops.Tensor): |
| 1135 | raise TypeError('The value of a feed cannot be a tf.Tensor object. ' |
| 1136 | 'Acceptable feed values include Python scalars, ' |
| 1137 | 'strings, lists, numpy ndarrays, or TensorHandles. ' |
| 1138 | 'For reference, the tensor object was ' + |
| 1139 | str(feed_val) + ' which was passed to the ' |
| 1140 | 'feed with key ' + str(feed) + '.') |
| 1141 | |
| 1142 | subfeed_dtype = subfeed_t.dtype.as_numpy_dtype |
| 1143 | if isinstance(subfeed_val, int) and _convert_to_numpy_obj( |
| 1144 | subfeed_dtype, subfeed_val) != subfeed_val: |
| 1145 | raise TypeError( |
| 1146 | 'Type of feed value ' + str(subfeed_val) + ' with type ' + |
| 1147 | str(type(subfeed_val)) + |
| 1148 | ' is not compatible with Tensor type ' + str(subfeed_dtype) + |
| 1149 | '. Try explicitly setting the type of the feed tensor' |
| 1150 | ' to a larger type (e.g. int64).') |
| 1151 | |
| 1152 | is_tensor_handle_feed = isinstance(subfeed_val, |
| 1153 | session_ops.TensorHandle) |
| 1154 | if is_tensor_handle_feed: |
| 1155 | np_val = subfeed_val.to_numpy_array() |
| 1156 | feed_handles[subfeed_t] = subfeed_val |
| 1157 | else: |
no test coverage detected