Returns a Python callable that runs a particular step. The returned callable will take `len(feed_list)` arguments whose types must be compatible feed values for the respective elements of `feed_list`. For example, if element `i` of `feed_list` is a `tf.Tensor`, the `i`th argument to
(self, fetches, feed_list=None, accept_options=False)
| 1192 | return fetch_handler.build_results(self, results) |
| 1193 | |
| 1194 | def make_callable(self, fetches, feed_list=None, accept_options=False): |
| 1195 | """Returns a Python callable that runs a particular step. |
| 1196 | |
| 1197 | The returned callable will take `len(feed_list)` arguments whose types |
| 1198 | must be compatible feed values for the respective elements of `feed_list`. |
| 1199 | For example, if element `i` of `feed_list` is a `tf.Tensor`, the `i`th |
| 1200 | argument to the returned callable must be a numpy ndarray (or something |
| 1201 | convertible to an ndarray) with matching element type and shape. See |
| 1202 | `tf.Session.run` for details of the allowable feed key and value types. |
| 1203 | |
| 1204 | The returned callable will have the same return type as |
| 1205 | `tf.Session.run(fetches, ...)`. For example, if `fetches` is a `tf.Tensor`, |
| 1206 | the callable will return a numpy ndarray; if `fetches` is a `tf.Operation`, |
| 1207 | it will return `None`. |
| 1208 | |
| 1209 | Args: |
| 1210 | fetches: A value or list of values to fetch. See `tf.Session.run` for |
| 1211 | details of the allowable fetch types. |
| 1212 | feed_list: (Optional.) A list of `feed_dict` keys. See `tf.Session.run` |
| 1213 | for details of the allowable feed key types. |
| 1214 | accept_options: (Optional.) If `True`, the returned `Callable` will be |
| 1215 | able to accept `tf.compat.v1.RunOptions` and `tf.compat.v1.RunMetadata` |
| 1216 | as optional keyword arguments `options` and `run_metadata`, |
| 1217 | respectively, with the same syntax and semantics as `tf.Session.run`, |
| 1218 | which is useful for certain use cases (profiling and debugging) but will |
| 1219 | result in measurable slowdown of the `Callable`'s |
| 1220 | performance. Default: `False`. |
| 1221 | |
| 1222 | Returns: |
| 1223 | A function that when called will execute the step defined by |
| 1224 | `feed_list` and `fetches` in this session. |
| 1225 | |
| 1226 | Raises: |
| 1227 | TypeError: If `fetches` or `feed_list` cannot be interpreted |
| 1228 | as arguments to `tf.Session.run`. |
| 1229 | """ |
| 1230 | if feed_list is not None: |
| 1231 | if not isinstance(feed_list, (list, tuple)): |
| 1232 | raise TypeError('`feed_list` must be a list or tuple.') |
| 1233 | # Delegate any non-empty feed lists to the existing `run()` logic. |
| 1234 | # TODO(mrry): Refactor the feed handling logic from |
| 1235 | # `Session._run()` so that we can convert the feeds to a list of |
| 1236 | # strings here. |
| 1237 | def _generic_run(*feed_args, **kwargs): |
| 1238 | feed_dict = { |
| 1239 | feed: feed_val for feed, feed_val in zip(feed_list, feed_args) |
| 1240 | } |
| 1241 | return self.run(fetches, feed_dict=feed_dict, **kwargs) |
| 1242 | |
| 1243 | return _generic_run |
| 1244 | |
| 1245 | # Ensure any changes to the graph are reflected in the runtime. |
| 1246 | # Note that we don't need to do this on subsequent calls to the |
| 1247 | # returned object, because the arguments to `fetches` must already be |
| 1248 | # in the graph. |
| 1249 | self._extend_graph() |
| 1250 | |
| 1251 | # Create a fetch handler to take care of the structure of fetches. |