pytorch / serve

Serve, optimize and scale PyTorch models in production
https://pytorch.org/serve/
Apache License 2.0
4.18k stars 855 forks source link

Add Detectron2 Support to TorchServe Object Detection Examples #3344

Open Mudassar-MLE opened 4 days ago

Mudassar-MLE commented 4 days ago

🚀 The feature

Implement support for Detectron2 models within the TorchServe object detection examples. This includes:

  1. Developing a custom handler that works seamlessly with both CPU and GPU environments.
  2. Providing sample configuration files (YAML files) as examples for model deployment.
  3. Ensuring compatibility with both pre-trained models from the Detectron2 Model Zoo and custom fine-tuned models.
  4. Updating documentation to guide users on serving Detectron2 models using TorchServe.

Motivation:

Detectron2 is a widely used open-source object detection library developed by Facebook AI Research, licensed under the permissive Apache-2.0 license. This makes it highly suitable for commercial use without the legal complexities associated with more restrictive licenses. In contrast, competitor libraries like Ultralytics' YOLO models are licensed under the AGPL-3.0 license, which imposes stricter requirements and can be less favorable for commercial applications.

Companies seeking free and commercially friendly resources for object detection often prefer Detectron2. Currently, TorchServe provides examples for YOLOv8, Mask R-CNN, and Faster R-CNN but lacks support for Detectron2 models. While TorchServe offers an easy way to deploy models, developers unfamiliar with its internals or with integrating Detectron2 may find the process challenging.

Moreover, there is a lack of optimized scripts for serving Detectron2 models:

Pitch:

By adding support for Detectron2 to TorchServe:

I have already implemented a custom handler that addresses these issues, ensuring smooth deployment of Detectron2 models regardless of the training environment (CPU or GPU) and without requiring extensive configuration from the user. This contribution will be highly beneficial for users who wish to deploy Detectron2 models using TorchServe but may be unfamiliar with creating custom handlers or managing device compatibility.

Alternatives

While users can manually create custom handlers for Detectron2 models, this requires additional effort and can be a significant barrier for those unfamiliar with TorchServe's internals. New developers or individuals who are self-learning may find the process confusing and overwhelming. By adding official support and examples, we can greatly assist many developers, making it easier for them to deploy Detectron2 models without getting discouraged.

Existing Limitations:

Contribution:

I am willing to contribute my existing code to the TorchServe project and collaborate with the maintainers to ensure it meets all guidelines and quality standards. My goal is to make it easier for developers to deploy Detectron2 models using TorchServe, thereby enhancing the utility of both projects.

mreso commented 3 days ago

Hi @Mudassar-MLE thanks for your proposal, we're always happy to integrate community contributions to the examples. Please go ahead and create a PR. I would suggest placing the example under: examples/object_detector/detectron2

Mudassar-MLE commented 3 days ago

Hi @mreso Thanks for the opportunity! I’ll create the PR and place the example under examples/object_detector/detectron2 as suggested. Could you please assign this issue to me?