예제 #1
0
    def plot_face_test(self):
        """
        Plot one face
        """
        masks = get_training_masks()[:10]

        print("Training model")
        res_t, res_th = load_histograms(masks=masks, recompute=False)

        print("Testing model")
        test_files = get_test_masks()[:5]
        distance = 25
        w = 15
        h = 15

        for name, mask in test_files:
            image_test = cv2.imread(name)
            plot_faces(image_test,
                       w,
                       h,
                       0.2,
                       res_t,
                       res_th,
                       distance,
                       "face_" + name.split("/")[-1],
                       nb_angles=10,
                       nb_scales=2)
예제 #2
0
    def verif_matrix(self):
        """
        ecrit dans le fichier matrice.txt le contenu de chaque matrice pour un biais de 0.2
        """
        masks = get_training_masks()[:200]
        fichier = open("output/matrice.txt", "w")

        print("Training model")
        res_t, res_th = load_histograms(masks=masks)

        print("Testing model")
        test_files = get_test_masks()[:20]
        recall = np.zeros((10, 10))
        precision = np.zeros((10, 10))
        accuracy = np.zeros((10, 10))

        distance = 400

        for w in range(50, 201, 50):
            for h in range(50, 201, 50):
                print("w", w, "h", h)
                Y_pred = np.array([])
                Y_true = np.array([])
                proba = np.array([])
                for name, mask in test_files:
                    image_test = cv2.imread(name)
                    prediction = get_predicted_masks(image_test, mask, w, h,
                                                     0.15, res_t, res_th,
                                                     distance)
                    Y_pred = np.append(Y_pred, prediction.flatten())
                    Y_true = np.append(Y_true, mask.flatten())
                fichier.write(
                    str(w) + "   " + str(h) + "    " +
                    str(met.get_confusion_matrix(Y_true, Y_pred)) + "\n\n")
예제 #3
0
def plot_face_test():

    images = [
        "Images/Nous/florent.jpg", "Images/Nous/yoan.jpg",
        "Images/Nous/antonin.jpg"
    ]
    masks = get_training_masks()[:150]
    hist_h, hist_hT = load_histograms(masks=masks)
    for i in images:
        print(i)
        img = cv2.imread(i)
        plot_faces(img, 50, 50, 0.2, hist_h, hist_hT, 200,
                   i.split("/")[-1] + "test50.png")
예제 #4
0
    def compare_bias(self, distance=50, w_range=range(20, 300, 50)):
        """
        Compare the bias
        """
        plt.close()
        masks = get_training_masks()[:50]

        fig, axes = plt.subplots(3, 1, figsize=(15, 10))
        fig.tight_layout(pad=10, w_pad=4, h_pad=4)

        for i, bias in enumerate([i/10.0 for i in range(0, 10)]):
            self.plot_with_parameters("bias = " + str(bias), axes, masks, bias=bias)

        plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.20),  shadow=True, ncol=2)

        plt.savefig("output/compare_bias.png")
예제 #5
0
    def compare_distance(self, w_range=range(20, 300, 50)):
        """
        Compare the distances
        """
        plt.close()
        masks = get_training_masks()[:50]

        fig, axes = plt.subplots(3, 1, figsize=(15, 10))
        fig.tight_layout(pad=10, w_pad=4, h_pad=4)

        for i, distance in enumerate(range(10, 400, 50)):
            self.plot_with_parameters("distance = " + str(distance), axes, masks, distance=distance)

        plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.20),  shadow=True, ncol=2)

        plt.savefig("output/compare_distance.png")
예제 #6
0
    def compare_color_type(self, distance=50, w_range=range(20, 300, 50)):
        """
        Compare the color type
        """
        plt.close()
        color_type = ['RGB', 'rg']
        masks = get_training_masks()[:50]

        fig, axes = plt.subplots(3, 1, figsize=(15, 10))
        fig.tight_layout(pad=8, w_pad=4, h_pad=4)

        for i, color in enumerate(color_type):
            self.plot_with_parameters("color mode = " + color, axes, masks, color_mode=color)

        plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.25),  shadow=True, ncol=2)

        plt.savefig("output/compare_color_mode.png")
예제 #7
0
    def compare_quantification(self, distance=50, w_range=range(20, 300, 50)):
        """
        Compare the quantification metric
        """
        plt.close()
        Q = [8, 16, 32, 64, 128, 256]
        masks = get_training_masks()[:50]

        fig, axes = plt.subplots(3, 1, figsize=(15, 10))
        fig.tight_layout(pad=8, w_pad=4, h_pad=4)

        for i, q in enumerate(Q):
            self.plot_with_parameters("Q = " + str(q), axes, masks, Q=q)

        plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.25),  shadow=True, ncol=2)

        plt.savefig("output/compare_quantification.png")
예제 #8
0
#!/usr/bin/env python3
"""
Implementation of Face Detection using Skin color.
"""

import cv2
import numpy as np
from src.lab1.info_image import get_training_masks
from src.lab1.colors_to_probabilities import convert_colors_probalities, compute_histograms, load_histograms, get_prediction

if __name__ == "__main__":
    # compute_histograms(" ")
    get_training_masks()
    # img_test = cv2.imread("/user/2/klopptoa/Documents/3A/PRML_TP/Images/2003/03/03/big/img_3.jpg")
    # h, ht = load_histograms(" ")
    # res_test = get_prediction(img_test, h, ht, 0.2)
    # cv2.imwrite("output/resultat.png", res_test)
    # print("fini")
예제 #9
0
    def verif_taille_ellipse(self,
                             w_range,
                             h_range,
                             bias,
                             distance,
                             save_plots_roc=False):
        """
        test les différentes metrics
        :param w_parameters: must be a tuple of 3 parameters (begin, end, step) of the width of each ellipse
        :param h_parameters: must be a tuple of 3 parameters (begin, end, step) of the height of each ellipse
        :param bias: the chosen bias
        :param distance: the minimum distance between two ellipses
        :param save_plot_roc: if set to true, it saves the roc plots
        :return: un dictionnaire des metrics
        """

        # Checkig parameters
        if (len(w_range) != 3 or len(h_range) != 3):
            print(
                "w_range or h_range should have size 3. Check documentation for further information"
            )
            raise ValueError

        if (w_range[1] < w_range[0]) or (h_range[1] < h_range[0]):
            print(
                "End width/height should be larger than beginning width/height"
            )
            raise ValueError

        masks = get_training_masks()[:1500]

        print("Training model")
        res_t, res_th = load_histograms(masks=masks)

        print("Testing model")
        test_files = get_test_masks()[:10]

        recall = np.zeros(
            (math.ceil((w_range[1] - w_range[0]) / float(w_range[2])),
             math.ceil((h_range[1] - h_range[0]) / float(h_range[2]))))
        precision = np.zeros(
            (math.ceil((w_range[1] - w_range[0]) / float(w_range[2])),
             math.ceil((h_range[1] - h_range[0]) / float(h_range[2]))))
        accuracy = np.zeros(
            (math.ceil((w_range[1] - w_range[0]) / float(w_range[2])),
             math.ceil((h_range[1] - h_range[0]) / float(h_range[2]))))

        w_index = 0
        h_index = 0

        for w in range(w_range[0], w_range[1], w_range[2]):
            for h in range(h_range[0], h_range[1], h_range[2]):
                print("w", w, "h", h)
                Y_pred = np.array([])
                Y_true = np.array([])
                proba = np.array([])
                for name, mask in test_files:
                    image_test = cv2.imread(name)
                    proba = np.append(
                        proba, get_proba_predic(image_test, res_t, res_th))
                    prediction = get_predicted_masks(image_test, mask, w, h,
                                                     bias, res_t, res_th,
                                                     distance)
                    Y_pred = np.append(Y_pred, prediction.flatten())
                    Y_true = np.append(Y_true, mask.flatten())
                recall[w_index, h_index] = met.get_all_metric(Y_true,
                                                              Y_pred)["recall"]
                precision[w_index,
                          h_index] = met.get_all_metric(Y_true,
                                                        Y_pred)["precision"]
                accuracy[w_index,
                         h_index] = met.get_all_metric(Y_true,
                                                       Y_pred)["accuracy"]
                if save_plots_roc:
                    met.plot_presion_recall_curve(Y_true,
                                                  proba,
                                                  name="output/TestPrWh_w" +
                                                  str(w) + "h" + str(h),
                                                  save=True)
                    met.plot_roc(Y_true,
                                 proba,
                                 name="output/TestRocWh_w" + str(w) + "h" +
                                 str(h),
                                 save=True)
                h_index += 1
            w_index += 1
            h_index = 0

        # PLOTTING
        w = np.arange(w_range[0], w_range[1], w_range[2])
        h = np.arange(w_range[0], w_range[1], w_range[2])
        w, h = np.meshgrid(w, h)
        self.plot(w, h, recall, "recall", distance, bias)
        self.plot(w, h, precision, "precision", distance, bias)
        self.plot(w, h, accuracy, "accuracy", distance, bias)