Skip to content

Conversation

oarriaga
Copy link

@oarriaga oarriaga commented Oct 1, 2024

This PR ports YOLOV8 from keras-cv to keras-hub (#176). All necessary YOLOV8 functions are now found inside keras-hub:

  • Add CIOU loss.
  • Add missing masking functionality in the bounding_boxes module.
  • Add multibackend non maximum supression layer.
  • Add label encoder.
  • Build basic abstract object detector task class.
  • Add YOLOV8 backbone and detector.

Missing steps include:

  • Upload previous presets to Kaggle.
  • Remove skipping tests with presets.
  • Add colab with basic functionality.
  • Add weight transfer script from keras-cv to keras-hub.
  • Add training script.

Copy link
Collaborator

@divyashreepathihalli divyashreepathihalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @oarriaga left some initial comments

Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! What's the current progress of the PR? Is it nearly ready to merge?

raise ValueError(
"`bounding_box.mask_invalid_detections()` requires inputs to be "
"Dense tensors. Please call "
"`bounding_box.to_dense(bounding_boxes)` before passing your boxes "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is to_dense actually located?

Copy link
Author

@oarriaga oarriaga Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In keras-cv to_dense was located outside of the training loop when building a tf.data pipeline.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bounding box code is now moved to keras repo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything that is bbox relates should be in Keras and if this models needs something new specifically just add it in the model folder

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a plan here. Bounding box support is coming into core Keras.

Why does this need to be public? Where will it be called by a user? How can we use the new Keras bounding box functionality?

We can add utilities to KerasHub. We can add layers (non-max, ciou loss) if we think they are generally useful outside of yolov8 and written in a way that could be usable by other models. We can even do temp things like add a symbol to KerasHub we are going to add to core Keras.

But we should have a clear picture of where we want everything to end up. And like the expected usage we are putting out. Will bounding_box.to_dense(bounding_boxes) even make sense with the core Keras way of handling bounding boxes?

@oarriaga
Copy link
Author

oarriaga commented Nov 8, 2024

Hi, thank you! I think it’s nearly ready. Right now, I’m validating the model’s expected convergence with PASCAL, which has turned out to be more challenging than anticipated. After that, the only remaining step will be to go through your comments and incorporate any additional input from Divya.

@divyashreepathihalli divyashreepathihalli added the kokoro:force-run Runs Tests on GPU label Feb 10, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Feb 10, 2025
Copy link
Collaborator

@divyashreepathihalli divyashreepathihalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did another pass. Can you add numerics verification colab in the PR description?

@oarriaga
Copy link
Author

oarriaga commented Mar 2, 2025

Hi @divyashreepathihalli:

  • Here is the link to a notebook with the optimization including the visualization of the results.
  • Here is the link to a notebook with the automatic preset download, forward pass, and visualization of results.
  • Here is the link to a notebook comparing the inference time between this implementation and the original one.

@Sohaib-Ahmed21 Sohaib-Ahmed21 mentioned this pull request Mar 8, 2025
@ctorney
Copy link

ctorney commented Mar 19, 2025

Hi @oarriaga the task alignment score is using CIoU here
but I think should be using IoU - see eqn. 9 of https://arxiv.org/abs/2108.07755 or clamp the CIoU to 0 as they seem to do here

I raised this issue keras-team/keras-cv#2253 a while ago as negative ciou scores were resulting in strange assignments

@parthsdoshi
Copy link

parthsdoshi commented Jun 13, 2025

I'm confused, the marketing for Keras 3 here seems to mention YOLOv8 is already present? Am I missing something?

Edit: I guess the marketing states in both keras-cv + KerasHub

@Lundez
Copy link

Lundez commented Jun 13, 2025

@parthsdoshi it works in inference but not training because of the RaggedArray requirements. keras_cv has a butt-load of requirement on tensorflow. Based on experience playing around with it.

@oarriaga
Copy link
Author

@parthsdoshi @Lundez both KerasCV and KerasHub are available for training and inference. The previous shared notebooks provided an example in the VOC dataset.

@Lundez
Copy link

Lundez commented Jun 13, 2025

@oarriaga your example is using TensorFlow, could you please share how I do training with PyTorch backend on the keras_cv model?

@oarriaga
Copy link
Author

All the internal components of the model are framework independent. However, the training pipeline does use tf.data. One should be able to modify the training pipeline with a PyDataset, or a custom python generator to manage ragged tensors accordingly.

@Lundez
Copy link

Lundez commented Jun 13, 2025

What I found with my custom dataset design (PyDataset) is that keras_cv required tf tensors for some bbox functionality and if I recall also something related to loss function.

I'll try again, but spent a lot of time on this trying to get pytorch backend working during training. Without success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants