Skip to content

Issues with YOLOv8 Bounding Box Predictions, Visualization, and bounding_box.to_ragged #2513

Open
@PLGP2020

Description

I am experiencing issues with bounding box visualization and predictions while working with a YOLO model trained using KerasCV. The bounding boxes displayed during data visualization or predictions do not align correctly with the objects in the images. Additionally, when I run predictions on test images, the results often contain arrays filled with -1 values, suggesting no valid detections are being made.

`def visualize_detections(model, dataset, bounding_box_format):
images, y_true = next(iter(dataset.take(1)))
y_pred = model.predict(images)
y_pred = bounding_box.to_ragged(y_pred)
visualization.plot_bounding_box_gallery(
images,
value_range=(0, 255),
bounding_box_format=bounding_box_format,
y_true=y_true,
y_pred=y_pred,
scale=4,
rows=2,
cols=2,
show=True,
font_scale=0.7,
class_mapping=class_mapping,
)

visualize_detections(yolo, dataset=val_ds, bounding_box_format="xyxy"`

Attempts to use keras_cv.bounding_box.to_ragged during visualization fail with the following error:
NotImplementedError: bounding_box.to_ragged was called using a backend which does not support ragged tensors. Current backend: tensorflow.

When I commented this line y_pred = bounding_box.to_ragged(y_pred) or change to to_danse(y_pred) I get only blue boxes for true not for predicted like in example https://keras.io/examples/vision/yolov8/#visualization.

When I want to predict one image its same error with to_ragged. When I use to_danse I get something like destroyed image.

`def visualize_single_image(model, image_path, bounding_box_format):

image = tf.image.decode_jpeg(tf.io.read_file(image_path))
image_resized = tf.image.resize(image, (640, 640)) / 255.0
image_resized = tf.expand_dims(image_resized, axis=0) 
y_pred = model.predict(image_resized)
y_pred = bounding_box.to_ragged(y_pred)


visualization.plot_bounding_box_gallery(
    images=image_resized,
    value_range=(0, 1),
    rows=1,
    cols=1,
    y_pred=y_pred,
    scale=5,
    font_scale=0.7,
    bounding_box_format=bounding_box_format,
    class_mapping=class_mapping,
)

visualize_single_image(yolo, "00078.jpg", bounding_box_format="xyxy")`

The data was converted using a script that processes bounding boxes into Pascal VOC (XML) format.

Is there a way to validate the data format expected by KerasCV, especially for bounding boxes in the xyxy format?

Does the issue stem from saving and reloading the model using model.save() and tf.keras.models.load_model()?

How can I address the issue with bounding_box.to_ragged on a TensorFlow backend? Are there any alternative methods for handling ragged tensors in this context?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions