Contains information about the result of a transform operation.
| 192 | |
| 193 | |
| 194 | class TransformerInfo(object): |
| 195 | """"Contains information about the result of a transform operation.""" |
| 196 | |
| 197 | def __init__(self, info): |
| 198 | """Constructor. |
| 199 | |
| 200 | Args: |
| 201 | info: an instance of Transformer._TmpInfo containing various internal |
| 202 | information about the transform operation. |
| 203 | """ |
| 204 | self._graph = info.graph |
| 205 | self._scope = info.scope |
| 206 | self._graph_ = info.graph_ |
| 207 | self._scope_ = info.scope_ |
| 208 | self._transformed_ops = info.transformed_ops |
| 209 | self._transformed_ts = info.transformed_ts |
| 210 | |
| 211 | def _get_transformed_map(self, top): |
| 212 | """Return the correct container depending on the type of `top`.""" |
| 213 | if isinstance(top, tf_ops.Operation): |
| 214 | return self._transformed_ops |
| 215 | elif isinstance(top, tf_ops.Tensor): |
| 216 | return self._transformed_ts |
| 217 | else: |
| 218 | raise TypeError( |
| 219 | "Expected a tf.Tensor or a tf.Operation, got a {}".format( |
| 220 | type(top))) |
| 221 | |
| 222 | def _transformed_elem(self, original_top, missing_fn=None): |
| 223 | """Return the transformed op/tensor corresponding to the original one. |
| 224 | |
| 225 | Args: |
| 226 | original_top: the original tensor/operation. |
| 227 | missing_fn: function handling the case where the counterpart |
| 228 | cannot be found. By default, None is returned. |
| 229 | Returns: |
| 230 | the transformed tensor/operation (or None if no match is found). |
| 231 | """ |
| 232 | transformed_map = self._get_transformed_map(original_top) |
| 233 | if isinstance(original_top, string_types): |
| 234 | for original, transformed in iteritems(transformed_map): |
| 235 | if original.name == original_top: |
| 236 | return transformed |
| 237 | return None if missing_fn is None else missing_fn(original_top) |
| 238 | else: |
| 239 | if original_top not in transformed_map: |
| 240 | return None if missing_fn is None else missing_fn(original_top) |
| 241 | return transformed_map[original_top] |
| 242 | |
| 243 | def _original_elem(self, transformed_top, missing_fn=None): |
| 244 | """Return the original op/tensor corresponding to the transformed one. |
| 245 | |
| 246 | Args: |
| 247 | transformed_top: the transformed tensor/operation. |
| 248 | missing_fn: function handling the case where the counterpart |
| 249 | cannot be found. By default, None is returned. |
| 250 | Returns: |
| 251 | the original tensor/operation (or None if no match is found). |