def _resize_image(self, image, bboxes=None):
        """
        We need to resize image and bounding boxes when the biggest side
        dimension is bigger than `self._image_max_size` or when the smaller
        side is smaller than `self._image_min_size`.

        Then, using the ratio we used, we need to properly scale the bounding
        boxes.

        Args:
            image: Tensor with image of shape (H, W, 3).
            bboxes: Tensor with bounding boxes with shape (num_bboxes, 5).
                where we have (x_min, y_min, x_max, y_max, label) for each one.

        Returns:
            image: Tensor with scaled image.
            bboxes: Tensor with scaled (using the same factor as the image)
                bounding boxes with shape (num_bboxes, 5).
            scale_factor: Scale factor used to modify the image (1.0 means no
                change).
        """
        if self._fixed_resize:
            resized = resize_image_fixed(image,
                                         self._image_fixed_height,
                                         self._image_fixed_width,
                                         bboxes=bboxes)
        else:
            resized = resize_image(
                image,
                bboxes=bboxes,
                min_size=self._image_min_size,
                max_size=self._image_max_size,
            )

        return resized["image"], resized.get("bboxes"), resized["scale_factor"]
Esempio n. 2
0
 def _resize_image(self,
                   image_array,
                   boxes_array=None,
                   min_size=None,
                   max_size=None):
     image = tf.placeholder(tf.float32, image_array.shape)
     feed_dict = {
         image: image_array,
     }
     if boxes_array is not None:
         boxes = tf.placeholder(tf.float32, boxes_array.shape)
         feed_dict[boxes] = boxes_array
     else:
         boxes = None
     resized = resize_image(image,
                            bboxes=boxes,
                            min_size=min_size,
                            max_size=max_size)
     with self.test_session() as sess:
         resized_dict = sess.run(resized, feed_dict=feed_dict)
         return (
             resized_dict['image'],
             resized_dict.get('bboxes'),
             resized_dict.get('scale_factor'),
         )
    def _resize_image(self, image, bboxes=None):
        """
        We need to resize image and bounding boxes when the biggest side
        dimension is bigger than `self._image_max_size` or when the smaller
        side is smaller than `self._image_min_size`.

        Then, using the ratio we used, we need to properly scale the bounding
        boxes.

        Args:
            image: Tensor with image of shape (H, W, 3).
            bboxes: Tensor with bounding boxes with shape (num_bboxes, 5).
                where we have (x_min, y_min, x_max, y_max, label) for each one.

        Returns:
            image: Tensor with scaled image.
            bboxes: Tensor with scaled (using the same factor as the image)
                bounding boxes with shape (num_bboxes, 5).
            scale_factor: Scale factor used to modify the image (1.0 means no
                change).
        """
        resized = resize_image(
            image, bboxes=bboxes, min_size=self._image_min_size,
            max_size=self._image_max_size
        )

        return resized['image'], resized.get('bboxes'), resized['scale_factor']
Esempio n. 4
0
 def _resize_image(self, image_array, boxes_array=None, min_size=None,
                   max_size=None):
     image = tf.placeholder(tf.float32, image_array.shape)
     feed_dict = {
         image: image_array,
     }
     if boxes_array is not None:
         boxes = tf.placeholder(tf.float32, boxes_array.shape)
         feed_dict[boxes] = boxes_array
     else:
         boxes = None
     resized = resize_image(
         image, bboxes=boxes, min_size=min_size, max_size=max_size
     )
     with self.test_session() as sess:
         resized_dict = sess.run(resized, feed_dict=feed_dict)
         return (
             resized_dict['image'],
             resized_dict.get('bboxes'),
             resized_dict.get('scale_factor'),
         )