示例#1
0
    def __init__(self, model):
        super(Keras2Parser, self).__init__()

        # load model files into Keras graph
        if isinstance(model, _string_types):
            model = _keras.models.load_model(
                model,
                custom_objects={
                    'relu6':
                    _keras.applications.mobilenet.relu6,
                    'DepthwiseConv2D':
                    _keras.applications.mobilenet.DepthwiseConv2D
                })
            self.weight_loaded = True

        elif isinstance(model, tuple):
            model = self._load_model(model[0], model[1])

        else:
            assert False

        # _keras.utils.plot_model(model, "model.png", show_shapes = True)

        # Build network graph
        self.data_format = _keras.backend.image_data_format()
        self.keras_graph = Keras2Graph(model)
        self.keras_graph.build()
        self.lambda_layer_count = 0
示例#2
0
    def __init__(self, model):
        super(Keras2Parser, self).__init__()

        # load model files into Keras graph
        if isinstance(model, _string_types):
            # try:
            #     # Keras 2.1.6
            #     from keras.applications.mobilenet import relu6
            #     from keras.applications.mobilenet import DepthwiseConv2D
            #     model = _keras.models.load_model(
            #         model,
            #         custom_objects={
            #             'relu6': _keras.applications.mobilenet.relu6,
            #             'DepthwiseConv2D': _keras.applications.mobilenet.DepthwiseConv2D
            #         }
            #     )
            # except:
            # Keras. 2.2.2
            import tensorflow.keras.layers as layers
            from tensorflow.keras.initializers import VarianceScaling
            from mmdnn.conversion.keras.metrics import F1Score
            model = _keras.models.load_model(model,
                                             custom_objects={
                                                 'relu6':
                                                 layers.ReLU(6, name='relu6'),
                                                 'DepthwiseConv2D':
                                                 layers.DepthwiseConv2D,
                                                 'AudioVarianceScaling':
                                                 VarianceScaling,
                                                 'F1Score':
                                                 F1Score
                                             })
            self.weight_loaded = True

        elif isinstance(model, tuple):
            model = self._load_model(model[0], model[1])

        else:
            assert False

        # _keras.utils.plot_model(model, "model.png", show_shapes = True)

        # Build network graph
        self.data_format = _keras.backend.image_data_format()
        self.keras_graph = Keras2Graph(model)
        self.keras_graph.build()
        self.lambda_layer_count = 0
示例#3
0
    def __init__(self, model):
        super(Keras2Parser, self).__init__()

        # load model files into Keras graph
        if isinstance(model, _string_types):
            model = _keras.models.load_model(model)
        elif isinstance(model, tuple):
            model = self._load_model(model[0], model[1])
        else:
            assert False

        # _keras.utils.plot_model(model, "model.png", show_shapes = True)

        # Build network graph
        self.data_format = _keras.backend.image_data_format()
        self.keras_graph = Keras2Graph(model)
        self.keras_graph.build()