Exemplo n.º 1
0
    def _parse_eval_data(self, data):
        """Parses data for evaluation."""

        # Get the image shape constants and cast the image to the selcted datatype.
        image = tf.cast(data['image'], dtype=self._dtype)
        boxes = data['groundtruth_boxes']
        classes = data['groundtruth_classes']

        image, infos, _ = preprocessing_ops.resize_and_jitter_image(
            image, [self._image_h, self._image_w],
            letter_box=self._letter_box,
            random_pad=False,
            shiftx=0.5,
            shifty=0.5,
            jitter=0.0)

        # Clip and clean boxes.
        image = image / 255.0
        boxes, inds = preprocessing_ops.transform_and_clip_boxes(
            boxes,
            infos,
            shuffle_boxes=False,
            area_thresh=0.0,
            filter_and_clip_boxes=False)
        classes = tf.gather(classes, inds)
        info = infos[-1]

        image, labels = self._build_label(image,
                                          boxes,
                                          classes,
                                          info,
                                          inds,
                                          data,
                                          is_training=False)
        return image, labels
Exemplo n.º 2
0
 def testResizeAndJitterImage(self, image_height, image_width, desired_size):
   image = tf.convert_to_tensor(np.random.rand(image_height, image_width, 3))
   processed_image, _, _ = preprocessing_ops.resize_and_jitter_image(
       image, desired_size)
   processed_image_shape = tf.shape(processed_image)
   self.assertAllEqual([desired_size[0], desired_size[1], 3],
                       processed_image_shape.numpy())
Exemplo n.º 3
0
 def _jitter_scale(self, image, shape, letter_box, jitter, random_pad,
                   aug_scale_min, aug_scale_max, translate, angle,
                   perspective):
     """Distort and scale each input image."""
     infos = []
     if (aug_scale_min != 1.0 or aug_scale_max != 1.0):
         crop_only = True
         # jitter gives you only one info object, resize and crop gives you one,
         # if crop only then there can be 1 form jitter and 1 from crop
         infos.append(self._pad_infos_object(image))
     else:
         crop_only = False
     image, crop_info, _ = preprocessing_ops.resize_and_jitter_image(
         image,
         shape,
         letter_box=letter_box,
         jitter=jitter,
         crop_only=crop_only,
         random_pad=random_pad,
         seed=self._seed,
     )
     infos.extend(crop_info)
     image, _, affine = preprocessing_ops.affine_warp_image(
         image,
         shape,
         scale_min=aug_scale_min,
         scale_max=aug_scale_max,
         translate=translate,
         degrees=angle,
         perspective=perspective,
         random_pad=random_pad,
         seed=self._seed,
     )
     return image, infos, affine
Exemplo n.º 4
0
    def _augment_image(self,
                       image,
                       boxes,
                       classes,
                       is_crowd,
                       area,
                       xs=0.0,
                       ys=0.0,
                       cut=None):
        """Process a single image prior to the application of patching."""
        if self._random_flip:
            # Randomly flip the image horizontally.
            image, boxes, _ = preprocess_ops.random_horizontal_flip(
                image, boxes, seed=self._seed)

        # Augment the image without resizing
        image, infos, crop_points = preprocessing_ops.resize_and_jitter_image(
            image, [self._output_size[0], self._output_size[1]],
            random_pad=False,
            letter_box=self._letter_box,
            jitter=self._random_crop,
            shiftx=xs,
            shifty=ys,
            cut=cut,
            seed=self._seed)

        # Clip and clean boxes.
        boxes, inds = preprocessing_ops.transform_and_clip_boxes(
            boxes,
            infos,
            area_thresh=self._area_thresh,
            shuffle_boxes=False,
            filter_and_clip_boxes=True,
            seed=self._seed)
        classes, is_crowd, area = self._select_ind(inds, classes, is_crowd,
                                                   area)  # pylint:disable=unbalanced-tuple-unpacking
        return image, boxes, classes, is_crowd, area, crop_points