Пример #1
0
def preprocess_func(image, image_meta, boxes=None):
    """
    Performs preprocessing on images
    """
    rgb_mean = (np.array([93.877, 98.801, 95.923], dtype=np.float32).reshape(1, 1, 3))
    rgb_std = (np.array([78.782, 80.130, 81.200], dtype=np.float32).reshape(1, 1, 3))

    if boxes is not None:
        # [x, y, w, h] -> 0, 2 -> x and width
        # a, min max -> boxes x1 and x2 coordinations, min is 0 and max is the orig_size of input
        boxes[:, [0, 2]] = np.clip(boxes[:, [0, 2]], 0., image_meta['orig_size'][1] - 1.)  # min max out -> deals with the width
        boxes[:, [1, 3]] = np.clip(boxes[:, [1, 3]], 0., image_meta['orig_size'][0] - 1.)   # deals with the height

    drift_prob = 0.
    flip_prob = 0.

    #image, image_meta = whiten(image, image_meta, mean=rgb_mean, std=rgb_std)
    image, image_meta, boxes = drift(image, image_meta, prob=drift_prob, boxes=boxes)
    image,image_meta, boxes = flip(image, image_meta, prob=flip_prob, boxes=boxes)

#     if args.forbid_resize:
#         image, image_meta, boxes = crop_or_pad(image, image_meta, args.input_size, boxes=boxes)
#     else:
#    image, image_meta, boxes = resize(image, image_meta, (384, 1248), boxes=boxes)

    return image, image_meta, boxes
Пример #2
0
    def preprocess(self,
                   input_size,
                   image,
                   image_meta,
                   boxes=None,
                   drift_prob,
                   flip_prob,
                   forbid_resize=False):
        """
        Performs preprocessing on images
        """
        if boxes is not None:
            # [x, y, w, h] -> 0, 2 -> x and width
            boxes[:,
                  [0, 2]] = np.clip(boxes[:, [0, 2]], 0.,
                                    image_meta['orig_size'][1] -
                                    1.)  # min max out -> deals with the width
            boxes[:, [1, 3]] = np.clip(boxes[:, [1, 3]], 0.,
                                       image_meta['orig_size'][0] -
                                       1.)  # deals with the height

        drift_prob = drift_prob if self.phase == 'train' else 0.
        flip_prob = flip_prob if self.phase == 'train' else 0.

        image, image_meta = whiten(image,
                                   image_meta,
                                   mean=self.rgb_mean,
                                   std=self.rgb_std)
        image, image_meta, boxes = drift(image,
                                         image_meta,
                                         prob=drift_prob,
                                         boxes=boxes)
        image, image_meta, boxes = flip(image,
                                        image_meta,
                                        prob=flip_prob,
                                        boxes=boxes)

        if forbid_resize == True:
            image, image_meta, boxes = crop_or_pad(image,
                                                   image_meta,
                                                   input_size,
                                                   boxes=boxes)
        else:
            image, image_meta, boxes = resize(image,
                                              image_meta,
                                              input_size,
                                              boxes=boxes)

        return image, image_meta, boxes
Пример #3
0
    def preprocess(self, image, image_meta, boxes=None):
        """
        Performs preprocessing on images
        """
        if boxes is not None:
            # [x, y, w, h] -> 0, 2 -> x and width
            # a, min max -> boxes x1 and x2 coordinations, min is 0 and max is the orig_size of input
            boxes[:,
                  [0, 2]] = np.clip(boxes[:, [0, 2]], 0.,
                                    image_meta['orig_size'][1] -
                                    1.)  # min max out -> deals with the width
            boxes[:, [1, 3]] = np.clip(boxes[:, [1, 3]], 0.,
                                       image_meta['orig_size'][0] -
                                       1.)  # deals with the height

        drift_prob = self.args.drift_prob if self.phase == 'train' else 0.
        flip_prob = self.args.flip_prob if self.phase == 'train' else 0.

        image, image_meta = whiten(image,
                                   image_meta,
                                   mean=self.rgb_mean,
                                   std=self.rgb_std)
        image, image_meta, boxes = drift(image,
                                         image_meta,
                                         prob=drift_prob,
                                         boxes=boxes)
        image, image_meta, boxes = flip(image,
                                        image_meta,
                                        prob=flip_prob,
                                        boxes=boxes)

        if self.args.forbid_resize:
            image, image_meta, boxes = crop_or_pad(image,
                                                   image_metea,
                                                   self.input_size,
                                                   boxes=boxes)
        else:
            image, image_meta, boxes = resize(image,
                                              image_meta,
                                              self.input_size,
                                              boxes=boxes)

        return image, image_meta, boxes