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

Added RTDETR model to inference #558

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Bhavay-2001
Copy link
Contributor

Description

PR for #546

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested, please provide a testcase or example of how you tested the change?

Any specific deployment considerations

Docs

  • Docs updated? What were the changes:

@grzegorz-roboflow
Copy link
Contributor

Hi @Bhavay-2001, thank you for providing this PR! I'd love to test it, can you share python code with inference performed using this model?

@Bhavay-2001
Copy link
Contributor Author

Hi @grzegorz-roboflow, I haven't tested it myself. I got the code from here. I have created the notebook that test this code.

I have just tried to convert that code to a file.

@Bhavay-2001
Copy link
Contributor Author

Hi @grzegorz-roboflow, pls let me know what changes needs to be done.


DEVICE = "cuda:0" if torch.cuda.is_available() else "cpu"

class RTDETR(RoboflowCoreModel):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should subclass RoboflowInferenceModelor even more ideally TransformerModel after a light refactor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Bhavay-2001
Copy link
Contributor Author

Hi @probicheaux, can you pls provide a detailed review?
Thanks

@Bhavay-2001 Bhavay-2001 marked this pull request as ready for review August 9, 2024 06:29
@Bhavay-2001
Copy link
Contributor Author

Hi @grzegorz-roboflow, PR is ready for review. Can you please check this.
Thanks

Copy link
Collaborator

@probicheaux probicheaux 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 your contribution, we will upload some weights and test this out. Some unit tests/integration tests will also need to be added

from inference.models.transformers.transformers import TransformerModel
from inference.core.utils.image_utils import load_image_rgb

DEVICE = "cuda:0" if torch.cuda.is_available() else "cpu"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not needed, self.device should be set on the TransformerModel

self.api_key = API_KEY
self.dataset_id, self.version_id = model_id.split("/")
self.cache_dir = os.path.join(MODEL_CACHE_DIR, self.endpoint + "/") # "PekingU/rtdetr_r50vd"
dtype = torch.bfloat16
Copy link
Collaborator

Choose a reason for hiding this comment

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

bfloat16 shouldn't be hardcoded here, bfloat16 is only supported on gpus with compute capability >= 8.0

Comment on lines +20 to +22
self.model_id = model_id
self.endpoint = model_id
self.api_key = API_KEY
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think these 3 lines are needed, this is set on RoboflowInferenceModel

self.cache_dir,
torch_dtype=dtype,
device_map=DEVICE,
revision="bfloat16",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can upload float16 weights to a Roboflow project and load from there

self.dataset_id, self.version_id = model_id.split("/")
self.cache_dir = os.path.join(MODEL_CACHE_DIR, self.endpoint + "/") # "PekingU/rtdetr_r50vd"
dtype = torch.bfloat16
self.model = RTDetrForObjectDetection.from_pretrained(
Copy link
Collaborator

Choose a reason for hiding this comment

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

revision="bfloat16",
).eval()

self.processor = RTDetrImageProcessor.from_pretrained(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment for class property

@yeldarby
Copy link
Contributor

Hey @Bhavay-2001! We greatly appreciate your contribution and thank you so much for submitting this PR.

I talked with the team and we are planning on incorporating fine-tuning of RT-DETR more tightly into Roboflow shortly so we need to adapt the inference integration to be compatible with the output of our training process.

This PR is a great start & we’ll likely continue working from it towards a release but we won’t be able to do that for a little while until the backend is more concrete. Best path forward in the meantime would be to use it via a plugin or fork. (Apologies for the inconvenience; we’ll update you when we have more to share on our end!)

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