Fill Tensor shapes in 'graph' with run time shape from 'run_meta'.
(graph, run_meta)
| 37 | |
| 38 | |
| 39 | def _fill_missing_graph_shape(graph, run_meta): |
| 40 | """Fill Tensor shapes in 'graph' with run time shape from 'run_meta'.""" |
| 41 | for dev_stat in run_meta.step_stats.dev_stats: |
| 42 | for node_stat in dev_stat.node_stats: |
| 43 | if not node_stat.output: |
| 44 | continue |
| 45 | try: |
| 46 | op = graph.get_operation_by_name(node_stat.node_name) |
| 47 | except KeyError as e: |
| 48 | # Graph doesn't contains the node_stat, usually RecvTensor. |
| 49 | continue |
| 50 | if len(node_stat.output) != len(op.outputs): |
| 51 | # For example, conditional op has only 1 output at run time. |
| 52 | continue |
| 53 | for (i, node_stat_out) in enumerate(node_stat.output): |
| 54 | if op.outputs[i].get_shape().is_fully_defined(): |
| 55 | continue |
| 56 | node_stat_dims = node_stat_out.tensor_description.shape.dim |
| 57 | node_stat_shape = tensor_shape.TensorShape( |
| 58 | [d.size for d in node_stat_dims]) |
| 59 | try: |
| 60 | op.outputs[i].set_shape(op.outputs[i].get_shape().merge_with( |
| 61 | node_stat_shape)) |
| 62 | except ValueError as e: |
| 63 | sys.stderr.write('Node %s incompatible shapes: %s.\n' % |
| 64 | (node_stat.node_name, e)) |
| 65 | return graph |
| 66 | |
| 67 | |
| 68 | def _str_id(s, str_to_id): |
no test coverage detected