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

Fixed the code that broke randomly

parent cc2aa019
No related branches found
No related tags found
No related merge requests found
import os
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
......@@ -63,11 +65,12 @@ def cross_validation_on_model(model, S):
## EXEMPLE D'EXECUTION DU PROJET
#INITIALISATION
S = compute_images_dictionnary(PATH_SEA, PATH_WITHOUT_SEA)
"""S = compute_images_dictionnary(PATH_SEA, PATH_WITHOUT_SEA)
svc_model = get_SVC_model_with_best_parameters()
#TESTS
cross_validation_on_model(svc_model, S)
cross_validation_on_model(svc_model, S)"""
os.listdir(PATH_SEA)
#test_model_on_single_train(svc_model, S)
......
......@@ -2,9 +2,15 @@ from Pipeline.ImageFolderManager import buildSampleFromPath
from Pipeline.Model import get_SVC_model_with_best_parameters
from Pipeline.Evaluation import cross_validation_on_model
PATH_SEA = "../Init/Mer" # PATH TO THE IMAGES CONTAINING THE SEA
PATH_WITHOUT_SEA = "../Init/Ailleurs" # PATH TO THE IMAGE WITHOUT THE SEA
PATH_SEA = "Init/Mer" # PATH TO THE IMAGES CONTAINING THE SEA
PATH_WITHOUT_SEA = "Init/Ailleurs" # PATH TO THE IMAGE WITHOUT THE SEA
#Exemple d'utilisation du projet
print("Début de la création de la liste d'images")
S = buildSampleFromPath(PATH_SEA, PATH_WITHOUT_SEA)
print("Fin de la création de la liste d'images")
print("Début de la récupération du modèle")
svc_model = get_SVC_model_with_best_parameters()
print("Fin de la récupération du modèle")
print("Début de l'évaluation")
cross_validation_on_model(svc_model, S)
\ No newline at end of file
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from ImageDictionaryManager import extract_relevant_data
from Pipeline.ImageDictionaryManager import extract_relevant_data
def fit_algorithm(S, algo):
......@@ -25,7 +25,7 @@ def fit_algorithm(S, algo):
return algo, S_test, y_test, S_train, y_train
def predictFromHisto(S, model, list_dict=True):
def predict(S, model, list_dict=True):
"""
Use the given model to predict the values on the images. Update the sample S to display the
predicted values.
......
......@@ -2,8 +2,8 @@ import numpy as np
import pandas as pd
from sklearn.model_selection import cross_val_score
from sklearn.metrics import accuracy_score
from ImageDictionaryManager import extract_relevant_data
from AlgoTraining import fit_algorithm
from Pipeline.ImageDictionaryManager import extract_relevant_data
from Pipeline.AlgoTraining import fit_algorithm
def computeError(S):
"""
......
import os
from PIL import Image
from ImageResizing import resizeImage
from Unsharp_Mask import apply_unsharp_mask
from Histogram import computeHisto
from GLCM import compute_glcm_caracteristics
from Gabor import get_gabor_filters
from Pipeline.ImageResizing import resizeImage
from Pipeline.Unsharp_Mask import apply_unsharp_mask
from Pipeline.Histogram import computeHisto
from Pipeline.GLCM import compute_glcm_caracteristics
from Pipeline.Gabor import get_gabor_filters
from threading import Thread
def computeDict(image_path, path, y_true_value, max_size: tuple):
......@@ -26,15 +26,14 @@ def computeDict(image_path, path, y_true_value, max_size: tuple):
resized = Image.fromarray(unsharp_resized)
rotated = [resized]#, resized.rotate(90), resized.rotate(180), resized.rotate(270)]
#rotated_gl = [im.convert("L") for im in rotated]
rotated_gl = [resized.convert('L')]
histogram = computeHisto(resized)
result = []
#create_dictionary_image(full_path, histogram, rotated_gl[0], y_true_value, result)
threaded_dictionary_creation(full_path, histogram, result, rotated_gl, y_true_value)
create_dictionary_image(full_path, histogram, resized.convert('L'), y_true_value, result)
#threaded_dictionary_creation(full_path, histogram, result, resized, y_true_value)
return result
......@@ -61,7 +60,7 @@ def extract_relevant_data(l: dict) -> list:
return l["X_histo"] + l["gabor_features"] + l["X_glcm_data"]
def threaded_dictionary_creation(full_path, histogram, result, rotated_gl, y_true_value):
def threaded_dictionary_creation(full_path, histogram, result, image, y_true_value):
"""
this function add to the list "result", the dictionary of the given images in "rotated_gl", this is a list
of images in gray level, delegating the computation of the different criteria used to train the model.
......@@ -73,6 +72,9 @@ def threaded_dictionary_creation(full_path, histogram, result, rotated_gl, y_tru
:param y_true_value: int that represent if there is the sea in the image, used to train and assert the model accuracy
"""
threads = []
rotated = [image , image.rotate(90), image.rotate(180), image.rotate(270)]
# rotated_gl = [im.convert("L") for im in rotated]
rotated_gl = [im.convert('L') for im in rotated]
for image_gl in rotated_gl:
thread = Thread(target=create_dictionary_image, args=(full_path, histogram, image_gl, y_true_value, result))
threads.append(thread)
......
import os
from ImageDictionaryManager import computeDict
from Pipeline.ImageDictionaryManager import computeDict
MAX_SIZE = (224, 224)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment