コード例 #1
0
ファイル: cnn.py プロジェクト: elitcloud/elit
    def load(self, model_path: str, **kwargs):
        """

        :param model_path: the path to a pre-trained model to be loaded.
        :type model_path: str
        """
        with open(pkl(model_path), 'rb') as fin:
            self.key = pickle.load(fin)
            self.label_map = pickle.load(fin)
            self.chunking = pickle.load(fin)
            self.feature_windows = pickle.load(fin)
            self.input_config = pickle.load(fin)
            self.output_config = pickle.load(fin)
            self.fuse_conv_config = pickle.load(fin)
            self.ngram_conv_config = pickle.load(fin)
            self.hidden_configs = pickle.load(fin)
        logging.info('{} is loaded'.format(pkl(model_path)))
        self.model = CNNModel(input_config=self.input_config,
                              output_config=self.output_config,
                              fuse_conv_config=self.fuse_conv_config,
                              ngram_conv_config=self.ngram_conv_config,
                              hidden_configs=self.hidden_configs)
        # self.model.load_params(params(model_path), self.ctx)
        self.model.load_parameters(params(model_path), self.ctx)
        logging.info('{} is loaded'.format(params(model_path)))
        logging.info(self.__str__())
        return self
コード例 #2
0
 def save(self, model_path, **kwargs):
     """
     :param model_path: the filepath where the model is to be saved.
     :type model_path: str
     """
     with open(pkl(model_path), 'wb') as fout:
         pickle.dump(self.key, fout)
         pickle.dump(self.label_map, fout)
         pickle.dump(self.chunking, fout)
         pickle.dump(self.rnn_config, fout)
         pickle.dump(self.output_config, fout)
     logging.info('{} is saved'.format(pkl(model_path)))
     self.model.save_parameters(params(model_path))
     logging.info('{} is saved'.format(params(model_path)))
コード例 #3
0
 def load(self, model_path: str, **kwargs):
     """
     :param model_path: the path to a pre-trained model to be loaded.
     :type model_path: str
     """
     with open(pkl(model_path), 'rb') as fin:
         self.key = pickle.load(fin)
         self.label_map = pickle.load(fin)
         self.chunking = pickle.load(fin)
         self.rnn_config = pickle.load(fin)
         self.output_config = pickle.load(fin)
     logging.info('{} is loaded'.format(pkl(model_path)))
     self.model = RNNModel(rnn_config=self.rnn_config, output_config=self.output_config)
     self.model.load_parameters(params(model_path), self.ctx)
     # self.model.load_params(params(model_path), self.ctx)
     logging.info('{} is loaded'.format(params(model_path)))
     logging.info(self.__str__())
     return self