Object Detection with DETR (ResNet-101) - Gradio Application
Overview
This project leverages the DETR (Detection Transformer) model with a ResNet-101 backbone for object detection. The application is built using Gradio, a user-friendly library for creating interactive machine learning interfaces. Users can upload an image and receive object detection results, including bounding boxes and labels for detected objects.
Components
- DETR Model and Image Processor
◦ The DetrImageProcessor and DetrForObjectDetection classes from the transformers library are used to load the pre-trained DETR model and its associated image processor.
◦ The model and processor are both sourced from the 'facebook/detr-resnet-101' repository.
- Object Detection Function (object_detection)
◦ Preprocessing: The input image is processed using the DetrImageProcessor.
◦ Inference: The processed image is passed through the DETR model to perform object detection.
◦ Post-processing: The results are post-processed to extract bounding boxes, labels, and scores. Only detections with a score above 0.9 are considered.
◦ Visualization: The detected objects are visualized by plotting bounding boxes and labels on the image using matplotlib. The resulting image is then saved to an in-memory buffer.
- Gradio Interface
◦ A Gradio interface is defined to allow users to upload an image and view the object detection results.
◦ The Interface class is used to set up the application, with the object_detection function as the main prediction function.
◦ The interface is configured with PIL image inputs and outputs, and is given a title and description for clarity.
- Launching the Application
◦ The application is launched with the demo.launch() method, making it accessible for user interaction.
Usage
To use this application, simply upload an image through the Gradio interface. The application will process the image, detect objects, and display the results with bounding boxes and labels for each detected object.