Example #1
0
    def generate_submodel(self, submodel):
        """
        Generates multiple PMML object for the regression and classification submodel of RetinaNet for each connected pyramid layers

        Parameters
        ----------
        submodel :
            The Regression or the Classification submodel

        Returns
        -------
        List of Nyoka's NetworkLayer object for all the submodels
        """
        net_layers_group = list()
        for idx, name in enumerate(self._pyramid_layers):
            nyoka_pmml_reg_mod = kerasAPI.KerasToPmml(submodel)
            del nyoka_pmml_reg_mod.DeepNetwork[0].NetworkLayer[0]
            nyoka_pmml_reg_mod.DeepNetwork[0].NetworkLayer[
                0].connectionLayerId = name
            for idx_, lay in enumerate(
                    nyoka_pmml_reg_mod.DeepNetwork[0].NetworkLayer):
                lay.layerId = lay.layerId + "_" + name
                if idx_ != 0:
                    lay.connectionLayerId = lay.connectionLayerId + "_" + name
            net_layers_group.extend(
                nyoka_pmml_reg_mod.DeepNetwork[0].NetworkLayer)
        return net_layers_group
Example #2
0
    def generate_beckbone_anchors(self, model, input_format, trained_classes):
        """
        Generates PMML object for the backbone + anchors

        Parameters
        ----------
        model : 
            RetinaNet model object
        input_format : string
            Input format to be used during inference with the PMML. Valid values are - 
                "image" : Original image in png format
                "encoded" : Base64 encoded string of the image
        trained_classes : List
            List of class names for which the model was trained

        Returns
        -------
        Nyoka's PMML object

        """
        from keras.models import Sequential
        mod = Sequential()
        for l in model.layers[1:]:
            if l.__class__.__name__ == "Model":
                break
            mod.add(l)
        if trained_classes == None:
            warnings.warn(
                f"trained_classes are not provided. Maximum 80 classes will be considered."
            )
            trained_classes = [
                "Category_" + str(i + 1).zfill(2) for i in range(80)
            ]

        group1_pmml = kerasAPI.KerasToPmml(mod,
                                           model_name=self.model_name,
                                           dataSet=input_format,
                                           description=self.description,
                                           predictedClasses=trained_classes,
                                           script_args=self.script_args)
        return group1_pmml