Spaces:
Sleeping
Sleeping
File size: 4,561 Bytes
423a25e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# Transformer-Based Object Detection
This project implements an **object detection system** powered by state-of-the-art **transformer models**, including **DETR** (DEtection TRansformer) and **YOLOS** (You Only Look One-level Series). The system supports object detection from both uploaded images and image URLs. It comes with a user-friendly **Gradio web interface** and a **FastAPI API** for automated processing.
Try the demo on Hugging Face: \[**Demo Link**].
## Supported Models
Here’s a list of the available models for different detection and segmentation tasks:
### **DETR (DEtection TRansformer)**:
* **facebook/detr-resnet-50**: Fast and efficient object detection.
* **facebook/detr-resnet-101**: More accurate, but slower than ResNet-50.
* **facebook/detr-resnet-50-panoptic** *(currently has bugs)*: For panoptic segmentation. Detects and segments scenes.
* **facebook/detr-resnet-101-panoptic** *(currently has bugs)*: High-accuracy segmentation for complex scenes.
### **YOLOS (You Only Look One-level Series)**:
* **hustvl/yolos-tiny**: Lightweight and quick. Ideal for environments with limited resources.
* **hustvl/yolos-base**: Strikes a balance between speed and accuracy.
## Key Features
* **Image Upload**: Upload an image from your device to run detection via the Gradio interface.
* **URL Input**: Input an image URL for detection through Gradio or the FastAPI.
* **Model Selection**: Choose between DETR and YOLOS models for object detection or segmentation.
* **Object Detection**: Detects objects and shows bounding boxes with confidence scores.
* **Panoptic Segmentation**: Available with certain models for detailed scene segmentation using colored masks.
* **Image Info**: Displays metadata such as size, format, aspect ratio, and file size.
* **API Access**: Use the FastAPI `/detect` endpoint for programmatic processing.
## How to Get Started
### 1. **Cloning the Repository**
#### Prerequisites:
* Python 3.8 or higher
* `pip` to install dependencies
#### Clone and Set Up:
```bash
git clone https://github.com/NeerajCodz/ObjectDetection.git
cd ObjectDetection
pip install -r requirements.txt
```
#### Run the Application:
* **FastAPI**: Start the server with:
```bash
uvicorn objectdetection:app --reload
```
* **Gradio Interface**: Launch with:
```bash
python app.py
```
#### Access the Application:
* **FastAPI**: Navigate to `http://localhost:8000` to interact with the API or view the Swagger UI.
* **Gradio**: The Gradio interface will be available at `http://127.0.0.1:7860` (URL will show up in the console).
### 2. **Running via Docker**
#### Prerequisites:
* Install Docker on your machine (if you haven’t already).
#### Set Up with Docker:
1. Clone the repository (if you haven’t):
```bash
git clone https://github.com/NeerajCodz/ObjectDetection.git
cd ObjectDetection
```
2. Build the Docker image:
```bash
docker build -t objectdetection:latest .
```
3. Run the container:
```bash
docker run -p 5000:5000 objectdetection:latest
```
Access the app at `http://localhost:5000`.
### 3. **Try the Online Demo**
Test the demo directly on Hugging Face’s Spaces:
[**Object Detection Demo**](https://huggingface.co/spaces/NeerajCodz/ObjectDetection)
## API Usage
Use the `/detect` endpoint in FastAPI for image processing.
### **POST** `/detect`
Parameters:
* **file** *(optional)*: Image file (must be of type image/\*).
* **image\_url** *(optional)*: URL of the image.
* **model\_name** *(optional)*: Choose the model (e.g., `facebook/detr-resnet-50`, `hustvl/yolos-tiny`, etc.).
Example Request Body:
```json
{
"image_url": "https://example.com/image.jpg",
"model_name": "facebook/detr-resnet-50"
}
```
Example Response:
```json
{
"image_url": "data:image/png;base64,...",
"detected_objects": ["person", "car"],
"confidence_scores": [0.95, 0.87],
"unique_objects": ["person", "car"],
"unique_confidence_scores": [0.95, 0.87]
}
```
## Development & Contributions
To contribute or modify the project:
1. Clone the repository:
```bash
git clone https://github.com/NeerajCodz/ObjectDetection.git
cd ObjectDetection
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run FastAPI or Gradio:
* **FastAPI**: `uvicorn objectdetection:app --reload`
* **Gradio**: `python app.py`
Access the app on `http://localhost:8000` (FastAPI) or the Gradio interface at the displayed URL.
## Contributing
Contributions are always welcome! Feel free to submit pull requests or open issues for bug fixes, new features, or improvements.
|