-
Notifications
You must be signed in to change notification settings - Fork 332
Description
Hi,
The closest issue I found about the problem I mention in this issue is the following. However I use a tf.data pipeline, as recommended in the provided answer.
I have several questions, regarding the description of the issue :
- May I miss something in my minimal provided code example ?
- May I miss something in the versions of keras-cv and tf and their cross compatibilities ?
- Should I upgrade to keras 3 (keras-hub), but I read that ragged tensor are not supported ?
Current Behavior:
I try to follow the tutorial in keras 2 to train a Yolov8 here, but it seems that a ValueError is encountered during the preprocessing layer when I add augmentation. Without augmentation the data pipeline seems to run well. It does raise the error with other preprocessing layer keras_cv.layers.RandomShear or keras_cv.layers.JitteredResize.
ValueError: Expected len(boxes.shape)=2, or len(boxes.shape)=3, got len(boxes.shape)=4
which comes from the following lines
keras_cv/src/bounding_box/utils.py", line 158, in _format_inputs * raise ValueError
It seems that the keras_cv preprocessing layer is adding a dimension in the ragged_tensor of bboxes.
Expected Behavior:
- pipeline running without error
Steps To Reproduce:
Here is a minimal exemple to reproduce the error I get
import tensorflow as tf
from tensorflow import keras
import keras_cv
import numpy as np
def load_dataset(images, classes, bbox):
image = images
bounding_boxes = {
"classes": tf.cast(classes, dtype=tf.float32),
"boxes": bbox,
}
return {"images": tf.cast(image, tf.float32), "bounding_boxes": bounding_boxes}
classes = [
[8, 8, 8, 8, 8], # 5 classes
[1], # 1 class
[12, 14, 14], # 3 classes
]
bbox = [
[[199.0, 19.0, 390.0, 401.0],
[217.0, 15.0, 270.0, 157.0],
[393.0, 18.0, 432.0, 162.0],
[1.0, 15.0, 226.0, 276.0],
[19.0, 95.0, 458.0, 443.0]], #image 1 has 4 objects
[[52.0, 117.0, 109.0, 177.0]], #image 2 has 1 object
[[88.0, 87.0, 235.0, 322.0],
[113.0, 117.0, 218.0, 471.0],
[113.0, 117.0, 218.0, 471.0]], #image 3 has 2 objects
]
images = np.random.randint(0, 255, (3, 340, 340))
bbox = tf.ragged.constant(bbox)
classes = tf.ragged.constant(classes)
images = tf.ragged.constant(images)
augmenter = keras.Sequential(
layers=[
keras_cv.layers.RandomFlip(mode="horizontal", bounding_box_format="rel_xyxy"),
]
)
data = tf.data.Dataset.from_tensor_slices((images, classes, bbox))
ds = data.map(load_dataset)
ds = ds.ragged_batch(2, drop_remainder=True)
ds = ds.map(augmenter)
Version:
Here is the package I add in the pyproject.toml:
- python = ">=3.10,<3.13"
- tensorflow = "2.13"
- keras-cv = "0.6.4"
Additional information : I tried many combination with more recent packages (keras-cv 0.9, tf 2.17, tf2.14, ...), this is one of them, I never managed to solve the error.
Anything else:
I find it difficult to find documentation about keras-cv layers as the documentation always redirect to keras-hub, but it may be normal as the migration is ongoing ? Is there a specific documentation page that is maintained during migration ?
Anyway, thank you for this amazing work and futur contributions,