Ejemplo n.º 1
0
    def _dump_nodeargs(self, graph: fbs.Graph):
        print('NodeArgs:')
        for idx in range(0, graph.NodeArgsLength()):
            node_arg = graph.NodeArgs(idx)
            type = node_arg.Type()
            if not type:
                # NodeArg for optional value that does not exist
                continue

            type_str = FbsTypeInfo.typeinfo_to_str(type)
            value_type = type.ValueType()
            value = type.Value()
            dims = None
            if value_type == fbs.TypeInfoValue.TypeInfoValue.tensor_type:
                tensor_type_and_shape = fbs.TensorTypeAndShape.TensorTypeAndShape(
                )
                tensor_type_and_shape.Init(value.Bytes, value.Pos)
                shape = tensor_type_and_shape.Shape()
                if shape:
                    dims = []
                    for dim in range(0, shape.DimLength()):
                        d = shape.Dim(dim).Value()
                        if d.DimType(
                        ) == fbs.DimensionValueType.DimensionValueType.VALUE:
                            dims.append(str(d.DimValue()))
                        elif d.DimType(
                        ) == fbs.DimensionValueType.DimensionValueType.PARAM:
                            dims.append(d.DimParam().decode())
                        else:
                            dims.append('?')
            else:
                dims = None

            print(f'{node_arg.Name().decode()} type={type_str} dims={dims}')
        print('--------')
Ejemplo n.º 2
0
    def _setup_type_info(graph: fbs.Graph, outer_scope_value_typeinfo={}):
        '''
        Setup the node args for this level of Graph.
        We copy the current list which represents the outer scope values, and add the local node args to that
        to create the valid list of values for the current Graph.
        :param graph: Graph to create NodeArg list for
        :param outer_scope_value_typeinfo: TypeInfo for outer scope values. Empty for the top-level graph in a model.
        :return: Dictionary of NodeArg name to TypeInfo
        '''
        value_name_to_typeinfo = outer_scope_value_typeinfo.copy()
        for j in range(0, graph.NodeArgsLength()):
            n = graph.NodeArgs(j)
            value_name_to_typeinfo[
                n.Name()] = n.Type()  # TypeInfo for this NodeArg's name

        return value_name_to_typeinfo