mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 19:45:21 +00:00
ensemble bug
This commit is contained in:
parent
d080107998
commit
84a6446040
@ -25,7 +25,6 @@ idendities = {
|
||||
"Matt": ["img29.jpg", "img30.jpg", "img31.jpg", "img32.jpg", "img33.jpg"],
|
||||
"Leonardo": ["img34.jpg", "img35.jpg", "img36.jpg", "img37.jpg"],
|
||||
"George": ["img38.jpg", "img39.jpg", "img40.jpg", "img41.jpg"]
|
||||
|
||||
}
|
||||
#--------------------------
|
||||
#Positives
|
||||
@ -33,7 +32,7 @@ idendities = {
|
||||
positives = []
|
||||
|
||||
for key, values in idendities.items():
|
||||
|
||||
|
||||
#print(key)
|
||||
for i in range(0, len(values)-1):
|
||||
for j in range(i+1, len(values)):
|
||||
@ -45,6 +44,7 @@ for key, values in idendities.items():
|
||||
|
||||
positives = pd.DataFrame(positives, columns = ["file_x", "file_y"])
|
||||
positives["decision"] = "Yes"
|
||||
|
||||
print(positives.shape)
|
||||
#--------------------------
|
||||
#Negatives
|
||||
@ -55,18 +55,18 @@ negatives = []
|
||||
|
||||
for i in range(0, len(idendities) - 1):
|
||||
for j in range(i+1, len(idendities)):
|
||||
#print(samples_list[i], " vs ",samples_list[j])
|
||||
#print(samples_list[i], " vs ",samples_list[j])
|
||||
cross_product = itertools.product(samples_list[i], samples_list[j])
|
||||
cross_product = list(cross_product)
|
||||
#print(cross_product)
|
||||
|
||||
|
||||
for cross_sample in cross_product:
|
||||
#print(cross_sample[0], " vs ", cross_sample[1])
|
||||
negative = []
|
||||
negative.append(cross_sample[0])
|
||||
negative.append(cross_sample[1])
|
||||
negatives.append(negative)
|
||||
|
||||
|
||||
negatives = pd.DataFrame(negatives, columns = ["file_x", "file_y"])
|
||||
negatives["decision"] = "No"
|
||||
|
||||
@ -80,8 +80,11 @@ df = pd.concat([positives, negatives]).reset_index(drop = True)
|
||||
|
||||
print(df.decision.value_counts())
|
||||
|
||||
df.file_x = "deepface/tests/dataset/"+df.file_x
|
||||
df.file_y = "deepface/tests/dataset/"+df.file_y
|
||||
df.file_x = "dataset/"+df.file_x
|
||||
df.file_y = "dataset/"+df.file_y
|
||||
|
||||
print(df.head())
|
||||
|
||||
#--------------------------
|
||||
#DeepFace
|
||||
|
||||
@ -94,7 +97,7 @@ pretrained_models["VGG-Face"] = VGGFace.loadModel()
|
||||
print("VGG-Face loaded")
|
||||
pretrained_models["Facenet"] = Facenet.loadModel()
|
||||
print("Facenet loaded")
|
||||
pretrained_models["OpenFace"] = OpenFace.loadModel()
|
||||
pretrained_models["OpenFace"] = OpenFace.loadModel()
|
||||
print("OpenFace loaded")
|
||||
pretrained_models["DeepFace"] = FbDeepFace.loadModel()
|
||||
print("FbDeepFace loaded")
|
||||
@ -111,7 +114,8 @@ if True:
|
||||
resp_obj = DeepFace.verify(instances
|
||||
, model_name = model
|
||||
, model = pretrained_models[model]
|
||||
, distance_metric = metric)
|
||||
, distance_metric = metric
|
||||
, enforce_detection = False)
|
||||
|
||||
distances = []
|
||||
|
||||
@ -120,7 +124,7 @@ if True:
|
||||
distances.append(distance)
|
||||
|
||||
df['%s_%s' % (model, metric)] = distances
|
||||
|
||||
|
||||
df.to_csv("face-recognition-pivot.csv", index = False)
|
||||
else:
|
||||
df = pd.read_csv("face-recognition-pivot.csv")
|
||||
@ -135,14 +139,14 @@ fig = plt.figure(figsize=(15, 15))
|
||||
figure_idx = 1
|
||||
for model in models:
|
||||
for metric in metrics:
|
||||
|
||||
|
||||
feature = '%s_%s' % (model, metric)
|
||||
|
||||
ax1 = fig.add_subplot(4, 2, figure_idx)
|
||||
|
||||
|
||||
ax1 = fig.add_subplot(len(models) * len(metrics), len(metrics), figure_idx)
|
||||
|
||||
df[df.decision == "Yes"][feature].plot(kind='kde', title = feature, label = 'Yes', legend = True)
|
||||
df[df.decision == "No"][feature].plot(kind='kde', title = feature, label = 'No', legend = True)
|
||||
|
||||
|
||||
figure_idx = figure_idx + 1
|
||||
|
||||
plt.show()
|
||||
@ -204,6 +208,15 @@ gbm.save_model("face-recognition-ensemble-model.txt")
|
||||
|
||||
predictions = gbm.predict(x_test)
|
||||
|
||||
prediction_classes = []
|
||||
for prediction in predictions:
|
||||
prediction_class = np.argmax(prediction)
|
||||
prediction_classes.append(prediction_class)
|
||||
|
||||
print(y_test)
|
||||
print("------")
|
||||
print(prediction_classes)
|
||||
|
||||
cm = confusion_matrix(y_test, prediction_classes)
|
||||
print(cm)
|
||||
|
||||
@ -232,7 +245,7 @@ plt.rcParams["figure.figsize"] = [20, 20]
|
||||
for i in range(0, gbm.num_trees()):
|
||||
ax = lgb.plot_tree(gbm, tree_index = i)
|
||||
plt.show()
|
||||
|
||||
|
||||
if i == 2:
|
||||
break
|
||||
#--------------------------
|
||||
@ -246,4 +259,4 @@ auc = metrics.roc_auc_score(y_test, y_pred_proba)
|
||||
plt.figure(figsize=(7,3))
|
||||
plt.plot(fpr,tpr,label="data 1, auc="+str(auc))
|
||||
|
||||
#--------------------------
|
||||
#--------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user