It is a wrapper of paddle.base.framework.IrGraph with some special functions for paddle slim framework. Args: program(framework.Program): A program with in_nodes(dict): A dict to indicate the input nodes of the graph. The key is user-defined and
| 72 | |
| 73 | |
| 74 | class GraphWrapper: |
| 75 | """ |
| 76 | It is a wrapper of paddle.base.framework.IrGraph with some special functions |
| 77 | for paddle slim framework. |
| 78 | |
| 79 | Args: |
| 80 | program(framework.Program): A program with |
| 81 | in_nodes(dict): A dict to indicate the input nodes of the graph. |
| 82 | The key is user-defined and human-readable name. |
| 83 | The value is the name of Variable. |
| 84 | out_nodes(dict): A dict to indicate the input nodes of the graph. |
| 85 | The key is user-defined and human-readable name. |
| 86 | The value is the name of Variable. |
| 87 | """ |
| 88 | |
| 89 | def __init__(self, program=None, in_nodes=[], out_nodes=[]): |
| 90 | """ """ |
| 91 | super().__init__() |
| 92 | self.program = Program() if program is None else program |
| 93 | self.persistables = {} |
| 94 | self.teacher_persistables = {} |
| 95 | for var in self.program.list_vars(): |
| 96 | if var.persistable: |
| 97 | self.persistables[var.name] = var |
| 98 | self.compiled_graph = None |
| 99 | in_nodes = [] if in_nodes is None else in_nodes |
| 100 | out_nodes = [] if out_nodes is None else out_nodes |
| 101 | self.in_nodes = OrderedDict(in_nodes) |
| 102 | self.out_nodes = OrderedDict(out_nodes) |
| 103 | self._attrs = OrderedDict() |
| 104 | |
| 105 | def ops(self): |
| 106 | """ |
| 107 | Return all operator nodes included in the graph as a set. |
| 108 | """ |
| 109 | ops = [] |
| 110 | for block in self.program.blocks: |
| 111 | for op in block.ops: |
| 112 | ops.append(OpWrapper(op, self)) |
| 113 | return ops |
| 114 | |
| 115 | def var(self, name): |
| 116 | """ |
| 117 | Get the variable by variable name. |
| 118 | """ |
| 119 | for block in self.program.blocks: |
| 120 | if block.has_var(name): |
| 121 | return VarWrapper(block.var(name), self) |
| 122 | return None |
| 123 | |
| 124 | |
| 125 | def count_convNd(op): |