示例#1
0
import image_operations as operations
import feature_extraction as extraction
from skimage import feature, color, exposure
import feature_validation as validation

training_images, training_labels, training_classes = data_loading.loadTrainingImagesPoleNumbersAndClasses(
)
size = 100

print("resizing...")
resized = util.loading_map(lambda x: operations.cropAndResize(x, 0, size),
                           training_images)
print("hsv...")
hsv = util.loading_map(color.rgb2hsv, resized)
print("grayscaling...")
grayscaled = util.loading_map(color.rgb2gray, resized)

print("colors")
colors = util.loading_map(
    lambda x: extraction.split_image_features(
        extraction.calculateColorFeatures, 7, x), hsv)

n_folds = 5

print("evaluating colors")
model = DistanceModel()
#from sklearn.linear_model import LogisticRegression
#model = LogisticRegression(solver = 'lbfgs', multi_class = 'multinomial')
validation.validate_feature(colors, training_labels, training_classes, model,
                            n_folds, False, False, True, True)
print('\a')
model = Pipeline([("standard scaler", StandardScaler()),
                  ("logistic regression",
                   LogisticRegression(solver='lbfgs',
                                      multi_class='multinomial'))])

for cpb in range(2, 11):
    ppc = int(100 / cpb)
    print("hog_8_", ppc, "_", cpb, " features")
    hog = util.loading_map(
        lambda x: feature.hog(x,
                              orientations=8,
                              pixels_per_cell=(ppc, ppc),
                              cells_per_block=(cpb, cpb),
                              normalise=True), grayscaled)
    print(numpy.shape(hog))
    validation.validate_feature(hog, labels, classes, model, n_folds, False,
                                False, True, True)

#hog_8_12_8 is optimal, optimizing orientations:
for orientations in range(10, 11):
    print("hog_", orientations, "_12_8 features")
    hog = util.loading_map(
        lambda x: feature.hog(x,
                              orientations=orientations,
                              pixels_per_cell=(12, 12),
                              cells_per_block=(8, 8),
                              normalise=True), grayscaled)
    print(numpy.shape(hog))
    validation.validate_feature(hog, labels, classes, model, n_folds, False,
                                False, True, True)

#retry optimizing cpb using 6 orientations
示例#3
0
model = Pipeline([
    ("standard scaler", StandardScaler()),
    #("Robust Scaler", RobustScaler()),
    #("principal component analysis", PCA(500)), #<- appears to reduce efficiency
    #("lda projection", lda.LDA(n_components = 80)),
    #("gaussian random projection", random_projection.GaussianRandomProjection(n_components = 100)),
    #("sparse random projection", random_projection.SparseRandomProjection(n_components = 500)),
    ("logistic regression",
     LogisticRegression(solver='lbfgs', multi_class='multinomial'))
    #("Random forest classifier", RandomForestClassifier(n_estimators = 200)),
    #("svm", svm.SVC(kernel = "sigmoid", C = 1000, gamma = 0.0001, probability = True))
])

print("Evaluating brightness features")
validation.validate_feature(brightness, labels, classes, model, n_folds, False,
                            False, True)
print('\a')
print("Evaluating hsv features")
validation.validate_feature(hsv_features, labels, classes, model, n_folds,
                            False, False, True, True)
print("Evaluating luv features")
validation.validate_feature(luv_features, labels, classes, model, n_folds,
                            False, False, True, True)
print("Evaluating hed features")
validation.validate_feature(hed_features, labels, classes, model, n_folds,
                            False, False, True, True)
print("Evaluating cie features")
validation.validate_feature(cie_features, labels, classes, model, n_folds,
                            False, False, True, True)
print("Evaluating HOG features")
#validation.validate_feature(hog, labels, classes, model, n_folds, False, False, True, True)
hsv = util.loading_map(color.rgb2hsv, resized)
print("luv...")
luv = util.loading_map(color.rgb2luv, resized)

model = Pipeline([("standard scaler", StandardScaler()),
                  ("logistic regression",
                   LogisticRegression(solver='lbfgs',
                                      multi_class='multinomial'))])

n_folds = 10

for i in range(1, 14, 2):
    print("rgb", i)
    rgb_f = util.loading_map(lambda x: extraction.pixel_features(x, i),
                             resized)
    validation.validate_feature(rgb_f, labels, classes, model, n_folds, False,
                                False, True, True)

for i in range(1, 14, 2):
    print("hsv", i)
    hsv_f = util.loading_map(lambda x: extraction.pixel_features(x, i), hsv)
    validation.validate_feature(hsv_f, labels, classes, model, n_folds, False,
                                False, True, True)

for i in range(1, 14, 2):
    print("luv", i)
    luv_f = util.loading_map(lambda x: extraction.pixel_features(x, i), luv)
    validation.validate_feature(luv_f, labels, classes, model, n_folds, False,
                                False, True, True)

#With STD
print("rgb 11 + std")
示例#5
0
    feature_extraction.calcHOGWrapper(img,
                                      orient=8,
                                      pixel_per_cell=5,
                                      nr_of_cells_per_block=2)
    for img in thumbsGray
]

features = HOGGray

print("Build random forest with gray features")

n_folds = 5
#iterate over multiple tree numbers 100->400
for nr_of_trees in range(100, 400, 50):
    print(nr_of_trees)
    model = Pipeline([("Random forest classifier",
                       RandomForestClassifier(n_estimators=nr_of_trees,
                                              class_weight='balanced',
                                              n_jobs=4))])
    print("Validating Features")
    validation.validate_feature(features, labels, classes, model, n_folds,
                                True, True, True, True)

    model = Pipeline([("Extreme forest classifier",
                       ExtraTreesClassifier(n_estimators=nr_of_trees,
                                            class_weight='balanced',
                                            n_jobs=4))])
    print("Validating Features")
    validation.validate_feature(features, labels, classes, model, n_folds,
                                True, True, True, True)
示例#6
0


hybrid_bright_hed_hog_luv = numpy.concatenate((brightness, hed_features, hog, luv_features), 1)


n_folds=5
print("Build random forest")
nr_of_trees=500
model = Pipeline([
    ("standard scaler", StandardScaler()),   
     ("Random forest classifier", RandomForestClassifier(n_estimators=nr_of_trees,class_weight='balanced',n_jobs=4))
    ])

print("Evaluating brightness+hed+hog+luv")
validation.validate_feature(hybrid_bright_hed_hog_luv, labels, classes, model, n_folds, False, False, True, True)

print('\a')
n_folds=5
print("Build extreme forest")
nr_of_trees=500
model = Pipeline([
    ("standard scaler", StandardScaler()),   
     ("Random forest classifier", ExtraTreesClassifier(n_estimators=nr_of_trees,class_weight='balanced',n_jobs=4))
    ])

print("Evaluating brightness+hed+hog+luv")
validation.validate_feature(hybrid_bright_hed_hog_luv, labels, classes, model, n_folds, False, False, True, True)

print('\a')
示例#7
0
                          cells_per_block=(8, 8),
                          normalise=True), grayscaled)
print("corner features")
corners = util.loading_map(
    lambda x: extraction.pixel_features(
        numpy.sqrt(feature.corner_shi_tomasi(x, sigma=8)), 8), grayscaled)

n_folds = 10

model = Pipeline([("standard scaler", StandardScaler()),
                  ("logistic regression",
                   LogisticRegression(solver='lbfgs',
                                      multi_class='multinomial'))])

print("Evaluating brightness features")
validation.validate_feature(brightness, labels, classes, model, n_folds, False,
                            False, True, True)
print("Evaluating luv features")
validation.validate_feature(luv_features, labels, classes, model, n_folds,
                            False, False, True, True)
print("Evaluating hog features")
validation.validate_feature(hog, labels, classes, model, n_folds, False, False,
                            True, True)
print("Evaluating corner features")
validation.validate_feature(corners, labels, classes, model, n_folds, False,
                            False, True, True)
print("Evaluating HSV_11_std features")
validation.validate_feature(numpy.array(hsv_11_std), labels, classes, model,
                            n_folds, False, False, True, True)

#we combine the 2 best ones
hog_hs = numpy.concatenate((hog, hsv_11_std), 1)