Skip to content
Snippets Groups Projects
Commit f55f2fc6 authored by paul_pvc's avatar paul_pvc
Browse files

cc

parent f7b52fff
No related branches found
No related tags found
1 merge request!1Gris
......@@ -30,8 +30,8 @@ def buildSampleFromPath(path1, path2, size=0):
return S
def computePixelBW(image):
return np.array(image.convert("L"))
def computePixelBW_histo(image):
return Image.fromarray(np.array(image.convert("L"))).histogram()
def computeDict(image_path, path, y_true_value, max_size: tuple):
......@@ -51,11 +51,11 @@ def computeDict(image_path, path, y_true_value, max_size: tuple):
resized = resizeImage(image, *max_size) # On ne stocke pas resized image, on calcule tout avant de l'oublier
#print(computePixelBW_histo(resized))
return {"name_path": full_path,
#"resized_image": resized,
"X_histo": computeHisto(resized),
"X_pixelbw": computePixelBW(resized),
"X_pixelbw": computePixelBW_histo(resized),
"y_true_class": y_true_value,
"y_predicted_class": None}
......@@ -94,8 +94,10 @@ def fitFromHisto(S, algo):
S_train, S_test, y_train, y_test = train_test_split(S, y, test_size=0.2, random_state=42)
X_train = np.array([np.array(l["X_histo"]) for l in S_train])
print(len(X_train[0]))
X_train = np.array([np.array(l["X_histo"]+l["X_pixelbw"]) for l in S_train])
#X_train = df[["X_histo", "X_pixelbw"]]
#print(X_train)
#print(len(X_train[0]))
algo.fit(X_train, y_train)
......@@ -111,7 +113,7 @@ def predictFromHisto(S, model, list_dict=True):
:param list_dict: is the sample in list(dict)
:return: None
"""
tab = model.predict(np.array([x["X_histo"] for x in S]))
tab = model.predict(np.array([x["X_histo"]+x["X_pixelbw"] for x in S]))
if list_dict:
for i in range(len(S)):
S[i]["y_predicted_class"] = tab[i]
......
......@@ -2,6 +2,7 @@ from PIL import Image
from sklearn.naive_bayes import GaussianNB, CategoricalNB
from sklearn.svm import SVC
import TP
from xgboost import XGBClassifier
path1_t = "./Init/Mer"
path2_t = "./Init/Ailleurs"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment