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

Added file for the oral presentation when we will have to test

parent 33bc60ba
No related branches found
No related tags found
No related merge requests found
from Pipeline.ImageFolderManager import buildSampleFromPath, fetch_images_to_dict
from Pipeline.Model import get_SVC_model_with_best_parameters
from Pipeline.Evaluation import cross_validation_on_model
from Pipeline.AlgoTraining import fit
from Pipeline.PredictionFile import computePredictionFile
from joblib import Memory
PATH_SEA = "../Init/Mer" # PATH TO THE IMAGES CONTAINING THE SEA
PATH_WITHOUT_SEA = "../Init/Ailleurs" # PATH TO THE IMAGE WITHOUT THE SEA
memory = Memory("cached_memory")
@memory.cache()
def classifier(model):
S = buildSampleFromPath(PATH_SEA, PATH_WITHOUT_SEA)
return fit(S, model), S
algo, S = classifier(get_SVC_model_with_best_parameters())
print("loaded trained algorithm")
path = "../Init/Mer" #TODO METTRE LE NOM DU DOSSIER
result_file_name = "testFile.txt" #TODO METTRE LE NOM DU FICHIER
print("loading test images")
images_to_test = fetch_images_to_dict(path)
print(f"predicting and computing result file named {result_file_name}")
computePredictionFile(algo, images_to_test, result_file_name, S)
......@@ -24,6 +24,17 @@ def fit_algorithm(S, algo):
return algo, S_test, y_test, S_train, y_train
def fit(S, algo):
"""
Same function as 'fit_algorithm' however, you only get the classifier trained on the sample S. It's mainly used
for simplicity in the usage.
:param S: the sample on which we train
:param algo: the algo to fit the data on
:return: the fitted algorithm
"""
algo, S_test, y_test, S_train, y_train = fit_algorithm(S, algo)
return algo
def predict(S, model, list_dict=True):
"""
......
......@@ -5,6 +5,7 @@ from sklearn.metrics import accuracy_score
from Pipeline.ImageDictionaryManager import extract_relevant_data
from Pipeline.AlgoTraining import fit_algorithm
def computeError(S):
"""
Compute the empirical error of the model on the given sample.
......@@ -66,3 +67,5 @@ def cross_validation_on_model(model, S):
allowing us to have a way more precise score function.
"""
print("Taux de réussite en cross-validation: ", get_cross_val_score(model, S), "%")
import os
from Pipeline.ImageFolderManager import buildSampleFromPath
from Pipeline.AlgoTraining import fit_algorithm, predict
from Pipeline.Evaluation import computeError
def computePredictionFile(classifier, images_test=None, filename=None, S=None):
"""
Compute a file with the predictions of the model.
:param classifier: the classifier to use.
:return: A file .txt with the name of the team, the classifier used, the description methods of images,
the prediction on each image, the empirical error, the real error and the score.
"""
file = open(filename if filename is not None else "syntax_error.txt" , "w+")
file.write("# T. Bertochio, N. Efremon, P. Vigeolas-Choury (Equipe Syntax Error) \n")
file.write("# Nom de l’algorithme d’apprentissage utilisé: SVC \n")
file.write("# Valeurs des hyper-paramètres principaux de l’algorithme: (optimisé GridSearch) \n")
file.write("# Concaténation: histogramme de couleurs, coefficients GLCM, filtre de Gabor \n")
S = S if S is not None else buildSampleFromPath("../Init/Mer", "../Init/Ailleurs")
classifier, S_test, y_test, S_train, y_train = fit_algorithm(S, classifier)
predict(S, classifier)
predict(images_test, classifier)
images = S if images_test is None else images_test
for image in images:
image_name = os.path.split(image["name_path"])[1]
if image["y_predicted_class"] == 1:
image_predicted_class = "+1"
else:
image_predicted_class = "-1"
file.write(image_name+" "+image_predicted_class+"\n")
file.write("# EE = "+ str(computeError(S_train))+"\n")
file.write("# ER = "+ str(computeError(S_test))+"\n")
file.close()
\ No newline at end of file
......@@ -8,8 +8,9 @@ path = './Init/Mer'
images_path = os.listdir(path)
full_path = os.path.join(path, images_path[0])
image = Image.open(full_path)
image = TP.resizeImage(image.convert("RGB"), 224, 224)
image.save("image.png")
image = image.convert("L")
image.show()
image.save("test_no_rotate.png")
image.save("image_gray.png")
image_r = image.rotate(90)
image_r.save("test_rotate.png")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment