Exemple #1
0
    def _parse_train_data(self, data):
        """Parses data for training."""

        # Initialize the shape constants.
        image = data['image']
        boxes = data['groundtruth_boxes']
        classes = data['groundtruth_classes']

        if self._random_flip:
            # Randomly flip the image horizontally.
            image, boxes, _ = preprocess_ops.random_horizontal_flip(
                image, boxes, seed=self._seed)

        if not data['is_mosaic']:
            image, infos, affine = self._jitter_scale(
                image, [self._image_h, self._image_w], self._letter_box,
                self._jitter, self._random_pad, self._aug_scale_min,
                self._aug_scale_max, self._aug_rand_translate,
                self._aug_rand_angle, self._aug_rand_perspective)

            # Clip and clean boxes.
            boxes, inds = preprocessing_ops.transform_and_clip_boxes(
                boxes,
                infos,
                affine=affine,
                shuffle_boxes=False,
                area_thresh=self._area_thresh,
                augment=True,
                seed=self._seed)
            classes = tf.gather(classes, inds)
            info = infos[-1]
        else:
            image = tf.image.resize(image, (self._image_h, self._image_w),
                                    method='nearest')
            output_size = tf.cast([640, 640], tf.float32)
            boxes_ = bbox_ops.denormalize_boxes(boxes, output_size)
            inds = bbox_ops.get_non_empty_box_indices(boxes_)
            boxes = tf.gather(boxes, inds)
            classes = tf.gather(classes, inds)
            info = self._pad_infos_object(image)

        # Apply scaling to the hue saturation and brightness of an image.
        image = tf.cast(image, dtype=self._dtype)
        image = image / 255.0
        image = preprocessing_ops.image_rand_hsv(image,
                                                 self._aug_rand_hue,
                                                 self._aug_rand_saturation,
                                                 self._aug_rand_brightness,
                                                 seed=self._seed,
                                                 darknet=self._darknet)

        # Cast the image to the selcted datatype.
        image, labels = self._build_label(image,
                                          boxes,
                                          classes,
                                          info,
                                          inds,
                                          data,
                                          is_training=True)
        return image, labels
Exemple #2
0
 def testImageRandHSV(self,
                      image_height,
                      image_width,
                      rh,
                      rs,
                      rv,
                      is_darknet=False):
   image = tf.convert_to_tensor(np.random.rand(image_height, image_width, 3))
   processed_image = preprocessing_ops.image_rand_hsv(
       image, rh, rs, rv, darknet=is_darknet)
   processed_image_shape = tf.shape(processed_image)
   self.assertAllEqual([image_height, image_width, 3],
                       processed_image_shape.numpy())