# 🚀 Object Detection with Transformer Models This project provides a robust object detection system leveraging state-of-the-art transformer models, including **DETR (DEtection TRansformer)** and **YOLOS (You Only Look One-level Series)**. The system supports object detection and panoptic segmentation from uploaded images or image URLs. It features a user-friendly **Gradio** web interface for interactive use and a **FastAPI** endpoint for programmatic access. Try the online demo on Hugging Face Spaces: [Object Detection Demo](https://huggingface.co/spaces/NeerajCodz/ObjectDetection). ## Models Supported The application supports the following models, each tailored for specific detection or segmentation tasks: - **DETR (DEtection TRansformer)**: - `facebook/detr-resnet-50`: Fast and accurate object detection with a ResNet-50 backbone. - `facebook/detr-resnet-101`: Higher accuracy object detection with a ResNet-101 backbone, slower than ResNet-50. - `facebook/detr-resnet-50-panoptic`: Panoptic segmentation with ResNet-50 (note: may have stability issues). - `facebook/detr-resnet-101-panoptic`: Panoptic segmentation with ResNet-101 (note: may have stability issues). - **YOLOS (You Only Look One-level Series)**: - `hustvl/yolos-tiny`: Lightweight and fast, ideal for resource-constrained environments. - `hustvl/yolos-base`: Balances speed and accuracy for object detection. ## Features - **Image Upload**: Upload images via the Gradio interface for object detection. - **URL Input**: Provide image URLs for detection through the Gradio interface or API. - **Model Selection**: Choose between DETR and YOLOS models for detection or panoptic segmentation. - **Object Detection**: Highlights detected objects with bounding boxes and confidence scores. - **Panoptic Segmentation**: Supports scene segmentation with colored masks (DETR panoptic models). - **Image Properties**: Displays metadata like format, size, aspect ratio, file size, and color statistics. - **API Access**: Programmatically process images via the FastAPI `/detect` endpoint. - **Flexible Deployment**: Run locally, in Docker, or in cloud environments like Google Colab. ## How to Use ### 1. **Local Setup (Git Clone)** Follow these steps to set up the application locally: #### Prerequisites - Python 3.8 or higher - `pip` for installing dependencies - Git for cloning the repository #### Clone the Repository ```bash git clone https://github.com/NeerajCodz/ObjectDetection cd ObjectDetection ``` #### Install Dependencies Install required packages from `requirements.txt`: ```bash pip install -r requirements.txt ``` #### Run the Application Launch the Gradio interface: ```bash python app.py ``` To enable the FastAPI server: ```bash python app.py --enable-fastapi ``` #### Access the Application - **Gradio**: Open the URL displayed in the console (typically `http://127.0.0.1:7860`). - **FastAPI**: Navigate to `http://localhost:8000` for the API or Swagger UI (if enabled). ### 2. **Running with Docker** Use Docker for a containerized setup. #### Prerequisites - Docker installed on your machine. Download from [Docker's official site](https://www.docker.com/get-started). #### Pull the Docker Image Pull the pre-built image from Docker Hub: ```bash docker pull neerajcodz/objectdetection:latest ``` #### Run the Docker Container Run the application on port 8080: ```bash docker run -d -p 8080:80 neerajcodz/objectdetection:latest ``` Access the interface at `http://localhost:8080`. #### Build and Run the Docker Image To build the Docker image locally: 1. Ensure you have a `Dockerfile` in the repository root (example provided in the repository). 2. Build the image: ```bash docker build -t objectdetection:local . ``` 3. Run the container: ```bash docker run -d -p 8080:80 objectdetection:local ``` Access the interface at `http://localhost:8080`. ### 3. **Demo** Try the demo on Hugging Face Spaces: [Object Detection Demo](https://huggingface.co/spaces/NeerajCodz/ObjectDetection) ## Command-Line Arguments The `app.py` script supports the following command-line arguments: - `--gradio-port `: Specify the port for the Gradio UI (default: 7860). - Example: `python app.py --gradio-port 7870` - `--enable-fastapi`: Enable the FastAPI server (disabled by default). - Example: `python app.py --enable-fastapi` - `--fastapi-port `: Specify the port for the FastAPI server (default: 8000). - Example: `python app.py --enable-fastapi --fastapi-port 8001` - `--confidence-threshold