def test_estimate_semantic_data_cub_ae(self):
        """
        Tests if result from semantic data estimation is in the correct shape for cub
        """
        data = loadmat('../../../../Datasets/SEM/cub_demo_data.mat')
        input_length = output_length = data['X_tr'].shape[1] + data[
            'S_tr'].shape[1]
        ae = Encoder(input_length, data['S_tr'].shape[1], output_length,
                     ModelType.SIMPLE_AE_1L, 1)

        labels = data['te_cl_id']
        labels_dict = {
            labels[i][0]: attributes
            for i, attributes in enumerate(data['S_te_pro'])
        }
        s_te = np.array(
            [labels_dict[label[0]] for label in data['test_labels_cub']])

        sem_tr, sem_te = ae.estimate_semantic_data(data['X_tr'], data['X_te'],
                                                   data['S_tr'], s_te)

        self.assertEqual((data['X_tr'].shape[0], data['S_tr'].shape[1]),
                         sem_tr.shape)
        self.assertEqual((data['X_te'].shape[0], data['S_tr'].shape[1]),
                         sem_te.shape)
예제 #2
0
    def estimate_vse_data(self, tr_vis, te_vis, tr_sem, te_sem, y_train,
                          y_test, res_path):
        tr_sem = normalize(tr_sem, norm='l2', axis=1, copy=True)
        tr_vis = normalize(tr_vis, norm='l2', axis=1, copy=True)
        te_vis = normalize(te_vis, norm='l2', axis=1, copy=True)

        te_sem = normalize(te_sem, norm='l2', axis=1, copy=True)
        te_sem = SemanticDegradation.kill_semantic_attributes(
            te_sem, self.degradation_rate)
        te_sem = normalize(te_sem, norm='l2', axis=1, copy=True)

        input_length = output_length = tr_vis.shape[1] + tr_sem.shape[1]
        ae = Encoder(input_length, tr_sem.shape[1], output_length,
                     ModelType.STRAIGHT_AE, self.epochs, res_path,
                     self.run_svm)

        tr_sem, te_sem = ae.estimate_semantic_data(tr_vis, te_vis, tr_sem,
                                                   te_sem, y_train, y_test,
                                                   self.save_results)

        return tr_sem, te_sem