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]]
# }
參數
傳回值
包含過濾後的邊界框的 tf.RaggedTensor
或 'tf.Tensor' 的字典。