為圖像生成單個隨機扭曲的邊界框。 (已棄用)
用法
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
)
參數
-
image_size
一個Tensor
。必須是以下類型之一:uint8
,int8
,int16
,int32
,int64
。一維,包含[height, width, channels]
。 -
bounding_boxes
Tensor
類型為float32
。 3-D,形狀為[batch, N, 4]
,說明了與圖像相關的 N 個邊界框。 -
seed
可選的int
。默認為0
。如果seed
或seed2
設置為非零,則隨機數生成器由給定的seed
播種。否則,它由隨機種子播種。 -
seed2
可選的int
。默認為0
。避免種子碰撞的第二個種子。 -
min_object_covered
float32
類型的張量。默認為0.1
。圖像的裁剪區域必須至少包含所提供的任何邊界框的這一部分。此參數的值應為非負數。在 0 的情況下,裁剪區域不需要與提供的任何邊界框重疊。 -
aspect_ratio_range
floats
的可選列表。默認為[0.75, 1.33]
。圖像的裁剪區域必須在此範圍內具有縱橫比 = 寬度 /高度。 -
area_range
floats
的可選列表。默認為[0.05, 1]
。圖像的裁剪區域必須包含此範圍內提供的圖像的一小部分。 -
max_attempts
可選的int
。默認為100
。嘗試生成具有指定約束的圖像的裁剪區域的次數。max_attempts
失敗後,返回整個圖像。 -
use_image_if_no_bounding_boxes
可選的bool
。默認為False
。如果未提供邊界框,則控製行為。如果為真,則假設一個隱式邊界框覆蓋整個輸入。如果為 false,則引發錯誤。 -
name
操作的名稱(可選)。
返回
-
Tensor
對象的元組(開始、大小、bbox)。 -
begin
一個Tensor
。具有與image_size
相同的類型。一維,包含[offset_height, offset_width, 0]
。作為輸入提供給tf.slice
。 -
size
一個Tensor
。具有與image_size
相同的類型。一維,包含[target_height, target_width, -1]
。作為輸入提供給tf.slice
。 -
bboxes
Tensor
類型為float32
。 3-D,形狀為[1, 1, 4]
,包含扭曲的邊界框。作為輸入提供給tf.image.draw_bounding_boxes
。
拋出
-
ValueError
如果未指定種子並啟用操作確定性。
警告:此函數已棄用。它將在未來的版本中刪除。更新說明:seed2
arg 已棄用。請改用 sample_distorted_bounding_box_v2。
在圖像識別或對象定位任務中,除了 ground-truth 標簽之外,通常還提供邊界框注釋。訓練這種係統的常用技術是在保留其內容的同時隨機扭曲圖像,即數據增強。在給定 image_size
, bounding_boxes
和一係列約束的情況下,此 Op 輸出對象的隨機失真定位,即邊界框。
這個 Op 的輸出是一個單一的邊界框,可以用來裁剪原始圖像。輸出作為 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
為假且未提供邊界框,則會引發錯誤。
相關用法
- Python tf.compat.v1.image.draw_bounding_boxes用法及代碼示例
- Python tf.compat.v1.image.extract_glimpse用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.compat.v1.strings.length用法及代碼示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代碼示例
- Python tf.compat.v1.feature_column.categorical_column_with_vocabulary_file用法及代碼示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代碼示例
- Python tf.compat.v1.variable_scope用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.as_numpy_iterator用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.covariance用法及代碼示例
- Python tf.compat.v1.placeholder用法及代碼示例
- Python tf.compat.v1.layers.Conv3D用法及代碼示例
- Python tf.compat.v1.train.get_or_create_global_step用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.image.sample_distorted_bounding_box。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。