Keras 3 API 文件 / KerasCV / 邊界框格式和工具 / 邊界框工具 / 將邊界框字典轉換為批次的 Ragged 張量

將邊界框字典轉換為批次的 Ragged 張量

[來源]

to_ragged 函數

keras_cv.bounding_box.to_ragged(bounding_boxes, sentinel=-1, dtype=tf.float32)

將密集填充的邊界框 tf.Tensor 轉換為 tf.RaggedTensor

邊界框在大多数用例中都是不規則張量。將它們轉換為密集張量可以更輕鬆地使用 Tensorflow 生態系統。這個函數可以用於通過檢查邊界框的 class_id 軸的填充哨兵值來過濾掉被遮罩的邊界框。

範例

bounding_boxes = {
    "boxes": tf.constant([[2, 3, 4, 5], [0, 1, 2, 3]]),
    "classes": tf.constant([[-1, 1]]),
}
bounding_boxes = bounding_box.to_ragged(bounding_boxes)
print(bounding_boxes)
# {
#     "boxes": [[0, 1, 2, 3]],
#     "classes": [[1]]
# }

參數

  • bounding_boxes:邊界框的張量。可以是批次的,也可以是非批次的。
  • sentinel:表示當前索引處不存在邊界框的值,並且相應的框是填充,默認為 -1。
  • dtype:用於基礎張量的資料類型。

傳回值

包含過濾後的邊界框的 tf.RaggedTensor 或 'tf.Tensor' 的字典。