def json(self):
        if self.training_event_log is not None:
            event_log = self.training_event_log.name
        else:
            event_log = self.file_name.split('_')[0]

        return {
            'id': self.id,
            'creationDate': self.creation_date,
            'algorithm': self.algorithm,
            'trainingEventLog': event_log,
            'trainingDuration': self.training_duration,
            'fileName': self.file_name,
            'trainingHost': self.training_host,
            'hyperparameters':
            json.loads(self.hyperparameters.replace("'", '"')),
            'modelFileExists': ModelFile(self.file_name).path.exists(),
            'cached': ModelFile(self.file_name).result_file.exists()
        }
Esempio n. 2
0
    def load(self, file_name):
        # load model file
        file_name = ModelFile(file_name)

        # load model
        from keras.models import load_model
        from keras.utils import CustomObjectScope
        from april.anomalydetection.binet.attention import Attention
        with CustomObjectScope({'Attention': Attention}):
            self._model = load_model(file_name.str_path)
    def save(self, file_name=None):
        """Save the class instance using pickle.

        :param file_name: Custom file name
        :return: the file path
        """
        if self._model is not None:
            model_file = ModelFile(file_name)
            self._save(model_file.str_path)
            return model_file
        else:
            raise RuntimeError(
                'Saving not possible. No model has been trained yet.')
    def load(self, file_name):
        """
        Load a class instance from a pickle file. If no extension or absolute path are given the method assumes the
        file to be located inside the models dir. Model extension can be omitted in the file name.

        :param file_name: Path to saved model file.
        :return: None
        """
        # load model file
        model_file = ModelFile(file_name)

        # load model
        self._model = pickle.load(open(model_file.path, 'rb'))
    def __init__(self, model):
        if not isinstance(model, ModelFile):
            self.model = ModelFile(model)
        else:
            self.model = model
        self.model_file = self.model.path

        self.model_name = self.model.name
        self.eventlog_name = self.model.event_log_name
        self.process_model_name = self.model.model
        self.noise = self.model.p
        self.dataset_id = self.model.id
        self.model_date = self.model.date
        self.ad_ = AD.get(self.model.ad)()

        self._dataset = None
        self._result = None
        self._binarizer = None
        self._event_log_df = None
        self._classification = None

        import warnings
        warnings.filterwarnings("ignore", category=UndefinedMetricWarning)