예제 #1
0
        print(time.time() - a)
        y_train, y_test = np.take(y,train_index,axis=0), np.take(y,test_index,axis=0)
        print("Size training set", len(X_train))
        print("Size test set", len(X_test))

        if fold_num==1:
            file.write("Size training set: %d\n" % len(X_train))
            file.write("Size test set: %d\n" % len(X_test))
            file.write("Class distribution:\n")
            file.write("Train;Test\n")
            dtrain = Counter(y_train)
            dtest = Counter(y_test)
            for i in range(IndianPines_Input.NUM_CLASSES):
                file.write(str(i)+";"+ str(dtrain[i]) + ";" + str(dtest[i]) + "\n")

        save_path,final_test_acc,conf_matrix = CNNTrain_2D.train_model(X_train, y_train, X_test, y_test, config)

        print(final_test_acc)
        accuracies.append(final_test_acc)
        file.write("Fold "+ str(fold_num) + ";" + "%.3f" % final_test_acc + "\n"  )


        # Clear memory
        del X_train, X_test, y_train, y_test

        fold_num+=1


    print(accuracies)
    mean_acc = np.asarray(accuracies,dtype=float).mean()
    file.write("Mean accuracy;" + "%.3f" % mean_acc + "\n\n" )
예제 #2
0
    print("Size test set", len(X_test))


    file.write("\n------------------\nResults for patch size " + str(patch_size) + ":\n")


    if validation_set:
        file.write("Class distribution:\n")
        file.write("#;Train;Validation;Test\n")
        dtrain = Counter(y_train)
        dval = Counter(y_val)
        dtest = Counter(y_test)
        for i in range(input.num_classes):
            file.write(str(i+1)+";" + str(dtrain[i]) + ";" + str(dval[i]) + ";" + str(dtest[i]) + "\n")
    #
        save_path, val_acc,  conf_matrix = CNNTrain_2D.train_model(X_train, y_train, X_val, y_val, config)
        # save_path, final_test_acc,  conf_matrix = CNNTrain_2D.train_model(X_test, y_test, X_train, y_train, config)

        # Clear memory
        del X_train, X_val, X_test, y_train, y_val, y_test

    else:
        file.write("Class distribution:\n")
        file.write("#;Train;Test\n")
        dtrain = Counter(y_train)
        dtest = Counter(y_test)
        for i in range(input.num_classes):
            file.write(str(i + 1) + ";" + str(dtrain[i]) + ";" + str(dtest[i]) + "\n")

        save_path, test_acc, conf_matrix = CNNTrain_2D.train_model(X_train, y_train, X_test, y_test, config)
예제 #3
0
                    file.write("Size test set: %d\n" % len(X_test))
                    file.write("Class distribution:\n")
                    file.write("Train;Test\n")
                    dtrain = Counter(y_train)
                    dtest = Counter(y_test)
                    for i in range(input.num_classes):
                        file.write(
                            str(i) + ";" + str(dtrain[i]) + ";" +
                            str(dtest[i]) + "\n")
                    file.write(
                        "Fold;Train acc; Test acc; Test Post acc;Kappa\n")

                print('Start training')
                t = time.time()

                save_path, test_acc, _ = CNNTrain_2D.train_model(
                    X_train, y_train, X_test, y_test, config)

                t = time.time() - t
                print(t)
                if fold_num == 1:
                    file.write("Time %0.3f\n" % t)

                print("Test accuracy:" + str(test_acc))

                raw, train_acc, test_acc = CV_Decoder.decode_cnn(
                    input, config, train_positions, test_positions, save_path)

                print("Train accuracy:" + str(train_acc))
                print("Test accuracy:" + str(test_acc))

                save_rgb(fold_dir + "outmap.png",