#include <image_ops.h>
Generate a randomly distorted bounding box for an image deterministically.
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, given the same seed
, deterministically 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
and bboxes
. 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 the height of the underlying image.
The output of this Op is guaranteed to be the same given the same seed
and is independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed
).
Example usage:
image = np.array([[[1], [2], [3]], [[4], [5], [6]], [[7], [8], [9]]]) bbox = tf.constant( ... [0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4]) seed = (1, 2)
Note that if no bounding box information is available, setting use_image_if_no_bounding_boxes = true
will assume there is a single implicit bounding box covering the whole image. If use_image_if_no_bounding_boxes
is false and no bounding boxes are supplied, an error is raised.
Arguments:
[height, width, channels]
.[batch, N, 4]
describing the N bounding boxes associated with the image.[2]
. The seed to the random number generator. Must have dtype int32
or int64
. (When using XLA, only int32
is allowed.)Optional attributes (see Attrs
):
max_attempts
failures, return the entire image.Returns:
Output
begin: 1-D, containing [offset_height, offset_width, 0]
. Provide as input to tf.slice
.Output
size: 1-D, containing [target_height, target_width, -1]
. Provide as input to tf.slice
.Output
bboxes: 3-D with shape [1, 1, 4]
containing the distorted bounding box. Provide as input to tf.image.draw_bounding_boxes
. Constructors and Destructors | |
---|---|
StatelessSampleDistortedBoundingBox(const ::tensorflow::Scope & scope, ::tensorflow::Input image_size, ::tensorflow::Input bounding_boxes, ::tensorflow::Input min_object_covered, ::tensorflow::Input seed) | |
StatelessSampleDistortedBoundingBox(const ::tensorflow::Scope & scope, ::tensorflow::Input image_size, ::tensorflow::Input bounding_boxes, ::tensorflow::Input min_object_covered, ::tensorflow::Input seed, const StatelessSampleDistortedBoundingBox::Attrs & attrs) |
Public attributes | |
---|---|
bboxes | |
begin | |
operation | |
size |
Public static functions | |
---|---|
AreaRange(const gtl::ArraySlice< float > & x) | |
AspectRatioRange(const gtl::ArraySlice< float > & x) | |
MaxAttempts(int64 x) | |
UseImageIfNoBoundingBoxes(bool x) |
Structs | |
---|---|
tensorflow::ops::StatelessSampleDistortedBoundingBox::Attrs | Optional attribute setters for StatelessSampleDistortedBoundingBox. |
::tensorflow::Output bboxes
::tensorflow::Output begin
Operation operation
::tensorflow::Output size
StatelessSampleDistortedBoundingBox( const ::tensorflow::Scope & scope, ::tensorflow::Input image_size, ::tensorflow::Input bounding_boxes, ::tensorflow::Input min_object_covered, ::tensorflow::Input seed )
StatelessSampleDistortedBoundingBox( const ::tensorflow::Scope & scope, ::tensorflow::Input image_size, ::tensorflow::Input bounding_boxes, ::tensorflow::Input min_object_covered, ::tensorflow::Input seed, const StatelessSampleDistortedBoundingBox::Attrs & attrs )
Attrs AreaRange( const gtl::ArraySlice< float > & x )
Attrs AspectRatioRange( const gtl::ArraySlice< float > & x )
Attrs MaxAttempts( int64 x )
Attrs UseImageIfNoBoundingBoxes( bool x )
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.4/api_docs/cc/class/tensorflow/ops/stateless-sample-distorted-bounding-box