Example #1
0
    def _load_model(self, model_network_path, model_weight_path):
        """Load a paddle model from disk

        Parameters
        ----------
        model_network_path: str
            Path where the model network path is (json file)

        model_weight_path: str
            Path where the model network weights are (hd5 file)

        Returns
        -------
        model: A paddle model
        """
        from paddle.proto import ModelConfig_pb2
        from mmdnn.conversion.common.IR.IR_graph import load_protobuf_from_file

        loaded_model = ModelConfig_pb2.ModelConfig()
        load_protobuf_from_file(loaded_model, model_network_path)

        if model_weight_path:
            if os.path.isfile(model_weight_path):
                parameters = paddle.parameters.Parameters.from_tar(gzip.open(model_weight_path, 'r'))
                self.weight_loaded = True
                print("Network file [{}] and [{}] is loaded successfully.".format(model_network_path, model_weight_path))

            else:
                print("Warning: Weights File [%s] is not found." % (model_weight_path))

        return loaded_model, parameters
Example #2
0
    def _load_model(model_file):
        """Load a ONNX model file from disk

        Parameters
        ----------
        model_file: str
            Path where the model file path is (protobuf file)

        Returns
        -------
        model: A ONNX protobuf model
        """
        from onnx import onnx_pb2
        from mmdnn.conversion.common.IR.IR_graph import load_protobuf_from_file

        model = onnx_pb2.ModelProto()
        load_protobuf_from_file(model, model_file)

        print("ONNX model file [%s] loaded successfully." % model_file)
        return model
Example #3
0
    def _load_meta(model_network_path):
        """Load a tensorflow meta file from disk

        Parameters
        ----------
        model_network_path: str
            Path where the model network path is (protobuf meta file)

        Returns
        -------
        model: A tensorflow protobuf file
        """
        from tensorflow.core.protobuf import meta_graph_pb2
        from mmdnn.conversion.common.IR.IR_graph import load_protobuf_from_file

        meta_graph = meta_graph_pb2.MetaGraphDef()
        load_protobuf_from_file(meta_graph, model_network_path)
        graph = meta_graph.graph_def

        print ("Tensorflow model file [%s] loaded successfully." % model_network_path)
        return graph
Example #4
0
    def _load_meta(model_network_path):
        """Load a tensorflow meta file from disk

        Parameters
        ----------
        model_network_path: str
            Path where the model network path is (protobuf meta file)

        Returns
        -------
        model: A tensorflow protobuf file
        """
        from tensorflow.core.protobuf import meta_graph_pb2
        from mmdnn.conversion.common.IR.IR_graph import load_protobuf_from_file

        meta_graph = meta_graph_pb2.MetaGraphDef()
        load_protobuf_from_file(meta_graph, model_network_path)
        graph = meta_graph.graph_def

        print ("Tensorflow model file [%s] loaded successfully." % model_network_path)
        return graph