This is a Flask application for performing object detection. Supports using models in formats such as caffemodel, pb, t7, net, weights, bin, and onnx, and leverages the capabilities of OpenCV DNN module for efficient and accurate detection.
The Flask application provides two routes:
/ping
: Handles health checks and returns a JSON response indicating the health status./invocations
: Handles inference requests and returns a JSON response containing the inference results.
Before running the application, make sure you have the following prerequisites:
-
Python >= 3.9
-
Required dependencies see requirements.txt
- MODEL: (optional) Path to the model file.
- CONFIG: (optional) Path to the configuration file.
- CLASSES: (optional) Path to the file containing class names.
- GPU_SUPPORT: (default: False) Boolean indicating whether GPU support is enabled.
- FORWARD_PASS: (default: False) Boolean indicating response output from cv.dnn.Net.forward.
- SILENT_RUN: (optional) Run detector without returning object detection results.
- CONFIDENCE_THRESHOLD: (default: 0.5) Confidence threshold for object detection.
- NMS_THRESHOLD: (default: 0.5) Non-Maximum Suppression (NMS) threshold for object detection.
- MODEL_SERVER_WORKERS: (default: auto) Number of workers, defaults to number of cpu cores.
- MODEL_SERVER_TIMEOUT: (default: 60) Server timout in seconds.
- LOG_LEVEL: (default: WARNING) The application log level.
Note: If the MODEL or CONFIG are not defined, their values will be automatically determined based on predefined file extension patterns and files available in the current directory and its subdirectories.
bin/start-dev
Used for health checks and returns a JSON response indicating the health status of the application.
Example Response:
{
"status": "Healthy"
}
Used for performing object detection on an input image. It expects a POST request with image data in the request body. Its response contains the inference results, including the latency, in seconds, and labeled objects.
Example Requests:
curl -X POST -H 'Content-Type: image/jpeg' --data-binary '@image.jpg' '<application_url>/invocations'
wget -qO - --method POST --header 'Content-Type: image/jpeg' --body-file='/image.jpg' '<application_url>/invocations'
Example Response
{
"Model": "model.pb",
"Config": "config.cfg",
"VersionID": 1,
"Forward": false,
"GPUSupport": true,
"SilentRun": false,
"StartTime": 1632833372.123456,
"EndTime": 1632833372.987654,
"DetectionStartTime": 1632833372.456789,
"DetectionEndTime": 1632833372.987654,
"DetectionLatency": 0.5312,
"DetectionResults": [
{
"id": "person",
"confidence": 0.85,
"left": 120,
"top": 150,
"right": 320,
"bottom": 480
},
{
"id": "car",
"confidence": 0.92,
"left": 400,
"top": 200,
"right": 650,
"bottom": 450
}
]
}
- Model The model filename used for detection.
- Config The config filename used for detection.
- Version The current ocv-dnn-detector application version.
- ForwardPass If response output format is cv.dnn.Net.forward.
- GPUSupport If GPU support is enabled.
- SilentRun If detector ran without returning object detection results.
- StartTime The response start time POSIX timestamp.
- EndTime The response end time POSIX timestamp
- Latency The response latency in seconds.
- DetectionStartTime The object detection start time POSIX timestamp.
- DetectionEndTime The object detection end time POSIX timestamp.
- DetectionLatency The object detection latency in seconds.
- Results The object detection results.
The following models have been tested to work:
Copyright 2023 Alexander Rose. All Rights Reserved.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for more information.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.