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)
Example #2
0
def estimate_sem_data_sec(data):
    tr_vis_data = normalize(data['X_tr'], norm='l2', axis=1, copy=True)
    tr_sem_data = normalize(data['S_tr'], norm='l2', axis=1, copy=True)

    te_vis_data = normalize(data['X_te'], norm='l2', axis=1, copy=True)

    input_length = output_length = tr_vis_data.shape[1] + tr_sem_data.shape[1]
    ae = Encoder(input_length, tr_sem_data.shape[1], output_length, ModelType.ZSL_AE, 50, '.', run_svm=False)
    tr_sem, te_sem = ae.estimate_semantic_data_zsl(tr_vis_data, te_vis_data, tr_sem_data, False)

    return tr_sem, te_sem
def estimate_sem_data(tr_vis_data, te_vis_data, tr_sem_data, res_path):
    tr_sem_data = normalize(tr_sem_data, norm='l2', axis=1, copy=True)
    tr_vis_data = normalize(tr_vis_data, norm='l2', axis=1, copy=True)

    te_vis_data = normalize(te_vis_data, norm='l2', axis=1, copy=True)

    input_length = output_length = tr_vis_data.shape[1] + tr_sem_data.shape[1]
    ae = Encoder(input_length, tr_sem_data.shape[1], output_length,
                 ModelType.ZSL_AE, 50, res_path)
    tr_sem, te_sem = ae.estimate_semantic_data_zsl(tr_vis_data, te_vis_data,
                                                   tr_sem_data, False)

    return tr_sem, te_sem
Example #4
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
    def setUpClass(cls):
        """
        Builds and train AE model
        """
        data = loadmat('../../../../Datasets/SEM/cub_demo_data.mat')
        input_length = output_length = data['X_tr'].shape[1] + data[
            'S_tr'].shape[1]
        cls.ae = Encoder(input_length, data['S_tr'].shape[1], output_length,
                         ModelType.SIMPLE_AE, 5)

        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']])
        cls.ae.estimate_semantic_data(data['X_tr'], data['X_te'], data['S_tr'],
                                      s_te)