def __send_data(self):
        """ a single thread which send a data to the data queue
        """
        priori_bboxes = config.priori_bboxes / config.img_size
        while True:
            r_n = random.uniform(0, 1)
            if r_n >= 0.5:
                img_name = random.sample(self.__inria_imgs_name, 1)[0]
            else:
                img_name = random.sample(self.__hazy_imgs_name, 1)[0]
            filename = os.path.basename(img_name)
            basefile = filename.split(".")[0]

            if 'hazy_person' in img_name:
                label_name = os.path.join(self.__hazy_label_dir, (basefile+".xml"))
                # print(label_name)
            elif 'inria_person' in img_name:
                label_name = os.path.join(self.__inria_label_dir, (basefile + ".xml"))
                # print(label_name)
            else:
                raise ValueError('not support now...')

            img, bboxes = self.__read_one_sample(img_name,label_name)
            ## resize img and normalize img and bboxes##
            if self.__for_what == "train":
                if self.__whether_aug:
                    img, bboxes = train_tools.img_aug(img, bboxes)
                    if len(bboxes) == 0:
                        ## sometimes aug func will corp no person##
                        #logger.warning("No person img, abandoned...")
                        continue
                    else:
                        x_ = (bboxes[:, 3] - bboxes[:, 1]) / img.shape[1]
                        y_ = (bboxes[:, 2] - bboxes[:, 0]) / img.shape[0]

                        if np.count_nonzero(x_ <= 0.08) > 0 or np.count_nonzero(y_ <= 0.08) > 0:
                            continue
                img, bboxes = train_tools.normalize_data(img, bboxes, config.img_size)
                labels, bboxes = \
                    train_tools.ground_truth_one_img(corner_bboxes=bboxes,
                                                     priori_boxes=priori_bboxes,
                                                     grid_cell_size=config.grid_cell_size,
                                                     surounding_size=config.surounding_size, top_k=config.top_k)

                ## put data into data queue ##
                self.__data_queue.put([img, labels, bboxes])
            else:
                # raise ValueError('not support now...')
                if self.__whether_aug:
                    img, bboxes = test_tools.img_aug(img, bboxes)
                    if len(bboxes) == 0:
                        ## sometimes aug func will corp no person##
                        #logger.warning("No person img, abandoned...")
                        continue
                img, bboxes = train_tools.normalize_data(img, bboxes, config.img_size)
                self.__data_queue.put([img, bboxes])
    def load_data_eval(self):
        """Traversing the test set in sequence
        Return:
            img: one img with shape (h, w, c), if end, None
            bboxes: shape is (n, 4), if end, None
        """

        try:
            ##get img name
            img_name = self.__imgs_name_que.popleft()

            ##get corresponding anotation name
            filename = os.path.basename(img_name)
            basefile = filename.split(".")[0]

            if 'hazy_person' in img_name:
                label_name = os.path.join(self.__hazy_label_dir, (basefile+".xml"))
                # print(label_name)
            elif 'inria_person' in img_name:
                label_name = os.path.join(self.__inria_label_dir, (basefile + ".xml"))
                # print(label_name)
            else:
                raise ValueError('not support now...')

            img, bboxes = self.__read_one_sample(img_name, label_name)
            img, bboxes = train_tools.normalize_data(img, bboxes, config.img_size)
            return img, bboxes, filename
        except IndexError:
            return None, None, None
Ejemplo n.º 3
0
    def __send_data(self):
        """ a single thread which send a data to the data queue
        """
        priori_bboxes = config.priori_bboxes / config.img_size
        while True:
            img_name = random.sample(self.__imgs_name, 1)[0]
            filename = os.path.basename(img_name)
            basefile = filename.split(".")[0]

            label_name = os.path.join(self.__label_dir, (basefile + ".xml"))

            img, bboxes = self.__read_one_sample(img_name, label_name)
            ## resize img and normalize img and bboxes##
            if self.__for_what == "train":
                if self.__whether_aug:
                    img, bboxes = train_tools.img_aug(img, bboxes)
                    if len(bboxes) == 0:
                        ## sometimes aug func will corp no person##
                        #logger.warning("No person img, abandoned...")
                        continue
                img, bboxes = train_tools.normalize_data(
                    img, bboxes, config.img_size)
                labels, bboxes = \
                    train_tools.ground_truth_one_img(corner_bboxes=bboxes,
                                                     priori_boxes=priori_bboxes,
                                                     grid_cell_size=config.grid_cell_size,
                                                     surounding_size=config.surounding_size, top_k=config.top_k)

                ## put data into data queue ##
                self.__data_queue.put([img, labels, bboxes])
            else:
                if self.__whether_aug:
                    img, bboxes = test_tools.img_aug(img, bboxes)
                    if len(bboxes) == 0:
                        ## sometimes aug func will corp no person##
                        #logger.warning("No person img, abandoned...")
                        continue
                img, bboxes = train_tools.normalize_data(
                    img, bboxes, config.img_size)
                self.__data_queue.put([img, bboxes])
Ejemplo n.º 4
0
    def load_data_eval(self):
        """Traversing the test set in sequence
        Return:
            img: one img with shape (h, w, c), if end, None
            bboxes: shape is (n, 4), if end, None
        """

        try:
            ##get img name
            img_name = self.__imgs_name_que.popleft()

            ##get corresponding anotation name
            filename = os.path.basename(img_name)
            basefile = filename.split(".")[0]
            label_name = os.path.join(self.__label_dir, (basefile + '.xml'))

            img, bboxes = self.__read_one_sample(img_name, label_name)
            img, bboxes = train_tools.normalize_data(img, bboxes,
                                                     config.img_size)
            return img, bboxes, filename
        except IndexError:
            return None, None, None