SampleDistortedBoundingBoxV2
tensorflow C++ API
tensorflow::ops::SampleDistortedBoundingBoxV2
Generate a single randomly distorted bounding box for an image.
Summary
Bounding box annotations are often supplied in addition to ground-truth labels in image recognition or object localization tasks. A common technique for training such a system is to randomly distort an image while preserving its content, i.e.data augmentation. This Op outputs a randomly distorted localization of an object, i.e. bounding box, given an image_size
, bounding_boxes
and a series of constraints.
The output of this Op is a single bounding box that may be used to crop the original image. The output is returned as 3 tensors:begin
,size
andbboxes
. The first 2 tensors can be fed directly into tf.slice
to crop the image. The latter may be supplied to tf.image.draw_bounding_boxes
to visualize what the bounding box looks like.
Bounding boxes are supplied and returned as[y_min, x_min, y_max, x_max]
. The bounding box coordinates are floats in[0.0, 1.0]
relative to the width and height of the underlying image.
For example,
```python Generate a single distorted bounding box.
begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box( tf.shape(image), bounding_boxes=bounding_boxes)
Draw the bounding box in an image summary.
image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0), bbox_for_draw) tf.image_summary('images_with_box', image_with_box)
Employ the bounding box to distort the image.
distorted_image = tf.slice(image, begin, size) ```
Note that if no bounding box information is available, settinguse_image_if_no_bounding_boxes = true
will assume there is a single implicit bounding box covering the whole image. Ifuse_image_if_no_bounding_boxes
is false and no bounding boxes are supplied, an error is raised.
Arguments:
- scope: A Scope object
- image_size: 1-D, containing [height, width, channels].
- bounding_boxes: 3-D with shape [batch, N, 4] describing the N bounding boxes associated with the image.
- min_object_covered: The cropped area of the image must contain at least this fraction of any bounding box supplied. The value of this parameter should be non-negative. In the case of 0, the cropped area does not need to overlap any of the bounding boxes supplied.
Optional attributes (seeAttrs
):
- seed: If eitherseedorseed2are set to non-zero, the random number generator is seeded by the givenseed. Otherwise, it is seeded by a random seed.
- seed2: A second seed to avoid seed collision. min_object_covered: The cropped area of the image must contain at least this fraction of any bounding box supplied. The value of this parameter should be non-negative. In the case of 0, the cropped area does not need to overlap any of the bounding boxes supplied.
- area_range: The cropped area of the image must contain a fraction of the supplied image within in this range.
- max_attempts: Number of attempts at generating a cropped region of the image of the specified constraints. After max_attemptsfailures, return the entire image.
- use_image_if_no_bounding_boxes: Controls behavior if no bounding boxes supplied. If true, assume an implicit bounding box covering the whole input. If false, raise an error.
Returns:
Output
begin: 1-D, containing[offset_height, offset_width, 0]
. Provide as input totf.slice
.Output
size: 1-D, containing[target_height, target_width, -1]
. Provide as input totf.slice
.Output
bboxes: 3-D with shape[1, 1, 4]
containing the distorted bounding box. Provide as input totf.image.draw_bounding_boxes
.
Constructor
- SampleDistortedBoundingBoxV2(const ::tensorflow::Scope & scope, ::tensorflow::Input image_size, ::tensorflow::Input bounding_boxes, const SampleDistortedBoundingBox::Attrs & attrs) .
Public attributes
- tensorflow::Output begin.
- tensorflow::Output size.
- tensorflow::Output bboxes.
SampleDistortedBoundingBoxV2 block
Source link : https://github.com/EXPNUNI/enuSpaceTensorflow/blob/master/enuSpaceTensorflow/tf_image_ops.cpp
Argument:
- Scope scope : A Scope object (A scope is generated automatically each page. A scope is not connected.)
- image_size : connect Input node or input int32 value.
- bounding_boxes : connect Input node or input float value.
- min_object_covered : connect Input node or input float value.
- SampleDistortedBoundingBoxV2::Attrs attrs : input attrs. ex) seed_ = 0;seed2_ = 0;aspect_ratio_range_ = {0.75f, 1.33f}; area_range_ = {0.05f, 1.0f};int64 max_attempts_ = 100;bool use_image_if_no_bounding_boxes_ = false;
Return:
- Output begin: Output object of SampleDistortedBoundingBoxV2 class object.
- Output size: Output object of SampleDistortedBoundingBoxV2 class object.
- Output bboxes: Output object of SampleDistortedBoundingBoxV2 class object.
Result:
- std::vector(Tensor) product_result : Returned object of executed result by calling session.