import numpy as np if __name__ == '__main__': # root = '/Users/cengmeng/PycharmProjects/python/Deep-subspace-clustering-networks/Data/' root = '/content/' # im_, gt_ = 'SalinasA_corrected', 'SalinasA_gt' im_, gt_ = 'Indian_pines_corrected', 'Indian_pines_gt' # im_, gt_ = 'Pavia', 'Pavia_gt' # im_, gt_ = 'KSC', 'KSC_gt' img_path = root + im_ + '.mat' gt_path = root + gt_ + '.mat' p = Processor() img, gt = p.prepare_data(img_path, gt_path) n_row, n_column, n_band = img.shape train_inx, test_idx = p.get_tr_tx_index(p.get_correct(img, gt)[1], test_size=0.9) img = minmax_scale(img.reshape(n_row * n_column, n_band)).reshape( (n_row, n_column, n_band)) x_input = img.reshape(n_row * n_column, n_band) num_class = 15 snmf = BandSelection_SNMF(num_class) X_new = snmf.predict(x_input).reshape(n_row, n_column, num_class) a, b = p.get_correct(X_new, gt) b = p.standardize_label(b) print(eval_band_cv(a, b, times=5))
im_, gt_ = 'Indian_pines_corrected', 'Indian_pines_gt' # im_, gt_ = 'Pavia', 'Pavia_gt' # im_, gt_ = 'Botswana', 'Botswana_gt' # im_, gt_ = 'KSC', 'KSC_gt' img_path = root + im_ + '.mat' gt_path = root + gt_ + '.mat' print(img_path) p = Processor() img, gt = p.prepare_data(img_path, gt_path) # Img, Label = Img[:256, :, :], Label[:256, :] n_row, n_column, n_band = img.shape X_img = minmax_scale(img.reshape(n_row * n_column, n_band)).reshape( (n_row, n_column, n_band)) img_correct, gt_correct = p.get_correct(X_img, gt) gt_correct = p.standardize_label(gt_correct) X_img_2D = X_img.reshape(n_row * n_column, n_band) train_inx, test_idx = p.get_tr_tx_index(gt_correct, test_size=0.4) n_input = [n_row, n_column] kernel_size = [11] n_hidden = [32] batch_size = n_band model_path = './pretrain-model-COIL20/model.ckpt' ft_path = './pretrain-model-COIL20/model.ckpt' logs_path = './pretrain-model-COIL20/logs' batch_size_test = n_band iter_ft = 0
img_path = root + im_ + '.mat' gt_path = root + gt_ + '.mat' # # gt_path = 'F:\Python\HSI_Files\Indian_pines_gt.mat' # img_path = 'F:\Python\HSI_Files\Indian_pines_corrected.mat' # # gt_path = 'F:\Python\HSI_Files\Pavia_gt.mat' # img_path = 'F:\Python\HSI_Files\Pavia.mat' print(img_path) p = Processor() img, gt = p.prepare_data(img_path, gt_path) n_row, n_clo, n_bands = img.shape print('img=', img.shape) # pca_img = p.pca_transform(n_comp, img.reshape(n_row * n_clo, n_bands)).reshape(n_row, n_clo, n_comp) X, y = p.get_correct(img, gt) print(X.shape) ''' ___________________________________________________________________ Data pre-processing ''' # remove these samples with small numbers classes = np.unique(y) print('size:', X.shape, 'n_classes:', classes.shape[0]) for c in classes: if np.nonzero(y == c)[0].shape[0] < 10: X = np.delete(X, np.nonzero(y == c), axis=0) y = np.delete(y, np.nonzero(y == c)) y = p.standardize_label(y) X = MinMaxScaler().fit_transform(X)
# im_, gt_ = 'KSC', 'KSC_gt' im_, gt_ = 'wuhanTM', 'wuhanTM_gt' # img_path = root + im_ + '.mat' gt_path = root + gt_ + '.mat' print(img_path) p = Processor() img, gt = p.prepare_data(img_path, gt_path) n_row, n_clo, n_bands = img.shape print('img=', img.shape) if n_bands > 20: pca_img = p.pca_transform(20, img.reshape(n_row * n_clo, n_bands)).reshape(n_row, n_clo, 20) X, y = p.get_correct(pca_img, gt) else: X, y = p.get_correct(img, gt) print(X.shape) ''' ___________________________________________________________________ Data pre-processing ''' # remove these samples with small numbers classes = np.unique(y) print('size:', X.shape, 'n_classes:', classes.shape[0]) for c in classes: if np.nonzero(y == c)[0].shape[0] < 10: X = np.delete(X, np.nonzero(y == c), axis=0)
# im_, gt_ = 'Pavia', 'Pavia_gt' # im_, gt_ = 'PaviaU', 'PaviaU_gt' # im_, gt_ = 'Salinas_corrected', 'Salinas_gt' # im_, gt_ = 'Botswana', 'Botswana_gt' # im_, gt_ = 'KSC', 'KSC_gt' img_path = root + im_ + '.mat' gt_path = root + gt_ + '.mat' print(img_path) p = Processor() img, gt = p.prepare_data(img_path, gt_path) n_row, n_column, n_band = img.shape X_img = minmax_scale(img.reshape(n_row * n_column, n_band).transpose()) X_img = X_img.transpose().reshape((n_row, n_column, n_band)) img_correct, gt_correct = p.get_correct(X_img, gt) gt_correct = p.standardize_label(gt_correct) X_img_2D = X_img.reshape(n_row * n_column, n_band) X_img_2D = minmax_scale(X_img_2D.transpose()).transpose() n_selected_band = 5 algorithm = [ EGCSR_BS_Clustering(n_selected_band, regu_coef=1e4, n_neighbors=3, ro=0.8), EGCSR_BS_Ranking(n_selected_band, regu_coef=1e4, n_neighbors=3, ro=0.8) ] alg_key = ['EGCSR-Clustering', 'EGCSR-Ranking'] for i in range(algorithm.__len__()):
# im_, gt_ = 'SalinasA_corrected', 'SalinasA_gt' # im_, gt_ = 'Indian_pines_corrected', 'Indian_pines_gt' # im_, gt_ = 'Pavia', 'Pavia_gt' im_, gt_ = 'KSC', 'KSC_gt' img_path = root + im_ + '.mat' gt_path = root + gt_ + '.mat' print(img_path) p = Processor() img, gt = p.prepare_data(img_path, gt_path) n_row, n_column, n_band = img.shape X_img = minmax_scale(img.reshape(n_row * n_column, n_band)).reshape( (n_row, n_column, n_band)) img_correct, gt_correct = p.get_correct(X_img, gt) train_inx, test_idx = p.get_tr_tx_index(gt_correct, test_size=0.4) # img_train = np.transpose(img_train, axes=(2, 0, 1)) # Img.transpose() # img_train = np.reshape(img_train, (n_band, n_row, n_column, 1)) # x_input = img.reshape(n_row * n_column, n_band) model_path = './pretrain-model-COIL20/model.ckpt' n_select_band = 20 spabs = SpaBS(n_select_band) X_new = spabs.predict(X_img) # 选出每个类中的代表波段 X_new, _ = p.get_correct(X_new, gt) # 带入没有压缩的数据 score = eval_band(X_new, gt_correct, train_inx, test_idx) # 进行评价
# im_, gt_ = 'Pavia', 'Pavia_gt' # im_, gt_ = 'Botswana', 'Botswana_gt' # im_, gt_ = 'KSC', 'KSC_gt' img_path = root + im_ + '.mat' gt_path = root + gt_ + '.mat' print(img_path) p = Processor() img, gt = p.prepare_data(img_path, gt_path) # Img, Label = Img[:256, :, :], Label[:256, :] n_row, n_column, n_band = img.shape X_img = minmax_scale(img.reshape(n_row * n_column, n_band)).reshape( (n_row, n_column, n_band)) X_img_2D = X_img.reshape(n_row * n_column, n_band) img_correct, gt_correct = p.get_correct(X_img, gt) gt_correct = p.standardize_label(gt_correct) train_inx, test_idx = p.get_tr_tx_index(gt_correct, test_size=0.4) n_input = [n_row, n_column] kernel_size = [7] n_hidden = [32] batch_size = n_band model_path = './pretrain-model-COIL20/model.ckpt' ft_path = './pretrain-model-COIL20/model.ckpt' logs_path = './pretrain-model-COIL20/logs' batch_size_test = n_band iter_ft = 0 display_step = 1