Esempio n. 1
0
def report_two_output_accuracy(X, y_fine, y_coarse, prefix_string='2output hierarchy'):
    Y_fine = np_utils.to_categorical(y_fine, nb_classes_fine)
    Y_coarse = np_utils.to_categorical(y_coarse, nb_classes_coarse)
    
    Y = np.concatenate((Y_coarse, Y_fine), axis=1)

    # Test the model
    Y_predict_dict = model.predict({'input':X}, batch_size=batch_size, verbose=1)

    Y_predict_fine = Y_predict_dict['output_fine']
    Y_predict_coarse = Y_predict_dict['output_coarse']

    Y_predict = np.concatenate((Y_predict_coarse, Y_predict_fine), axis=1)

    # Convert floating point vector to a clean binary vector with only two 1's
    Y_predict_clean = clean_hierarchy_vec(Y_predict)
    
    accuracy, acc_coarse, acc_fine = accuracy_hierarchy(Y_predict_clean, Y)
    print("%s accuracy: %f" % (prefix_string, accuracy))
    print("%s coarse accuracy: %f" % (prefix_string, acc_coarse))
    print("%s fine accuracy: %f" % (prefix_string, acc_fine))
Esempio n. 2
0
    Y_train_coarse = np_utils.to_categorical(y_train_coarse, nb_classes_coarse)
    Y_test_fine = np_utils.to_categorical(y_test_fine, nb_classes_fine)
    Y_test_coarse = np_utils.to_categorical(y_test_coarse, nb_classes_coarse)
    
    Y_train = np.concatenate((Y_train_coarse, Y_train_fine), axis=1)
    Y_test = np.concatenate((Y_test_coarse, Y_test_fine), axis=1)

    # Test the model
    Y_predict_test = model.predict({'input':X_test}, batch_size=batch_size, verbose=1)['output']
    Y_predict_train = model.predict({'input':X_train}, batch_size=batch_size, verbose=1)['output']

    # Convert floating point vector to a clean binary vector with only two 1's
    Y_predict_test_clean = clean_hierarchy_vec(Y_predict_test)
    Y_predict_train_clean = clean_hierarchy_vec(Y_predict_train)
    
    test_accuracy, test_acc_coarse, test_acc_fine = accuracy_hierarchy(Y_predict_test_clean, Y_test)
    print("hierarchy test accuracy: %f" % test_accuracy)
    print("hierarchy test coarse accuracy: %f" % test_acc_coarse)
    print("hierarchy test fine accuracy: %f" % test_acc_fine)
    
    train_accuracy, train_acc_coarse, train_acc_fine = accuracy_hierarchy(Y_predict_train_clean, Y_train)
    print("hierarchy train accuracy: %f" % train_accuracy)
    print("hierarchy train coarse accuracy: %f" % train_acc_coarse)
    print("hierarchy train fine accuracy: %f" % train_acc_fine)
elif '2output' in model_name or 'keras_cifar100' in model_name:
    # Load and format data
    (X_train, y_train_fine), (X_test, y_test_fine) = cifar100.load_data(label_mode='fine')
    (_, y_train_coarse), (_, y_test_coarse) = cifar100.load_data(label_mode='coarse')

    X_train = X_train.astype('float32')
    X_test = X_test.astype('float32')