Skip to content

Adding new zero-shot examples #32483

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

Draft
wants to merge 83 commits into
base: main
Choose a base branch
from

Conversation

SangbumChoi
Copy link
Contributor

What does this PR do?

Fixes #32459

Following two PR should be merged before merging this example!
#31828
#31964

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

EduardoPach and others added 30 commits June 25, 2024 13:54
@SangbumChoi SangbumChoi marked this pull request as ready for review September 26, 2024 01:48
@SangbumChoi
Copy link
Contributor Author

Hi @qubvel It is now ready to review this new example. For the CI error it says unauthorized I'm not sure how to handle this so it would be appreciated to let me know how to fix this.

@SangbumChoi
Copy link
Contributor Author

Screenshot 2024-09-27 at 4 36 25 PM

@junxnone
Copy link

Screenshot 2024-09-27 at 4 36 25 PM

Thanks for share the finetune code.

I test with the code https://github.com/SangbumChoi/transformers on branch grounding_examples.
and only get the lower MAP, it is same as the tensorboard logs in your model here

image

Looks like I missed something...

@SangbumChoi
Copy link
Contributor Author

SangbumChoi commented Nov 30, 2024

@junxnone Thanks for the interest. This is because due to difference between zero-shot to coco converted AP. I have fixed in my code but not updated in here :(

Comment on lines +122 to +150
def convert_zero_shot_to_coco_format(predictions, label2id):
"""
Convert zershot format output to typical object detection format in order to calculate mAP.

Args:
predictions (Dict): Output of zero-shot object detection
e.g. {'scores': tensor([0.4786, 0.4379, 0.4760], device='cuda:0'), 'labels': ['a cat', 'a cat', 'a remote control'], 'boxes': tensor([[344.6973, 23.1085, 637.1817, 374.2748],[ 12.2690, 51.9104, 316.8564, 472.4341],[ 38.5870, 70.0092, 176.7755, 118.1748]], device='cuda:0')}
label2id (Dict): Dictionary of label to id mapping

Returns:
Dict: Output of zero-shot object detection
e.g. {'scores': tensor([0.4786, 0.4379, 0.4760], device='cuda:0'), 'labels': [1, 1, 2], 'boxes': tensor([[344.6973, 23.1085, 637.1817, 374.2748],[ 12.2690, 51.9104, 316.8564, 472.4341],[ 38.5870, 70.0092, 176.7755, 118.1748]], device='cuda:0')}

"""
# convert center to corners format
torch_label = []
for prediction in predictions:
scores = prediction["scores"]
device = scores.device
labels = prediction["labels"]
for label in labels:
if label in label2id:
torch_label.append(label2id[label])
else:
# Give background class
torch_label.append(0)
prediction["labels"] = torch.Tensor(torch_label).to(dtype=torch.int32).to(device)

return predictions
Copy link

Choose a reason for hiding this comment

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

@SangbumChoi if this is the zero-shot to coco converted, your repo is same with here.

Copy link

Choose a reason for hiding this comment

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

I also checkout the pr, and got the same result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was meaning I have my own code which is not commited here

Comment on lines +581 to +588
validation_transform_batch = partial(
augment_and_transform_batch,
transform=validation_transform,
processor=processor,
id2label=id2label,
label2id=label2id,
random_text_prompt=True,
)
Copy link

Choose a reason for hiding this comment

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

I have some confusion here. Why with random_text_prompt=True do I get bad results?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be deprecated. You understand correctly

Choose a reason for hiding this comment

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

@SangbumChoi thanks a ton for your work so far! I am looking to use this code to finetune GroundingDINO for a critical medical imaging project - and from my understanding of the thread here I am noting some issues I should be careful about. Do you have any points on 'things to remember' when using this code? Or if you have a latest clean version would be super useful to us if you can commit those updates. One other option I am considering is finetuning GroundingDINO using this repo; but would still prefer finetuning the model off transformers. Thanks!!

@JamesEmi
Copy link

@qubvel @EduardoPach thanks for your work on this so far (and in general for the wider HF ecosystem :) ). Ended up here after digging around for a train script entrypoint to use for finetuning grounding dino tiny. Any updates on why this PR is not merged to the main branch? @EduardoPach could you comment on what training script you used to finetune grounding dino tiny to get this model? Thanks in advance!!!

@SangbumChoi SangbumChoi marked this pull request as draft February 28, 2025 08:49
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.

Zero-shot finetuning examples
6 participants