Spec-Zone.ru › TensorFlow 2.9

tf.compat.v1.image.sample_distorted_bounding_box

Генерирует одну случайную искажённую рамку для изображения. (устарело)

tf.compat.v1.image.sample_distorted_bounding_box(
    image_size,
    bounding_boxes,
    seed=None,
    seed2=None,
    min_object_covered=0.1,
    aspect_ratio_range=None,
    area_range=None,
    max_attempts=None,
    use_image_if_no_bounding_boxes=None,
    name=None
)
Устарело: ЭТА ФУНКЦИЯ УСТАРЕЛА. Она будет удалена в будущей версии. Инструкции по обновлению: seed2 параметр устарел. Используйте sample_distorted_bounding_box_v2 вместо него.

Аннотации границ часто предоставляются в дополнение к меткам фактических данных в задачах распознавания изображений или локализации объектов. Распространённый метод обучения такой системы заключается в случайном искажении изображения при сохранении его содержимого, т.е. усилении данных. Данный оператор возвращает случайное искажённое расположение объекта, т.е. рамку, с учётом image_size, bounding_boxes и ряда ограничений.

Выходной результат этого оператора — одна рамка, которую можно использовать для обрезки исходного изображения. Результат возвращается в виде 3 тензоров: begin, size и bboxes. Первые 2 тензора можно напрямую использовать в tf.slice для обрезки изображения. Последний может быть передан в tf.image.draw_bounding_boxes для визуализации вида рамки.

Рамки предоставляются и возвращаются как [y_min, x_min, y_max, x_max]. Координаты рамки — это числа с плавающей точкой в [0.0, 1.0] относительно ширины и высоты базового изображения.

Например,

# Generate a single distorted bounding box.
begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
    tf.shape(image),
    bounding_boxes=bounding_boxes,
    min_object_covered=0.1)

# 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.compat.v1.summary.image('images_with_box', image_with_box)

# Employ the bounding box to distort the image.
distorted_image = tf.slice(image, begin, size)

Обратите внимание, что если информация о рамках отсутствует, установка use_image_if_no_bounding_boxes = True предполагает наличие одной неявной рамки, охватывающей всё изображение. Если use_image_if_no_bounding_boxes имеет значение false и рамки не предоставлены, возникает ошибка.

Args
image_size A Tensor. Must be one of the following types: uint8, int8, int16, int32, int64. 1-D, containing [height, width, channels].
bounding_boxes A Tensor of type float32. 3-D with shape [batch, N, 4] describing the N bounding boxes associated with the image.
seed An optional int. Defaults to 0. If either seed or seed2 are set to non-zero, the random number generator is seeded by the given seed. Otherwise, it is seeded by a random seed.
seed2 An optional int. Defaults to 0. A second seed to avoid seed collision.
min_object_covered A Tensor of type float32. Defaults to 0.1. 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.
aspect_ratio_range An optional list of floats. Defaults to [0.75, 1.33]. The cropped area of the image must have an aspect ratio = width / height within this range.
area_range An optional list of floats. Defaults to [0.05, 1]. The cropped area of the image must contain a fraction of the supplied image within this range.
max_attempts An optional int. Defaults to 100. Number of attempts at generating a cropped region of the image of the specified constraints. After max_attempts failures, return the entire image.
use_image_if_no_bounding_boxes An optional bool. Defaults to False. Controls behavior if no bounding boxes supplied. If true, assume an implicit bounding box covering the whole input. If false, raise an error.
name A name for the operation (optional).
Returns
A tuple of Tensor objects (begin, size, bboxes).
begin A Tensor. Has the same type as image_size. 1-D, containing [offset_height, offset_width, 0]. Provide as input to tf.slice.
size A Tensor. Has the same type as image_size. 1-D, containing [target_height, target_width, -1]. Provide as input to tf.slice.
bboxes A Tensor of type float32. 3-D with shape [1, 1, 4] containing the distorted bounding box. Provide as input to tf.image.draw_bounding_boxes.
Raises
ValueError If no seed is specified and op determinism is enabled.

© 2022 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.9/api_docs/python/tf/compat/v1/image/sample_distorted_bounding_box

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API