update project structure and improve scripts
This commit is contained in:
+131
-64
@@ -1,75 +1,142 @@
|
||||
# Memory Module Detection API Documentation
|
||||
# Memory Module Detection System
|
||||
|
||||
## Overview
|
||||
Flask API for detecting memory modules on motherboard images using YOLOv8. Processes uploaded images and returns bounding box coordinates with confidence scores.
|
||||
A computer vision system for detecting memory modules in images and videos using YOLO object detection.
|
||||
|
||||
## Base URL
|
||||
`http://localhost:5000`
|
||||
## Features
|
||||
|
||||
## Endpoints
|
||||
- **Image Detection**: Upload images to detect memory modules
|
||||
- **Video Processing**: Process video files frame-by-frame
|
||||
- **Bounding Box Visualization**: See detected objects with confidence scores
|
||||
- **Detailed Analytics**: Get detection statistics and metrics
|
||||
- **REST API**: Fully documented API endpoints
|
||||
- **Web Interface**: User-friendly browser interface
|
||||
|
||||
### 1. Root Endpoint
|
||||
**GET** `/`
|
||||
- Returns the test interface HTML page
|
||||
- Response: `test.html`
|
||||
## Requirements
|
||||
|
||||
### 2. Image Detection
|
||||
**POST** `/detect`
|
||||
- Accepts image uploads for processing
|
||||
- **Request:**
|
||||
```bash
|
||||
curl -X POST -F "image=@motherboard.jpg" http://localhost:5000/detect
|
||||
```
|
||||
- **Successful Response (200):**
|
||||
```json
|
||||
{
|
||||
"detections": [
|
||||
{
|
||||
"box": [x1,y1,x2,y2],
|
||||
"confidence": 0.95,
|
||||
"class": 0
|
||||
}
|
||||
],
|
||||
"result_image": "/results/filename.jpg"
|
||||
}
|
||||
```
|
||||
- **Error Responses:**
|
||||
- `400 Bad Request`: Missing/invalid image file
|
||||
- `500 Server Error`: Processing failure
|
||||
- Python 3.8+
|
||||
- CUDA-enabled GPU (recommended for best performance)
|
||||
- Docker (optional)
|
||||
|
||||
### 3. Result Retrieval
|
||||
**GET** `/results/<filename>`
|
||||
- Returns annotated image with bounding boxes
|
||||
- Example: `http://localhost:5000/results/out1.jpg`
|
||||
## Installation
|
||||
|
||||
## Request/Response Examples
|
||||
**Sample Request:**
|
||||
```python
|
||||
import requests
|
||||
response = requests.post(
|
||||
'http://localhost:5000/detect',
|
||||
files={'image': open('motherboard.jpg', 'rb')}
|
||||
)
|
||||
### 1. Clone the repository
|
||||
```bash
|
||||
git clone https://github.com/yourusername/memory-detection.git
|
||||
cd memory-detection
|
||||
```
|
||||
|
||||
**Sample Response:**
|
||||
```json
|
||||
{
|
||||
"detections": [
|
||||
{
|
||||
"box": [541,567,661,265],
|
||||
"confidence": 0.98,
|
||||
"class": 0
|
||||
}
|
||||
],
|
||||
"result_image": "/results/out1.jpg"
|
||||
}
|
||||
### 2. Set up Python environment
|
||||
```bash
|
||||
python -m venv venv
|
||||
source venv/bin/activate # Linux/MacOS
|
||||
venv\Scripts\activate # Windows
|
||||
```
|
||||
|
||||
## Technical Specifications
|
||||
| Parameter | Value |
|
||||
|--------------------|---------------------------|
|
||||
| Model | YOLOv8n (custom-trained) |
|
||||
| Input Formats | JPG/PNG |
|
||||
| Recommended Resolution | 416px |
|
||||
| Processing Time (CPU) | 200-500ms per image |
|
||||
### 3. Install dependencies
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 4. Download YOLO model
|
||||
Place your `.pt` model file in the `models/` directory and update `config.py` with the correct path.
|
||||
|
||||
## Configuration
|
||||
|
||||
Edit `config.py` to customize:
|
||||
|
||||
- Model paths
|
||||
- Confidence thresholds
|
||||
- File size limits
|
||||
- Server host/port settings
|
||||
|
||||
## Running the Application
|
||||
|
||||
### Development Mode
|
||||
```bash
|
||||
python backend/app.py
|
||||
```
|
||||
|
||||
### Production Mode (with Gunicorn)
|
||||
```bash
|
||||
gunicorn --bind 0.0.0.0:5000 backend.app:app
|
||||
```
|
||||
|
||||
### Docker
|
||||
```bash
|
||||
docker build -t memory-detection .
|
||||
docker run -p 5000:5000 memory-detection
|
||||
```
|
||||
|
||||
## API Documentation
|
||||
|
||||
### Endpoints
|
||||
|
||||
| Endpoint | Method | Description |
|
||||
|----------|--------|-------------|
|
||||
| `/` | GET | Web interface |
|
||||
| `/api/health` | GET | Service health check |
|
||||
| `/api/v1/detect` | POST | Detect memory modules in image |
|
||||
| `/api/v1/detect/video` | POST | Process video for detections |
|
||||
| `/api/v1/results/<filename>` | GET | Retrieve result images |
|
||||
|
||||
### Example Requests
|
||||
|
||||
**Image Detection**:
|
||||
```bash
|
||||
curl -X POST -F "image=@test.jpg" http://localhost:5000/api/v1/detect
|
||||
```
|
||||
|
||||
**Video Processing**:
|
||||
```bash
|
||||
curl -X POST -F "video=@test.mp4" -F "fps=2" -F "max_frames=100" http://localhost:5000/api/v1/detect/video
|
||||
```
|
||||
|
||||
## Web Interface
|
||||
|
||||
Access the web interface at `http://localhost:5000`:
|
||||
|
||||
1. **Upload Images**:
|
||||
- Supported formats: JPG, PNG
|
||||
- Max file size: 10MB (configurable)
|
||||
|
||||
2. **Process Videos**:
|
||||
- Supported formats: MP4, AVI, MOV
|
||||
- Adjustable FPS and frame limits
|
||||
- Detailed frame-by-frame results
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
memory-detection/
|
||||
├── backend/ # Core application
|
||||
│ ├── app.py # Flask application
|
||||
│ ├── config.py # Configuration
|
||||
│ ├── detector.py # YOLO detection logic
|
||||
│ ├── exceptions.py # Custom exceptions
|
||||
│ ├── utils.py # Helper functions
|
||||
│ ├── video_processor.py # Video handling
|
||||
│ └── templates/ # Frontend templates
|
||||
│ └── index.html # Web interface
|
||||
├── models/ # YOLO model files
|
||||
├── uploads/ # Temporary upload storage
|
||||
├── results/ # Detection result images
|
||||
├── tests/ # Unit tests
|
||||
├── requirements.txt # Python dependencies
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Common Issues**:
|
||||
|
||||
1. **Model not loading**:
|
||||
- Verify model path in `config.py`
|
||||
- Check file permissions
|
||||
|
||||
2. **CUDA errors**:
|
||||
- Ensure compatible CUDA version is installed
|
||||
- Try CPU-only mode by modifying detector.py
|
||||
|
||||
3. **File upload issues**:
|
||||
- Check `MAX_FILE_SIZE` in config
|
||||
- Verify file extensions are allowed
|
||||
|
||||
Reference in New Issue
Block a user