CV / YOLOv5

YOLOv5s_seg

Versión estándar de la serie YOLOv5s_Seg de segmentación de instancias, ligera y eficiente, diseñada para segmentación a nivel de píxel y predicción de máscaras con particionamiento regional preciso, ideal para despliegue en el borde.

330 descargas
Tamaño
~11.3MB
Memoria
2GB+
Precisión
INT8

Elige el dispositivo que estás usando. La guía de configuración y la documentación se actualizarán en consecuencia.

Primeros pasos

Desplegar
sudo docker run --rm \
  --name rk3588-yolov5s-seg \
  --privileged \
  --net=host \
  -e PYTHONUNBUFFERED=1 \
  -e RKNN_LOG_LEVEL=0 \
  --device /dev/video0:/dev/video0 \
  --device /dev/dri/renderD128:/dev/dri/renderD128 \
  -v /proc/device-tree/compatible:/proc/device-tree/compatible \
  ghcr.io/seeed-projects/recomputer-rk-cv/rk3588-yolov5_seg:latest \
  python3 web_detection.py --model_path model/yolov5s-seg.rknn --video video/test.mp4

API REST

Usa la API REST para ejecutar inferencia. Copia los comandos siguientes.

Curl
curl -X POST "http://127.0.0.1:8000/api/models/yolov5_seg/predict" -F "realtime=true"
# Or without file parameters
curl -X POST "http://127.0.0.1:8000/api/models/yolov5_seg/predict"
Python
import requests
import json
resp = requests.post(
    "http://127.0.0.1:8000/api/models/yolov5_seg/predict",
    json={},
    timeout=30
)
result = resp.json()
print(json.dumps(result, indent=2, ensure_ascii=False))

Detalles del modelo

Quick Start

1. Install Docker

Run the following commands on the development board to install Docker:

bash
# Download installation script
curl -fsSL https://get.docker.com -o get-docker.sh
# Install using Aliyun mirror source
sudo sh get-docker.sh --mirror Aliyun
# Start Docker and enable auto-start on boot
sudo systemctl enable docker
sudo systemctl start docker

2. Run the Project (One command, dual-mode preview)

This project supports previewing through a "web browser". The project can be run with a single command. Additionally, a Fast-API interface is provided to facilitate users' customized development and testing.

Step A: Pull Images

bash
sudo docker pull ghcr.io/Seeed-Projects/recomputer-rk-cv/rk3588-yolov5_seg:latest
sudo docker pull ghcr.io/Seeed-Projects/recomputer-rk-cv/rk3576-yolov5_seg:latest

Step B: Run with One Click

For RK3588:

bash
sudo docker run --rm --privileged --net=host \
    -e PYTHONUNBUFFERED=1 \
    -e RKNN_LOG_LEVEL=0 \
    --device /dev/video0:/dev/video0 \
    --device /dev/dri/renderD128:/dev/dri/renderD128 \
    -v /proc/device-tree/compatible:/proc/device-tree/compatible \
    ghcr.io/seeed-projects/recomputer-rk-cv/rk3588-yolov5_seg:latest \
    python3 web_detection.py --model_path model/yolov5n_seg.rknn --video video/test.mp4

For RK3576:

bash
sudo docker run --rm --privileged --net=host \
    -e PYTHONUNBUFFERED=1 \
    -e RKNN_LOG_LEVEL=0 \
    --device /dev/video0:/dev/video0 \
    --device /dev/dri/renderD128:/dev/dri/renderD128 \
    -v /proc/device-tree/compatible:/proc/device-tree/compatible \
    ghcr.io/seeed-projects/recomputer-rk-cv/rk3576-yolov5_seg:latest \
    python3 web_detection.py --model_path model/yolov5n_seg.rknn --video video/test.mp4

Access via: http://<Board_IP>:8000

Note: If you need custom classes, you can add -v $(pwd)/class_config.txt:/app/class_config.txt \ mount and --class_path parameter. The program defaults to COCO 80 classes.

Example:

bash
sudo docker run --rm --privileged --net=host \
    -e PYTHONUNBUFFERED=1 \
    -e RKNN_LOG_LEVEL=0 \
    -v $(pwd)/class_config.txt:/app/class_config.txt \
    --device /dev/video0:/dev/video0 \
    --device /dev/dri/renderD128:/dev/dri/renderD128 \
    -v /proc/device-tree/compatible:/proc/device-tree/compatible \
    ghcr.io/seeed-projects/recomputer-rk-cv/rk3588-yolov5_seg:latest \
    python3 web_detection.py --model_path model/yolov5n-seg.rknn --video video/test.mp4 --class_path class_config.txt

🔌 API Documentation

This project provides RESTful interfaces compatible with the Ultralytics Cloud API standard, supporting instance segmentation via image, video uploads or direct camera calls.

1. Model Inference Interface (Predict)

Endpoint: POST /api/models/yolov5_seg/predict

Request Parameters (Multipart/Form-Data):

  • file: (Optional) Image file to be detected.
  • video: (Optional) MP4 video file to be detected.
  • timestamp: (Optional) Timestamp in the video file (seconds), returns detection results for the frame at that point. Default is 0.
  • realtime: (Optional) Boolean. If true or if no file/video parameters are provided, returns detection results for the current camera frame.
  • conf: (Optional) Confidence threshold for a single request, range 0.0-1.0.
  • iou: (Optional) NMS IOU threshold for a single request, range 0.0-1.0.

Usage Examples:

1. Image Detection:

bash
curl -X POST "http://127.0.0.1:8000/api/models/yolov5_seg/predict" -F "file=@/home/cat/001.jpg"

2. Video Specific Frame Detection:

bash
curl -X POST "http://127.0.0.1:8000/api/models/yolov5_seg/predict" -F "video=@/home/cat/test.mp4" -F "timestamp=5.5"

3. Get Current Camera Frame Detection:

bash
curl -X POST "http://127.0.0.1:8000/api/models/yolov5_seg/predict" -F "realtime=true"
# Or without file parameters
curl -X POST "http://127.0.0.1:8000/api/models/yolov5_seg/predict"

Response Format (JSON):

json
{
  "success": true,
  "source": "video frame at 5.5s",
  "predictions": [
    {
      "class": "person",
      "confidence": 0.92,
      "box": { "x1": 100, "y1": 200, "x2": 300, "y2": 500 },
      "polygons": [
        [100, 200], [150, 210], [160, 300]
      ]
    }
  ],
  "image": { "width": 1280, "height": 720 }
}

2. System Configuration Interface (Config)

Used to dynamically adjust thresholds for real-time video streams and default inference.

Get Current Configuration

  • Endpoint: GET /api/config
  • Response: {"obj_thresh": 0.25, "nms_thresh": 0.45}

Update System Configuration

  • Endpoint: POST /api/config
  • Request Body (JSON): {"obj_thresh": 0.3, "nms_thresh": 0.5}
  • Response: {"status": "success"}

3. Real-time Video Stream Interface (Video Feed)

Get real-time MJPEG video stream with detection boxes and segmentation masks drawn, can be directly embedded in HTML <img> tags.

  • Endpoint: GET /api/video_feed
  • Example Usage: <img src="http://<Board_IP>:8000/api/video_feed">

🛠️ Developer Guide (Production Recommendations)

Code Description

  • web_detection.py:
    • Dual-mode Support: Integrates FastAPI, supporting both local rendering and MJPEG streaming output.
    • Environment Adaptive: Automatically detects the DISPLAY environment variable, silently skipping GUI initialization if not present.
    • RKNN Inference: Encapsulates RKNN initialization, model loading, and multi-core inference logic.
    • Dynamic Loading: Supports dynamic class configuration loading via --class_path.
    • Post-processing: High-performance Numpy-based bounding box decoding, NMS, and contour extraction (cv2.findContours).

Modifying Models

  1. Place the trained and converted .rknn model into the model/ directory.
  2. Add the --model_path argument to the running command to point to the new model.