-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bce4dda
commit b9d38bc
Showing
6 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: CI checks | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
linting_testing: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
submodules: true | ||
- name: Set up Python 3 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements_dev.txt | ||
- name: Run black | ||
run: | | ||
black --check main.py | ||
- name: Run pylint | ||
run: | | ||
pylint main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- | ||
name: Login to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- | ||
name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
file: Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/mo-rise/crowsnest-processor-video-yolov5:latest | ||
ghcr.io/mo-rise/crowsnest-processor-video-yolov5:${{ github.event.release.tag_name }} | ||
- | ||
name: Image digest | ||
run: echo ${{ steps.docker_build.outputs.digest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM python:3.9-slim | ||
|
||
COPY requirements.txt requirements.txt | ||
|
||
RUN pip3 install -r requirements.txt | ||
|
||
WORKDIR /app | ||
|
||
COPY main.py main.py | ||
|
||
CMD ["python3", "main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"""Main entrypoint for this application""" | ||
import warnings | ||
import logging | ||
|
||
import yolov5 | ||
from vidgear.gears import CamGear | ||
from vidgear.gears import WriteGear | ||
|
||
from environs import Env | ||
|
||
env = Env() | ||
|
||
SOURCE_STREAM: str = env("SOURCE_STREAM") | ||
SINK_STREAM: str = env("SINK_STREAM") | ||
YOLOV5_MODEL: str = env("YOLOV5_MODEL", default="yolov5s.pt") | ||
YOLOV5_CONFIDENCE_THRESHOLD: float = env.float( | ||
"YOLOV5_CONFIDENCE_THRESHOLD", default=0.5, validate=lambda x: 0.0 <= x <= 1.0 | ||
) | ||
YOLOV5_MAX_DETECTIONS: int = env.int( | ||
"YOLOV5_MAX_DETECTIONS", default=10, validate=lambda x: x > 0 | ||
) | ||
LOG_LEVEL = env.log_level("LOG_LEVEL", logging.WARNING) | ||
|
||
verbose = LOG_LEVEL <= logging.INFO | ||
|
||
# Setup logger | ||
logging.basicConfig(level=LOG_LEVEL) | ||
logging.captureWarnings(True) | ||
warnings.filterwarnings("once") | ||
LOGGER = logging.getLogger("crowsnest-processor-video-yolov5") | ||
|
||
### Configure yolov5 model | ||
MODEL = yolov5.load(YOLOV5_MODEL) | ||
|
||
MODEL.conf = 0.25 # NMS confidence threshold | ||
MODEL.iou = 0.45 # NMS IoU threshold | ||
MODEL.agnostic = False # NMS class-agnostic | ||
MODEL.multi_label = False # NMS multiple labels per box | ||
MODEL.max_det = 10 # maximum number of detections per image | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
try: | ||
|
||
# Open source stream, we always want the last frame since we | ||
# cant guarantee to keep up with the source frame rate | ||
source = CamGear( | ||
source=SOURCE_STREAM, | ||
colorspace="COLOR_BGR2RGB", | ||
logging=verbose, | ||
**{"THREADED_QUEUE_MODE": False} | ||
).start() | ||
|
||
sink = WriteGear( | ||
output_filename=SINK_STREAM, | ||
logging=verbose, | ||
**{"-f": "rtsp", "-rtsp_transport": "tcp"} | ||
) | ||
|
||
# Frame-wise loop | ||
while True: | ||
frame = source.read() | ||
if frame is None: | ||
break | ||
|
||
# Do object detection | ||
# pylint: disable=not-callable | ||
result: yolov5.models.common.Detections = MODEL( | ||
frame, size=max(frame.shape) | ||
) | ||
|
||
annotated_frame = result.render()[0] | ||
sink.write(annotated_frame) | ||
|
||
except Exception: # pylint: disable=broad-except | ||
LOGGER.exception("Fundamental failure...") | ||
|
||
finally: | ||
source.stop() | ||
sink.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vidgear | ||
yolov5 | ||
environs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
black | ||
pylint | ||
-r requirements.txt |