Example #1
0
    def main(self):
        # Generate Model: top structure of tflite model file
        buf = self.tflite_file.read()
        buf = bytearray(buf)
        tf_model = tflite.Model.Model.GetRootAsModel(buf, 0)

        stats = graph_stats.GraphStats()
        # Model file can have many models
        for subgraph_index in range(tf_model.SubgraphsLength()):
            tf_subgraph = tf_model.Subgraphs(subgraph_index)
            model_name = "#{0} {1}".format(subgraph_index, tf_subgraph.Name())
            # 0th subgraph is main subgraph
            if (subgraph_index == 0):
                model_name += " (MAIN)"

            # Parse Operators
            op_parser = OperatorParser(tf_model, tf_subgraph)
            op_parser.Parse()

            stats += graph_stats.CalcGraphStats(op_parser)

            if self.save == False:
                # print all of operators or requested objects
                self.PrintModel(model_name, op_parser)
            else:
                # save all of operators in this model
                self.SaveModel(model_name, op_parser)

        print('==== Model Stats ({} Subgraphs) ===='.format(
            tf_model.SubgraphsLength()))
        print('')
        graph_stats.PrintGraphStats(stats, self.print_level)
Example #2
0
    def PrintInfo(self):
        if self.print_all_tensor == True and self.print_all_operator == True:
            self.PrintModelInfo()
            self.PrintAllOperatorsInList()
            graph_stats.PrintGraphStats(
                graph_stats.CalcGraphStats(self.op_parser), self.verbose)

        if self.print_all_tensor == False:
            print('')
            self.PrintSpecificTensors()

        if self.print_all_operator == False:
            print('')
            self.PrintSpecificOperators()