Exemple #1
0
 def __init__(self):
     Subject.__init__(self)
     self._color = Colors()
     self._path = PATH()
     self._serializer = Serializer()
     self._facesThreads = []
     self._faces = []
     self._imgfaces = []
     self._running = 0
     self._total = 0
Exemple #2
0
    def run(self, fd, obj, pickle_data):
        # Get list of files in Folder
        data = Serializer.format_data(glob.glob("IMAGE_DB_RAW/*"))

        # *======================*
        # | Create Database Tree |
        # *======================*
        Colors.print_infos("[INFO] Create Folders of databases...\n")
        for name in data.name:
            if not os.path.isdir("Data/IMAGE_DB/" + name):
                os.mkdir("Data/IMAGE_DB/" + name)

        # *=======================*
        # | Extract Faces Process |
        # *=======================*
        cpt = 0
        t2 = time.time()
        for img_path in data.image:
            Colors.print_infos("\n[PROCESSING] Try to Detect a Person...")

            # *===================*
            # | Performed Process |
            # *===================*
            yolo_result = obj.run(img_path)

            if re.match('person', yolo_result):
                Colors.print_sucess("[PROCESSING] Person Detected !")
                Colors.print_infos("[PROCESSING] Running Extract Faces Processing...")

                # print(img_path)
                Colors.print_infos("[PROCESSING] Extract Faces {}/{}".format(cpt + 1, len(data.image)))
                t1 = time.time()
                result = fd.ExtractFace(cv2.imread(img_path), "Data/IMAGE_DB/" + str(data.name[cpt]) + "/result_" + str(cpt))
                Colors.print_infos("[PROCESSING] Faces Detected : {} in {} s".format(result, time.time() - t1))
                del t1
                del result
            else:
                Colors.print_error("[PROCESSING] No Face Detected !")
            cpt += 1

        Colors.print_infos("[INFO] Remove file in IMG_DB_RAW...")
        os.system("rm -rfv IMAGE_DB_RAW/*")

        Colors.print_sucess("\n[SUCCESS] Extraction Completed in " + str(round(time.time()-t2, 4)) + " s\n")

        # Cleanning RAM
        del data
        del fd
        del cpt
        del t2

        data = Serializer.format_data(glob.glob("Data/IMAGE_DB/*"))

        # Saving Data
        Serializer.saving_data(data, pickle_data)
Exemple #3
0
def _training(object_detector, face_detector, pickle_data):
    Colors.print_sucess("[NEW] New Image Detected Run Analyse...\n")
    ex = ExtractFaces()
    ex.run(face_detector, object_detector, pickle_data)
    Colors.print_infos("[INFOS] Reloading the Serialized Data")
    recognizer.data = Serializer.loading_data(pickle_data)
    del ex
Exemple #4
0
    def __init__(self, pickle_data, pickle_embs, tiny_model, openface_model, predicator_landmarks):
        self.data = Serializer.loading_data(pickle_data)
        self._pickles_embs = pickle_embs
        self._train_paths = glob.glob("Data/IMAGE_DB/*")
        self._nb_classes = len(self._train_paths)
        self._label_index = []

        self._tinyFace_model = tiny_face_model.Model(tiny_model)
        self._nn4_small2 = create_model()

        Colors.print_infos("[LOADING] Load the model size of openface")
        Colors.print_infos("[LOADING] Align the face Predicator 68 Face Landmarks")
        # self._nn4_small2.summary()

        self._nn4_small2.load_weights(openface_model)
        self._alignment = AlignDlib(predicator_landmarks)

        Colors.print_sucess("[LOADING] Loading Model Completed\n")
Exemple #5
0
    def __init__(self, labelindex, nn4_small2, alignment, image_path, train_embs, subject, data):
        Thread.__init__(self)
        Observer.__init__(self)

        # *======================*
        # | Register the Subject |
        # *======================*
        self.register(subject)

        self._path = PATH()
        self._color = Colors()
        self._serializer = Serializer()
        self._train_paths = glob("Data/IMAGE_DB/*")
        self._label_index = labelindex
        self._nn4_small2 = nn4_small2
        self._alignment = alignment
        self._data = data
        self._image_path = image_path
        self._train_embs = train_embs
Exemple #6
0
class ExtractFaces(Subject):
    def __init__(self):
        Subject.__init__(self)
        self._color = Colors()
        self._path = PATH()
        self._serializer = Serializer()
        self._facesThreads = []
        self._faces = []
        self._imgfaces = []
        self._running = 0
        self._total = 0

    # ===========================================================================
    #         Function of main
    # ===========================================================================
    def run(self):
        self._color.printing("info", "[LOADING] Quantifying faces...")

        # Get list of Folder
        train_paths = glob.glob("IMAGE_DB_RAW/*")
        # print(train_paths)

        data = self._format_data(train_paths)
        self._thread_init(data)
        self._color.printing("success",
                             "[SUCCESS] Quantifying faces Finished\n")

        self._launch_detect_face()
        self._waiting_end_thread()

        # Saving Images
        self._saving()

    # ===========================================================================
    #         Create the Data Frame with Panda
    # ===========================================================================
    """
    @:parameter train_path = Path from glog (UNIX LIKE)
    """

    def _format_data(self, train_paths):
        data = pd.DataFrame(columns=['image', 'label', 'name'])

        for i, train_path in tqdm(enumerate(train_paths)):
            name = train_path.split("/")[-1]
            images = glob.glob(train_path + "/*")
            for image in images:
                data.loc[len(data)] = [image, i, name]

        # print(data)
        return data

    # ===========================================================================
    #         Get the Notify from DP Observer
    # ===========================================================================
    """
    @:update
    """

    def update(self, value, message):
        self._faces.append(value)
        self._imgfaces.append(message)
        self._running -= 1

    # ===========================================================================
    #         Initialize the list of threads
    # ===========================================================================
    """
    @:parameter data = DataFrame
    """

    def _thread_init(self, data):
        total = 0

        for img_path in data.image:
            # self._color.printing("info", "[LOADING] Create Threading {}/{}".format(total + 1, len(data.image)))
            # print(img_path)

            # Create the Thread
            frame = cv2.imread(img_path)
            self._facesThreads.append(FaceDetector(frame, img_path, self))
            total += 1

        self._color.printing("success",
                             "[SUCCESS] Create Threading Completed\n")

    def _waiting_end_thread(self):
        while self._running > 0:
            self._color.printing("info",
                                 "[WAITING] Waiting the end of Threads...")
            time.sleep(0.5)
        self._color.printing("success", "[SUCCESS] Thread Finished !\n")

    # ===========================================================================
    #         Launch the Threads
    # ===========================================================================
    """
    @:parameter data = the DataFrame from Panda
    @:parameter max = The maximum of Threads
    """

    def _launch_detect_face(self, max=15):

        while self._total < len(self._facesThreads):
            if self._running <= max:
                self._facesThreads[self._total].start()
                self._running += 1
                self._total += 1
                self._color.printing(
                    "info", "[PROCESSING] Processing image {}/{}".format(
                        self._total, len(self._facesThreads)))
            else:
                while self._running == 5:
                    time.sleep(0.1)

        self._color.printing("success",
                             "[SUCCESS] Processing image completed\n")

    def _saving(self):
        os.system("rsync -a " + self._path.IMAGE_DB_RAW + "/*  " +
                  self._path.IMAGE_DB)
        os.system("rm -rf " + self._path.IMAGE_DB_RAW + "/*")

        # Get list of Folder
        train_paths = glob.glob("Data/IMAGE_DB/*")
        data = self._format_data(train_paths)

        self._color.printing("success", "[SUCCESS] Extraction Completed\n")
        # print(data)
        # print(self._faces)
        self._serializer.saving_data(data)
        self._serializer.saving_faces(self._faces)