Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RetinaNet] Image Converter and ObjectDetector #1906

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

sineeli
Copy link
Collaborator

@sineeli sineeli commented Oct 3, 2024

This PR covers preprocessor for RetinaNet object detector and RetinaNet model itself. #1756

  1. ImageObjectDetector
  2. ImageObjectDetectorPreprocessor
  3. RetinaNetObjectDetector
  4. RetinaNetObjectDetectorPreprocessor
  5. RetinaNetImageConverter

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 @sineeli!! Looks generally good!! I have left a few comments.
Also, I want to make sure the -The code usage is updated to reflect the correct implementation - https://docs.google.com/document/d/15FUEP_vNehwLWJLragXhPFkYcbmmpbo0NYh5vL6q1xA/edit?tab=t.0

keras_hub/src/models/image_object_detector.py Outdated Show resolved Hide resolved
keras_hub/src/models/image_object_detector.py Outdated Show resolved Hide resolved
keras_hub/src/models/image_object_detector_preprocessor.py Outdated Show resolved Hide resolved
keras_hub/src/models/image_object_detector_preprocessor.py Outdated Show resolved Hide resolved
keras_hub/src/models/image_object_detector_preprocessor.py Outdated Show resolved Hide resolved
keras_hub/src/models/retinanet/retinanet_backbone.py Outdated Show resolved Hide resolved
keras_hub/src/models/retinanet/retinanet_label_encoder.py Outdated Show resolved Hide resolved
keras_hub/src/tests/test_case.py Outdated Show resolved Hide resolved
@sineeli
Copy link
Collaborator Author

sineeli commented Oct 4, 2024

@divyashreepathihalli

Kept some layers FeaturePyramid, RetinaNetLabelEncoder , BoxMatcher and NonMaxSupressionnot exposed as layer API's we can expose once all the models are ported in and move a centralized layers to layers/modeling/ folder.

@sineeli sineeli requested a review from fchollet October 4, 2024 18:54
@divyashreepathihalli divyashreepathihalli added the kokoro:force-run Runs Tests on GPU label Oct 5, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Oct 5, 2024
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 @sineeli. I left a few comments.

keras_hub/src/models/retinanet/prediction_head.py Outdated Show resolved Hide resolved
keras_hub/src/models/retinanet/prediction_head.py Outdated Show resolved Hide resolved
keras_hub/src/models/retinanet/prediction_head.py Outdated Show resolved Hide resolved
keras_hub/src/models/retinanet/prediction_head.py Outdated Show resolved Hide resolved
keras_hub/src/models/retinanet/prediction_head.py Outdated Show resolved Hide resolved
"max_level": 7,
"num_scales": 3,
"aspect_ratios": [0.5, 1.0, 2.0],
"anchor_size": 8,
},
input_data={
Copy link
Collaborator

Choose a reason for hiding this comment

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

define input_data also in setup()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

input_data varies in each test_case so kept it separately also how we assert changes

@divyashreepathihalli divyashreepathihalli added the kokoro:force-run Runs Tests on GPU label Oct 8, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Oct 8, 2024
@sineeli sineeli added the kokoro:force-run Runs Tests on GPU label Oct 8, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Oct 8, 2024
@sineeli sineeli added the kokoro:force-run Runs Tests on GPU label Oct 8, 2024
@divyashreepathihalli divyashreepathihalli added the kokoro:force-run Runs Tests on GPU label Oct 14, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Oct 14, 2024
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 updates @sineeli. Left a few comments! This is looking good!

keras_hub/src/bounding_box/converters.py Outdated Show resolved Hide resolved
keras_hub/src/bounding_box/converters.py Outdated Show resolved Hide resolved
Args:
anchors: `Tensors`. Anchor boxes with shape of `(N, 4)` where N is the
number of anchors.
boxes: `Tensors` Bounding boxes to encode. Boxes can be of be shape
Copy link
Collaborator

Choose a reason for hiding this comment

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

with shape (B, N, 4) for batched boxes or (N, 4) for a single set of boxes. N should match the number of anchors.

keras_hub/src/bounding_box/converters.py Outdated Show resolved Hide resolved

@keras_hub_export("keras_hub.layers.RetinaNetImageConverter")
class RetinaNetImageConverter(ImageConverter):
backbone_cls = RetinaNetBackbone
Copy link
Collaborator

Choose a reason for hiding this comment

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

The converter has no resizing option, this is something we need to support for vision models. The backbone is taking image_shape as an input. This means we have to support image resizing in preprocessor.

positive_threshold=0.5,
negative_threshold=0.4,
box_variance=[0.1, 0.1, 0.2, 0.2],
box_variance=[1.0, 1.0, 1.0, 1.0],
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please explain why this update?

anchors=anchor_boxes,
boxes=matched_gt_boxes,
anchor_format=self.bounding_box_format,
box_format=self.bounding_box_format,
encoding_format=self.encoding_format,
variance=self.box_variance,
image_shape=image_shape,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

for the return statement of this method. assign the value to box_targets and class_targets and then return them for clarity

@sineeli
Copy link
Collaborator Author

sineeli commented Oct 14, 2024

Weights Transfer Check:

retinanet_resnet50_fpn_coco: https://colab.research.google.com/gist/sineeli/c9689bb91d5ae9482e58da097f0b68d8/-keras-hub-retinanet-resnet50-fpn.ipynb

retinanet_resnet50_fpn_v2_coco: https://colab.research.google.com/gist/sineeli/1630a6d2ea48c8b13f9ef206f6f28d81/-keras-hub-retinanet-resnet50-fpn-v2.ipynb

@sineeli
Copy link
Collaborator Author

sineeli commented Oct 15, 2024

@divyashreepathihalli divyashreepathihalli added the kokoro:force-run Runs Tests on GPU label Nov 1, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Nov 1, 2024
@sineeli sineeli added the kokoro:force-run Runs Tests on GPU label Nov 4, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Nov 4, 2024
@sineeli sineeli added the kokoro:force-run Runs Tests on GPU label Nov 4, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Nov 4, 2024
@sineeli sineeli added the kokoro:force-run Runs Tests on GPU label Nov 4, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Nov 4, 2024
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.

4 participants