Skip to content
Snippets Groups Projects
Commit 0eaffca4 authored by Victor Demessance's avatar Victor Demessance
Browse files

[+] Add selective search process & scale factor threshold (computed from statistics and q(0.05)

parent 9b210359
No related branches found
No related tags found
1 merge request!5[+] Add global light classifier, different scale between light & sign, global...
This diff is collapsed.
0004, 515,801,541,851,0.9952337438579902,feux
0004, 337,552,503,867,0.9894110951509656,feux
0004, 407,326,424,364,0.9761382228356837,feux
0004, 354,334,364,382,0.9752702712687679,feux
0004, 425,602,458,648,0.9648697466863115,feux
0004, 406,791,450,815,0.7745253440252448,obligation
0004, 270,991,309,1000,0.7389454794497546,danger
0039, 155,326,394,566,0.9999999972515112,ceder
0039, 425,554,442,619,0.9999989042615994,feux
0039, 194,755,233,779,0.9999988602516906,feux
0039, 330,545,351,593,0.9937075776361155,feux
0039, 640,770,715,790,0.9933633032725986,feux
0039, 0,621,327,1000,0.9912733877457484,feux
0039, 496,500,641,650,0.9870504749448945,feux
0039, 246,536,284,568,0.9856224914127107,interdiction
0039, 281,621,294,642,0.9785043961881216,obligation
0039, 638,601,659,703,0.9738275396565923,feux
0039, 693,534,715,572,0.9721666109721353,feux
0039, 3,423,34,469,0.9613660899693652,feux
0039, 255,485,277,508,0.9554668828090723,ceder
0039, 158,751,191,770,0.9554464109950297,feux
0039, 441,558,510,675,0.9542978068908017,feux
0039, 368,572,405,605,0.7328675389698446,stop
0039, 248,592,274,614,0.7253960393445719,ceder
File added
No preview for this file type
......@@ -71,58 +71,67 @@ with open(output_file, "w") as f:
print(f"[DETECTION] Processing image {name}")
# 1. Extract rois from images with dynamic sliding window process
rois = []
rois = selective_search(image)
for roi in rois[:200]:
rois = []
rois_ss = selective_search(image)
for roi in rois_ss[:500]:
x0, y0, x1, y1 = roi
window = np.array(Image.fromarray(image[y0:y1, x0:x1]).resize(AVERAGE_SIZE))
# HOG features
hog_features = np.array(hog(rgb2gray(window), pixels_per_cell=(16, 16), cells_per_block=(2, 2), block_norm='L2-Hys')).flatten()
area = (int(x1) - int(x0) + 1) * (int(y1) - int(y0) + 1)
# HUE features
color_features = np.histogram(rgb2hsv(window)[:,:,0], bins=10, range=(0, 1), density=True)[0]
if area > AREA_THRESHOLD:
window = np.array(Image.fromarray(image[y0:y1, x0:x1]).resize(AVERAGE_SIZE))
# HOG features
hog_features = np.array(hog(rgb2gray(window), pixels_per_cell=(16, 16), cells_per_block=(2, 2), block_norm='L2-Hys')).flatten()
# Concatenate ROI features
roi_features = np.concatenate((hog_features, color_features)).reshape(1, -1)
# HUE features
color_features = np.histogram(rgb2hsv(window)[:,:,0], bins=10, range=(0, 1), density=True)[0]
# Concatenate ROI features
roi_features = np.concatenate((hog_features, color_features)).reshape(1, -1)
probas = {
"danger" : None,
"interdiction": None,
"obligation": None,
"stop": None,
"ceder": None,
}
for classe, classifier in classifiers.items():
if classe not in ["feux", "fvert", "frouge", "forange"]:
proba = classifier.predict_proba(roi_features)[0][1]
if proba > 0.7:
probas[classe] = proba
else:
probas[classe] = 0
probas = {
"danger" : None,
"interdiction": None,
"obligation": None,
"stop": None,
"ceder": None,
}
for classe, classifier in classifiers.items():
if classe not in ["feux", "fvert", "frouge", "forange"]:
proba = classifier.predict_proba(roi_features)[0][1]
if proba > 0.7:
probas[classe] = proba
else:
probas[classe] = 0
max_proba = 0
max_classe = "empty"
for classe, proba in probas.items():
if proba > max_proba:
max_proba = 0
max_classe = "empty"
for classe, proba in probas.items():
if proba > max_proba:
max_proba = proba
max_classe = classe
# Classificate if there is a light
proba = classifiers["feux"].predict_proba(roi_features)[0][1]
if proba > 0.95 and proba > max_proba:
max_proba = proba
max_classe = classe
# Classificate if there is a light
proba = classifiers["feux"].predict_proba(roi_features)[0][1]
if proba > 0.95 and proba > max_proba:
max_proba = proba
max_classe = "feux"
max_classe = "feux"
if max_classe != "empty":
rois.append([x0, y0, x1, y1, max_classe, max_proba])
if max_classe != "empty":
rois.append([x0, y0, x1, y1, max_classe, max_proba])
# 2. Filter rois with Non Maximum Suppression process
rois = non_max_suppression(rois, iou_threshold=0.1)
#display_rois(image, rois)
for roi in rois:
x0, y0, x1, y1 = roi[:4]
area = (int(x1) - int(x0) + 1) * (int(y1) - int(y0) + 1)
print(area)
display_rois(image, rois)
# 3. Write predicted labels into prediction files
for roi in rois:
......
No preview for this file type
......@@ -9,7 +9,7 @@ import random
AVERAGE_SIZE = (100, 100) # Computed with statistics
WINDOW_SIZE_SIGN = (64, 64)
WINDOW_SIZE_LIGHT = (43, 100)
AREA_THRESHOLD = 300 # 0.05 quantile for all the areas of the training dataset, prevent to classificate too little sign/light
# Dictionary for mapping class names to integers
CLASSE_TO_INT = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment