Beispiel #1
0
    def get_x_data_features_by_sampleidlist(self, cur_sampid_list):
        """
        Do features extraction and cached, get x_data array by cur_sampid_list.
        :param cur_sampid_list:
        :return: list of arrays.
        """
        if self.spec_len_status == 1:
            self.g_cached_train_x.clear()
            self.g_cached_x_sampldid_list.clear()
            self.spec_len_status = 2
        cur_need_id_list = [
            sampleid for sampleid in cur_sampid_list
            if sampleid not in self.g_cached_x_sampldid_list
        ]

        if len(cur_need_id_list) > 0:
            cur_need_origin_xdata = [
                self.g_ori_train_x[cur_sampid]
                for cur_sampid in cur_need_id_list
            ]
            self.imp_feat_args["mode"] = "train"
            cur_need_x_data_list = ut.pre_trans_wav_update(
                cur_need_origin_xdata, self.imp_feat_args)
            for i, cur_sampid in enumerate(cur_need_id_list):
                self.g_cached_x_sampldid_list.extend(cur_sampid_list)
                self.g_cached_x_sampldid_list = list(
                    set(self.g_cached_x_sampldid_list))
                self.g_cached_train_x[cur_sampid] = cur_need_x_data_list[i]
        return [
            self.g_cached_train_x[cur_sampid] for cur_sampid in cur_sampid_list
        ]
Beispiel #2
0
    def test(self, test_x, remaining_time_budget=None):
        """
        :param test_x: list of vectors, input test speech raw data.
        :param remaining_time_budget:
        :return: A `numpy.ndarray` matrix of shape (sample_count, class_num).
                     here `sample_count` is the number of examples in this dataset as train
                     set and `class_num` is the same as the class_num in metadata. The
                     values should be binary.
        """
        K.set_learning_phase(0)
        model = self.model
        if self.test_idx == 1 or self.spec_len_status == 2:
            self.test_x_data_report = self.autospeech_eda.get_x_data_report(
                x_data=test_x)
            or_data_x_seq_mean = self.test_x_data_report.get("x_seq_len_mean")
            self.spec_len_status = 0
            self.imp_feat_args["mode"] = "test"
            test_x = ut.pre_trans_wav_update(test_x, self.imp_feat_args)
            test_x = np.array(test_x)
            self.test_x = test_x[:, :, :, np.newaxis]

        if self.good_to_predict():
            y_pred = model.predict(self.test_x,
                                   batch_size=self.tr34_mconfig.PRED_SIZE)
            if self.tr34_mconfig.ENABLE_PRE_ENSE and self.decision_if_pre_ensemble(
            ):
                self.best_test_predict_prob_list[self.round_idx - 1] = y_pred
                y_pred = self.test_pred_ensemble()
            self.test_idx += 1
            self.last_y_pred = y_pred
            self.last_y_pred_round = self.round_idx
            return y_pred
        else:
            return self.last_y_pred
Beispiel #3
0
 def decide_if_full_valid(self):
     if self.round_idx == self.tr34_mconfig.FULL_VAL_R_START:
         self.accpet_loss_list = [100]
         self.imp_feat_args["mode"] = "train"
         self.g_valid_x_features = ut.pre_trans_wav_update(self.g_valid_x, self.imp_feat_args)
         self.g_valid_gen = generator.DataGenerator(self.g_valid_x_features, self.g_valid_y, **self.params)
     if self.round_idx > self.tr34_mconfig.FULL_VAL_R_START:
         return True
     else:
         return False