Пример #1
0
def test_combined_classifier_prediction():
    eps = 4
    min_samples = 20
    theta = 20

    imgpath = "/home/tom/FullModel/PanoramaSmallX_1Y_15.png"

    SEM = scipy.misc.imread(imgpath, flatten=True)
    L = Localizer(eps, min_samples, theta)
    centroids = L.predict(SEM)

    ##
    ## Combined classifier
    ##

    settingsjson = "/home/tom/FullModel/settings.json"
    cc = combined_classifier(settingsjson)

    annotations_combined = cc.predict(SEM, centroids)

    #
    # Combined classifier with modules executed seperately
    #

    annotations = ["Not Classified" for i in range(len(centroids))]

    weights_path = "/home/tom/FullModel/models/InceptionV3_IncVsAll_NoInc.hdf5"
    model = "InceptionV3"
    window_size = [250, 250]

    FirstStage = classifier(model, 2, window_size, weights_path=weights_path)
    y_pred = FirstStage.predict(SEM, centroids)

    not_inc = []
    pos_not_inc = []
    threshold = 0.7
    for i in range(len(centroids)):
        if y_pred[i][0] > threshold:
            annotations[i] = "Inclusion"
        else:
            not_inc.append(centroids[i])
            pos_not_inc.append(i)

    weights_path = "/home/tom/FullModel/models/EERACN_SecondStage.hdf5"
    model = "EERACN"
    window_size = [50, 50]

    SecondStage = classifier(model, 4, window_size, weights_path=weights_path)
    y_pred = SecondStage.predict(SEM, not_inc)

    for i in range(len(not_inc)):
        if y_pred[i][0] > threshold:
            annotations[pos_not_inc[i]] = "Martensite"
        elif y_pred[i][1] > threshold:
            annotations[pos_not_inc[i]] = "Interface"
        elif y_pred[i][2] > threshold:
            annotations[pos_not_inc[i]] = "Notch"
        elif y_pred[i][3] > threshold:
            annotations[pos_not_inc[i]] = "Boundary"

    assert annotations == annotations_combined, "Classifier not correctly combined"
Пример #2
0
""" displays evaluation of the current models """
import sys
sys.path.append('../')
from encode_dataset import encoded_x_train_clr0, encoded_x_train_clr1, x_train
from encode_dataset import encoded_x_test_clr0, encoded_x_test_clr1, x_test
from encode_dataset import encoded_y_train_clr0, encoded_y_train_clr1, y_train, y_test
from models.auto_encoder import auto_encoder
from models.classifier import classifier


########################################################################################################################

print('Auto Encoder: ')
# auto_encode dataset (this also prints the evaluations of the model in the end)
auto_encoded_clr0, _ = auto_encoder(encoded_x_train_clr0, x_train, encoded_x_test_clr0, x_test, '0', False, True)
auto_encoded_clr1, _ = auto_encoder(encoded_x_train_clr1, x_train, encoded_x_test_clr1, x_test, '1', False, True)

print('\n')

print('Classifier: ')
# evaluate (this also prints) the Classifier model on the auto_encoded data
print('\tNo Clearance: ')
classifier(x_train, y_train, x_test, y_test, False, True)
print('\tClearance Level 0 Evaluation: ')
classifier(auto_encoded_clr0, encoded_y_train_clr0, auto_encoded_clr0, encoded_y_train_clr0, False, True)
print('\tClearance Level 1 Evaluation: ')
classifier(auto_encoded_clr1, encoded_y_train_clr1, auto_encoded_clr1, encoded_y_train_clr1, False, True)

########################################################################################################################
Пример #3
0
from models.results import calculate_results

np.seterr(divide='ignore', invalid='ignore')

# preprocess
features_gcd, labels_gcd = preprocess_german_credit()
features_glass, labels_glass = preprocess_glass()
features_covid, labels_covid = preprocess_covid()

# classifiers
rf_classifier = RandomForestClassifier(n_estimators=100)
ab_classifier = AdaBoostClassifier(n_estimators=100)
mlp_classifier = MLPClassifier(random_state=1, max_iter=300)

# ## random forest
test_labels_gcd_rf, y_pred_gcd_rf, delta_gcd_rf = classifier(
    features_gcd, labels_gcd, rf_classifier)
test_labels_glass_rf, y_pred_glass_rf, delta_glass_rf = classifier(
    features_glass, labels_glass, rf_classifier)
# test_labels_covid_rf, y_pred_covid_rf, delta_covid_rf = classifier(features_covid, labels_covid, rf_classifier)

## adaboost
test_labels_gcd_ab, y_pred_gcd_ab, delta_gcd_ab = classifier(
    features_gcd, labels_gcd, ab_classifier)
test_labels_glass_ab, y_pred_glass_ab, delta_glass_ab = classifier(
    features_glass, labels_glass, ab_classifier)

## multilayer perceptron
test_labels_gcd_mlp, y_pred_gcd_mlp, delta_gcd_mlp = classifier(
    features_gcd, labels_gcd, mlp_classifier)
test_labels_glass_mlp, y_pred_glass_mlp, delta_glass_mlp = classifier(
    features_glass, labels_glass, mlp_classifier)
Пример #4
0
    INPUT:
        array - numpy array
    OUTPUT:
        config - configuration to shuffle arrays of the same size
    """
    config = np.arange(array.shape[0])
    np.random.shuffle(config)
    return config


# create shuffle configuration for train and test datasets
train_config = get_shuffle_configuration(train_images)
test_config = get_shuffle_configuration(test_images)

# shuffle image and label train datasets symmetrically
train_images = train_images[train_config]
train_labels = train_labels[train_config]
# shuffle image and label test datasets symmetrically
test_images = test_images[test_config]
test_labels = test_labels[test_config]

########################################################################################################################
""" train Classifier model """

# THIS CALLS classifier.py

# train Classifier models
model = classifier(train_images, train_labels, test_images, test_labels)

########################################################################################################################
Пример #5
0
##

L = Localizer(eps, min_samples, theta)
centroids = L.predict(SEM)

annotations = ["Not Classified" for i in range(len(centroids))]

##
## Using InceptionV3 determine if the damage is an inclusion
##

weights_path = "/home/tom/FullModel/models/InceptionV3_IncVsAll_095.hdf5"
model = "InceptionV3"
window_size = [250, 250]

FirstStage = classifier(model, 2, window_size, weights_path=weights_path)
y_pred = FirstStage.predict(SEM, centroids)

not_inc = []
pos_not_inc = []
threshold = 0.7
for i in range(len(centroids)):
    if y_pred[i][0] > threshold:
        annotations[i] = "Inclusion {:0.2f}".format(y_pred[i][0])
    else:
        not_inc.append(centroids[i])
        pos_not_inc.append(i)

weights_path = "/home/tom/FullModel/models/EERACN_SecondStage.hdf5"
model = "EERACN"
window_size = [50, 50]