Пример #1
0
    pred_test = model_ResNeXt.predict(
        x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2],
                       x_test.shape[3], 1)).argmax(axis=1)

    collections.Counter(pred_test)

    gt_test = gt[test_indices] - 1

    overall_acc = metrics.accuracy_score(pred_test, gt_test[:-VAL_SIZE])
    confusion_matrix = metrics.confusion_matrix(pred_test, gt_test[:-VAL_SIZE])
    each_acc, average_acc = averageAccuracy.AA_andEachClassAccuracy(
        confusion_matrix)
    kappa = metrics.cohen_kappa_score(pred_test, gt_test[:-VAL_SIZE])
    KAPPA_3D_ResNeXt.append(kappa)
    OA_3D_ResNeXt.append(overall_acc)
    AA_3D_ResNeXt.append(average_acc)
    TRAINING_TIME_3D_ResNeXt.append(toc6 - tic6)
    TESTING_TIME_3D_ResNeXt.append(toc7 - tic7)
    ELEMENT_ACC_3D_ResNeXt[index_iter, :] = each_acc

    print("3D ResNeXt finished.")
    print("# %d Iteration" % (index_iter + 1))

# save records
modelStatsRecord.outputStats(
    KAPPA_3D_ResNeXt, OA_3D_ResNeXt, AA_3D_ResNeXt, ELEMENT_ACC_3D_ResNeXt,
    TRAINING_TIME_3D_ResNeXt, TESTING_TIME_3D_ResNeXt, history_3d_ResNeXt,
    loss_and_metrics, CATEGORY, './records/UP_train_3D_ResNeXt_4_1_5_60_1.txt',
    './records/UP_train_element_3D_ResNeXt_4_1_5_60_1.txt')
Пример #2
0
    pred_test_res4 = model_res4_SS_BN.predict(
        x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2],
                       x_test.shape[3], 1)).argmax(axis=1)
    collections.Counter(pred_test_res4)
    gt_test = gt[test_indices] - 1
    overall_acc_res4 = metrics.accuracy_score(pred_test_res4,
                                              gt_test[:-VAL_SIZE])
    confusion_matrix_res4 = metrics.confusion_matrix(pred_test_res4,
                                                     gt_test[:-VAL_SIZE])
    each_acc_res4, average_acc_res4 = averageAccuracy.AA_andEachClassAccuracy(
        confusion_matrix_res4)
    kappa = metrics.cohen_kappa_score(pred_test_res4, gt_test[:-VAL_SIZE])
    KAPPA_RES_SS4.append(kappa)
    OA_RES_SS4.append(overall_acc_res4)
    AA_RES_SS4.append(average_acc_res4)
    TRAINING_TIME_RES_SS4.append(toc6 - tic6)
    TESTING_TIME_RES_SS4.append(toc7 - tic7)
    ELEMENT_ACC_RES_SS4[index_iter, :] = each_acc_res4

    print("3D RESNET_SS4 without BN training finished.")
    print("# %d Iteration" % (index_iter + 1))

modelStatsRecord.outputStats(
    KAPPA_RES_SS4, OA_RES_SS4, AA_RES_SS4, ELEMENT_ACC_RES_SS4,
    TRAINING_TIME_RES_SS4, TESTING_TIME_RES_SS4, history_res4_SS,
    loss_and_metrics_res4_SS, CATEGORY,
    './drive/My Drive/Residual_HSI-Colab/SSRN/records/UP_mod_train_SS_10.txt',
    './drive/My Drive/Residual_HSI-Colab/records/UP_mod_train_SS_element_10.txt'
)
Пример #3
0
    print(history_res4_SS_BN.history.keys())

    pred_test_res4 = model_res4_SS_BN.predict(
        x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2],
                       x_test.shape[3], 1)).argmax(axis=1)
    collections.Counter(pred_test_res4)
    gt_test = gt[test_indices] - 1
    overall_acc_res4 = metrics.accuracy_score(pred_test_res4,
                                              gt_test[:-VAL_SIZE])
    confusion_matrix_res4 = metrics.confusion_matrix(pred_test_res4,
                                                     gt_test[:-VAL_SIZE])
    each_acc_res4, average_acc_res4 = averageAccuracy.AA_andEachClassAccuracy(
        confusion_matrix_res4)
    kappa = metrics.cohen_kappa_score(pred_test_res4, gt_test[:-VAL_SIZE])
    KAPPA_RES_SS4.append(kappa)
    OA_RES_SS4.append(overall_acc_res4)
    AA_RES_SS4.append(average_acc_res4)
    TRAINING_TIME_RES_SS4.append(toc6 - tic6)
    TESTING_TIME_RES_SS4.append(toc7 - tic7)
    ELEMENT_ACC_RES_SS4[index_iter, :] = each_acc_res4

    print("3D RESNET_SS4 without BN training finished.")
    print("# %d Iteration" % (index_iter + 1))

modelStatsRecord.outputStats(
    KAPPA_RES_SS4, OA_RES_SS4, AA_RES_SS4, ELEMENT_ACC_RES_SS4,
    TRAINING_TIME_RES_SS4, TESTING_TIME_RES_SS4, history_res4_SS_BN,
    loss_and_metrics_res4_SS_BN, CATEGORY,
    '/home/zilong/SSRN/records/IN_train_SS_10.txt',
    '/home/zilong/SSRN/records/IN_train_SS_element_10.txt')
    # 跟踪值出现的次数
    collections.Counter(pred_test)

    gt_test = gt[test_indices] - 1
    # print(len(gt_test))
    # 8194
    # 这是测试集,验证和测试还没有分开
    overall_acc = metrics.accuracy_score(pred_test, gt_test[:-VAL_SIZE])
    confusion_matrix = metrics.confusion_matrix(pred_test, gt_test[:-VAL_SIZE])
    each_acc, average_acc = averageAccuracy.AA_andEachClassAccuracy(confusion_matrix)
    kappa = metrics.cohen_kappa_score(pred_test, gt_test[:-VAL_SIZE])
    KAPPA_3D_MSDNet.append(kappa)
    OA_3D_MSDNet.append(overall_acc)
    AA_3D_MSDNet.append(average_acc)
    TRAINING_TIME_3D_MSDNet.append(toc6 - tic6)
    TESTING_TIME_3D_MSDNet.append(toc7 - tic7)
    ELEMENT_ACC_3D_MSDNet[index_iter, :] = each_acc

    # 绘制acc-loss曲线
    history.loss_plot('epoch')

    print("3D MSDNet finished.")
    print("# %d Iteration" % (index_iter + 1))

# 自定义输出类
modelStatsRecord.outputStats(KAPPA_3D_MSDNet, OA_3D_MSDNet, AA_3D_MSDNet, ELEMENT_ACC_3D_MSDNet,
                             TRAINING_TIME_3D_MSDNet, TESTING_TIME_3D_MSDNet,
                             history_3d_MSDNet, loss_and_metrics, CATEGORY,
                             'F:/transfer code/Tensorflow  Learning/3D-MSDNet/records-botswana-13-514-5/IN_train_3D.txt',
                             'F:/transfer code/Tensorflow  Learning/3D-MSDNet/records-botswana-13-514-5/IN_train_3D_element.txt')
Пример #5
0
    print('3D DenseNet Test accuracy:', loss_and_metrics[1])

    pred_test = model_densenet.predict(
        x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2],
                       x_test.shape[3], 1)).argmax(axis=1)

    collections.Counter(pred_test)

    gt_test = gt[test_indices] - 1

    overall_acc = metrics.accuracy_score(pred_test, gt_test[:-VAL_SIZE])
    confusion_matrix = metrics.confusion_matrix(pred_test, gt_test[:-VAL_SIZE])
    each_acc, average_acc = averageAccuracy.AA_andEachClassAccuracy(
        confusion_matrix)
    kappa = metrics.cohen_kappa_score(pred_test, gt_test[:-VAL_SIZE])
    KAPPA_3D_DenseNet.append(kappa)
    OA_3D_DenseNet.append(overall_acc)
    AA_3D_DenseNet.append(average_acc)
    TRAINING_TIME_3D_DenseNet.append(toc6 - tic6)
    TESTING_TIME_3D_DenseNet.append(toc7 - tic7)
    ELEMENT_ACC_3D_DenseNet[index_iter, :] = each_acc

    print("3D DenseNet finished.")
    print("# %d Iteration" % (index_iter + 1))

modelStatsRecord.outputStats(
    KAPPA_3D_DenseNet, OA_3D_DenseNet, AA_3D_DenseNet, ELEMENT_ACC_3D_DenseNet,
    TRAINING_TIME_3D_DenseNet, TESTING_TIME_3D_DenseNet, history_3d_densenet,
    loss_and_metrics, CATEGORY, './records/UP_train_RGCSA_2_1_7_100_1.txt',
    './records/UP_train_element_RGCSA_2_1_7_100_1.txt')
Пример #6
0
    print('3D MSDNet  Test accuracy:', loss_and_metrics_3d_MSDNet[1])

    print(history_3d_MSDNet.history.keys())

    pred_test = model_MSDNet.predict(
        x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2], x_test.shape[3], 1)).argmax(axis=1)
    collections.Counter(pred_test)
    gt_test = gt[test_indices] - 1
    overall_acc = metrics.accuracy_score(pred_test, gt_test[:-VAL_SIZE])
    confusion_matrix = metrics.confusion_matrix(pred_test, gt_test[:-VAL_SIZE])
    each_acc, average_acc = averageAccuracy.AA_andEachClassAccuracy(confusion_matrix)
    kappa = metrics.cohen_kappa_score(pred_test, gt_test[:-VAL_SIZE])
    KAPPA_3D_MSDNet.append(kappa)
    OA_3D_MSDNet.append(overall_acc)
    AA_3D_MSDNet.append(average_acc)
    TRAINING_TIME_3D_MSDNet.append(toc6 - tic6)
    TESTING_TIME_3D_MSDNet.append(toc7 - tic7)
    ELEMENT_ACC_3D_MSDNet[index_iter, :] = each_acc

    # 绘制acc-loss曲线
    history.loss_plot('epoch')

    print("3D MSDNet  finished.")
    print("# %d Iteration" % (index_iter + 1))

modelStatsRecord.outputStats(KAPPA_3D_MSDNet, OA_3D_MSDNet, AA_3D_MSDNet, ELEMENT_ACC_3D_MSDNet,
                             TRAINING_TIME_3D_MSDNet, TESTING_TIME_3D_MSDNet,
                             history_3d_MSDNet, loss_and_metrics_3d_MSDNet, CATEGORY,
                             'F:/transfer code/Tensorflow  Learning/3D-MSDNet/records-up-13-217-7-1/UP_train_3D_10.txt',
                             'F:/transfer code/Tensorflow  Learning/3D-MSDNet/records-up-13-217-7-1/UP_train_3D_element_10.txt')
Пример #7
0
    # 跟踪值出现的次数
    collections.Counter(pred_test)

    gt_test = gt[test_indices] - 1
    # print(len(gt_test))
    # 8194
    # 这是测试集,验证和测试还没有分开
    overall_acc = metrics.accuracy_score(pred_test, gt_test[:-VAL_SIZE])
    confusion_matrix = metrics.confusion_matrix(pred_test, gt_test[:-VAL_SIZE])
    each_acc, average_acc = averageAccuracy.AA_andEachClassAccuracy(confusion_matrix)
    kappa = metrics.cohen_kappa_score(pred_test, gt_test[:-VAL_SIZE])
    KAPPA_3D_HSICNNet.append(kappa)
    OA_3D_HSICNNet.append(overall_acc)
    AA_3D_HSICNNet.append(average_acc)
    TRAINING_TIME_3D_HSICNNet.append(toc6 - tic6)
    TESTING_TIME_3D_HSICNNet.append(toc7 - tic7)
    ELEMENT_ACC_3D_HSICNNet[index_iter, :] = each_acc

    # 绘制acc-loss曲线
    history.loss_plot('epoch')

    print("3D HSICNNet finished.")
    print("# %d Iteration" % (index_iter + 1))

# 自定义输出类
modelStatsRecord.outputStats(KAPPA_3D_HSICNNet, OA_3D_HSICNNet, AA_3D_HSICNNet, ELEMENT_ACC_3D_HSICNNet,
                             TRAINING_TIME_3D_HSICNNet, TESTING_TIME_3D_HSICNNet,
                             history_3d_HSICNNet, loss_and_metrics, CATEGORY,
                             'F:/transfer code/Tensorflow  Learning/SKNet/records-in-densenet-23-514/IN_train_3D.txt',
                             'F:/transfer code/Tensorflow  Learning/SKNet/records-in-densenet-23-514/IN_train_3D_element.txt')
Пример #8
0
    collections.Counter(pred_test_conv)

    gt_test = gt[test_indices] - 1
    overall_acc_conv = metrics.accuracy_score(pred_test_conv, gt_test)
    confusion_matrix_conv = metrics.confusion_matrix(pred_test_conv, gt_test)
    each_acc_conv, average_acc_conv = averageAccuracy.AA_andEachClassAccuracy(
        confusion_matrix_conv)
    kappa = metrics.cohen_kappa_score(pred_test_conv, gt_test)
    KAPPA_CONV.append(kappa)
    OA_CONV.append(overall_acc_conv)
    AA_CONV.append(average_acc_conv)
    TRAINING_TIME_CONV.append(toc2 - tic2)
    TESTING_TIME_CONV.append(toc3 - tic3)
    ELEMENT_ACC_CONV[index_iter, :] = each_acc_conv

    print("Overall Accuracy:", overall_acc_conv)
    print("Confusion matrix:", confusion_matrix_conv)
    print("Average Accuracy:", average_acc_conv)

    print("Each Class Accuracies are listed as follows:")
    for idx, acc in enumerate(each_acc_conv):
        print("Class %d : %.3e" % (idx + 1, acc))

    print("3D CONV training finished.")

modelStatsRecord.outputStats(
    KAPPA_CONV, OA_CONV, AA_CONV, ELEMENT_ACC_CONV, TRAINING_TIME_CONV,
    TESTING_TIME_CONV, history_conv, loss_and_metrics, CATEGORY,
    'D:/Tensorflow  Learning/SSRN-master/SSRN-master/Real3D_conv/record_3D_CONV_IN.txt',
    'D:/Tensorflow  Learning/SSRN-master/SSRN-master/Real3D_conv/element_acc_3D_CONV_IN.txt'
)
Пример #9
0
    collections.Counter(pred_test_res4)
    gt_test = gt[test_indices] - 1
    overall_acc_res4 = metrics.accuracy_score(pred_test_res4, gt_test)
    confusion_matrix_res4 = metrics.confusion_matrix(pred_test_res4, gt_test)
    each_acc_res4, average_acc_res4 = averageAccuracy.AA_andEachClassAccuracy(
        confusion_matrix_res4)
    kappa = metrics.cohen_kappa_score(pred_test_res4, gt_test)
    KAPPA_RES_SS4.append(kappa)
    OA_RES_SS4.append(overall_acc_res4)
    AA_RES_SS4.append(average_acc_res4)
    TRAINING_TIME_RES_SS4.append(toc6 - tic6)
    TESTING_TIME_RES_SS4.append(toc7 - tic7)
    print(len(each_acc_res4))
    ELEMENT_ACC_RES_SS4[index_iter, :] = each_acc_res4

    # sio.savemat('./pred_gt' + str(DataSetName) + '_' + str((index_iter + 1)) + '.mat', {'train_indices':train_indices,'test_indices':test_indices,'pred':pred_test_res4,'gt':gt_test})

    print("3D RESNET_SS4 without BN training finished.")

# sio.savemat('./pred_gt' + str(DataSetName) + '_' + str((index_iter + 1)) + '.mat', {'train_indices':train_indices,'test_indices':test_indices,'pred':pred_test_res4,'gt':gt_test})
modelStatsRecord.outputStats(
    KAPPA_RES_SS4, OA_RES_SS4, AA_RES_SS4, ELEMENT_ACC_RES_SS4,
    TRAINING_TIME_RES_SS4, TESTING_TIME_RES_SS4, history_res4_SS_BN,
    loss_and_metrics_res4_SS_BN, CATEGORY,
    'records/' + str(save_name) + '_pure_cnn.txt',
    'records/' + str(save_name) + '_train_SS_element_10.txt')
# sendMsg("cnn finish")
print(np.mean(OA_RES_SS4) * 100, np.std(OA_RES_SS4) * 100)
print(np.mean(AA_RES_SS4) * 100, np.std(AA_RES_SS4) * 100)
print(np.mean(KAPPA_RES_SS4) * 100, np.std(KAPPA_RES_SS4) * 100)
Пример #10
0
    each_acc, average_acc = averageAccuracy.AA_andEachClassAccuracy(
        confusion_matrix)
    kappa = metrics.cohen_kappa_score(pred_test, gt_test[:-VAL_SIZE])
    KAPPA_3D_DenseNet.append(kappa)
    OA_3D_DenseNet.append(overall_acc)
    AA_3D_DenseNet.append(average_acc)
    TRAINING_TIME_3D_DenseNet.append(toc6 - tic6)
    TESTING_TIME_3D_DenseNet.append(toc7 - tic7)
    ELEMENT_ACC_3D_DenseNet[index_iter, :] = each_acc

    print("3D DenseNet finished.")
    print("# %d Iteration" % (index_iter + 1))

# 自定义输出类
# modelStatsRecord.outputStats(KAPPA_3D_DenseNet, OA_3D_DenseNet, AA_3D_DenseNet, ELEMENT_ACC_3D_DenseNet,
#                              TRAINING_TIME_3D_DenseNet, TESTING_TIME_3D_DenseNet,
#                              history_3d_densenet, loss_and_metrics, CATEGORY,
#                              './records/IN_train_3D_ResneXt_Dual_loss_3_1_6_80_3.txt',
#                              './records/IN_train_element_3D_ResneXt_Dual_loss_3_1_6_80_3.txt')
modelStatsRecord.outputStats(
    KAPPA_3D_DenseNet, OA_3D_DenseNet, AA_3D_DenseNet, ELEMENT_ACC_3D_DenseNet,
    TRAINING_TIME_3D_DenseNet, TESTING_TIME_3D_DenseNet, history_3d_densenet,
    loss_and_metrics, CATEGORY,
    './records/KSC_train_ResNeXt_TwoStepAttention_5_1_4_60_1.txt',
    './records/KSC_train_element_ResNeXt_TwoStepAttention_5_1_4_60_1.txt')
# modelStatsRecord.outputStats(KAPPA_3D_DenseNet, OA_3D_DenseNet, AA_3D_DenseNet, ELEMENT_ACC_3D_DenseNet,
#                              TRAINING_TIME_3D_DenseNet, TESTING_TIME_3D_DenseNet,
#                              history_3d_densenet, loss_and_metrics, CATEGORY,
#                              './records/IN_train_3D_SSRN_6_1_3_100_1.txt',
#                              './records/IN_train_element_3D_SSRN_6_1_3_100_1.txt')
Пример #11
0
collections.Counter(pre_test_pro)
# np.save('/home/asdf/Documents/juyan/SSRN-master/juyan/result/pavia.npy', pre_test_pro)
gt_test = gt[test_indices] - 1
overall_acc_res4 = metrics.accuracy_score(pre_test_pro[test_indices], gt_test)
confusion_matrix_res4 = metrics.confusion_matrix(pre_test_pro[test_indices], gt_test)
each_acc_res4, average_acc_res4 = averageAccuracy.AA_andEachClassAccuracy(confusion_matrix_res4)
kappa = metrics.cohen_kappa_score(pre_test_pro[test_indices], gt_test)
KAPPA_RES_SS4.append(kappa)
OA_RES_SS4.append(overall_acc_res4)
AA_RES_SS4.append(average_acc_res4)

ELEMENT_ACC_RES_SS4[0, :] = each_acc_res4

print("3D RESNET_SS4 without BN training finished.")
# print("# %d Iteration" % (index_iter + 1))

modelStatsRecord.outputStats(KAPPA_RES_SS4, OA_RES_SS4, AA_RES_SS4, ELEMENT_ACC_RES_SS4, CATEGORY,
                         '/home/asdf/Documents/juyan/SSRN-master/juyan/PC_train_SS_10.txt',
                         '/home/asdf/Documents/juyan/SSRN-master/juyan/PC_train_SS_element_10.txt')

# label_mat = np.zeros((512, 271), dtype=np.uint8)
# pre_label = pre_test_pro.argmax(axis=1)
# index = 0
# for ir in tqdm(range(whole_data.shape[0])):
#     for ic in range(whole_data.shape[1]):
#         label_mat[ir][ic] = pre_label[index]
#         index += 1
# np.save('/home/asdf/Documents/juyan/SSRN-master/juyan/result/SA_0712.npy', label_mat)


Пример #12
0
    print('3D DenseNet  Test time:', toc7 - tic7)

    print('3D DenseNet  Test score:', loss_and_metrics_3d_densenet[0])
    print('3D DenseNet  Test accuracy:', loss_and_metrics_3d_densenet[1])

    print(history_3d_densenet.history.keys())

    pred_test = model_densenet.predict(
        x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2], x_test.shape[3], 1)).argmax(axis=1)
    collections.Counter(pred_test)
    gt_test = gt[test_indices] - 1
    overall_acc = metrics.accuracy_score(pred_test, gt_test[:-VAL_SIZE])
    confusion_matrix = metrics.confusion_matrix(pred_test, gt_test[:-VAL_SIZE])
    each_acc, average_acc = averageAccuracy.AA_andEachClassAccuracy(confusion_matrix)
    kappa = metrics.cohen_kappa_score(pred_test, gt_test[:-VAL_SIZE])
    KAPPA_3D_DenseNet.append(kappa)
    OA_3D_DenseNet.append(overall_acc)
    AA_3D_DenseNet.append(average_acc)
    TRAINING_TIME_3D_DenseNet.append(toc6 - tic6)
    TESTING_TIME_3D_DenseNet.append(toc7 - tic7)
    ELEMENT_ACC_3D_DenseNet[index_iter, :] = each_acc

    print("3D DenseNet  finished.")
    print("# %d Iteration" % (index_iter + 1))

modelStatsRecord.outputStats(KAPPA_3D_DenseNet, OA_3D_DenseNet, AA_3D_DenseNet, ELEMENT_ACC_3D_DenseNet,
                             TRAINING_TIME_3D_DenseNet, TESTING_TIME_3D_DenseNet,
                             history_3d_densenet, loss_and_metrics_3d_densenet, CATEGORY,
                             'D:/Tensorflow  Learning/3D-DenseNet-Hyperspectral/records-up-3dcnn/UP_train_3D_10.txt',
                             'D:/Tensorflow  Learning/3D-DenseNet-Hyperspectral/records-up-3dcnn/UP_train_3D_element_10.txt')