Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user-story/1079-run-and-develop-otvision-in-docker-container #177

Draft
wants to merge 55 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3ceba5a
Create docker container and fix gui to run in it
briemla Oct 20, 2022
44c515f
Add devcontainer config for vscode
briemla Nov 11, 2022
f526c4f
Merge 1st-version into branch create-docker-container
randy-seng Nov 25, 2022
ca13cfe
Install gdal specific packages in docker container
randy-seng Nov 25, 2022
c9aa044
Add OTValidate to PYTHONPATH in docker container
randy-seng Nov 25, 2022
c342772
Add vscode extensions
briemla Dec 19, 2022
a065dee
Add otvision to pythonpath
briemla Dec 19, 2022
eaa53b9
Fix pip version
briemla Dec 19, 2022
da2f97d
Pin versions and user newer syntax
briemla Dec 19, 2022
38b5427
Merge remote-tracking branch 'origin/main' into create-docker-container
briemla Feb 2, 2023
a5316cc
Build docker container for detect with cuda
briemla Feb 3, 2023
34572e5
Fix unused import
briemla Feb 3, 2023
d915901
Use github as container registry
briemla Feb 3, 2023
c0c8084
Merge remote-tracking branch 'origin/main' into create-docker-container
briemla Feb 3, 2023
c5a5996
Separate deploy step
briemla Feb 6, 2023
5296113
Checkout code for deploy
briemla Feb 6, 2023
c0442b0
Update docker action version
briemla Feb 6, 2023
3a77a46
Revert changes in init
briemla Feb 22, 2023
800ce0e
Merge branch 'main' into create-docker-container
briemla Feb 22, 2023
85ee088
Clean up init file
briemla Feb 22, 2023
1e81d85
Clean up unsupported parameters
briemla Feb 22, 2023
e21c090
Update to python 3.10
briemla Feb 22, 2023
20624dc
Use config file to start detection
briemla Feb 22, 2023
da687ec
Add docker file for tracking
briemla Feb 23, 2023
80fef71
Build container for detect and track
briemla Feb 23, 2023
9843435
Fix incorrect variable reference
briemla Feb 23, 2023
f4e937c
Fix case sensitive data in ci script
briemla Feb 23, 2023
2d9e9b9
Python3.10 is in official ubuntu repository
briemla Feb 23, 2023
5c65925
Remove unused dependency
briemla Feb 23, 2023
1df569d
Remove dependencies
briemla Feb 23, 2023
fe28f0f
Deactivate tests in pipeline to speedup docker
briemla Feb 23, 2023
4d9012c
Use correct tag for containers
briemla Feb 23, 2023
57af63c
Fix multiline yaml strings
briemla Feb 23, 2023
cecf576
Fix multiline yaml strings
briemla Feb 23, 2023
03092ab
Reactivate tests before deployment
briemla Feb 23, 2023
89864c2
Build container in other order
briemla Feb 23, 2023
3d8b165
Merge branch 'main' into create-docker-container
briemla Feb 24, 2023
73e646d
Merge branch 'main' into create-docker-container
briemla Feb 27, 2023
9a51780
Merge branch 'main' into create-docker-container
briemla Mar 2, 2023
1b9afff
rename requirements text files
frunika Mar 8, 2023
59460aa
add moviepy to detect requirements
frunika Mar 8, 2023
8ddd36d
add detect and track requirements
frunika Mar 8, 2023
8f7322a
bump ipython version in detect requirements
frunika Mar 8, 2023
166107e
use matrix instead of code duplication
frunika Mar 8, 2023
f7dd335
fix typo
frunika Mar 8, 2023
c8e2b4e
Merge branch 'main' into create-docker-container
briemla Mar 9, 2023
3673c43
Organize imports
briemla Mar 9, 2023
3f7ce6f
Use pytorch container
briemla Mar 9, 2023
5a2dda7
Remove unused devcontainer configuration
briemla Mar 9, 2023
0a857a2
Merge remote-tracking branch 'origin/main' into create-docker-container
briemla Mar 10, 2023
1c97ee8
Merge branch 'main' into create-docker-container
briemla Mar 13, 2023
401ab53
Merge branch 'main' into create-docker-container
briemla Mar 14, 2023
f3dc008
Merge branch 'main' into create-docker-container
briemla Mar 22, 2023
05fa01d
Add information about container usage
briemla Apr 20, 2023
bc2d00d
Merge pull request #235 from OpenTrafficCam/feature/1720-add-informat…
frunika Apr 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ on:
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
OTVISION_VERSION: 0.1.3

jobs:
test:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -46,3 +52,25 @@ jobs:
mypy .
- name: Test with pytest
run: pytest --cov=OTVision tests/
deploy:
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
package: ["detect", "track"]
steps:
- uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile.${{ matrix.package }}
push: true
tags: "${{ env.REGISTRY }}/opentrafficcam/otvision:\
${{ env.OTVISION_VERSION }}-${{ matrix.package }}"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ obj_train_data/*
*ffmpeg.exe
*ffmpeg.zip
tests/resources/
data
models
config
*.log
!test.log

Expand Down
4 changes: 0 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@
"args": [
"--path",
".tmp/debug/Testvideo_Cars-Cyclist_FR20_2020-01-01_00-00-00.mp4",
"--filetypes",
"mp4",
"--weights",
"yolov5s"
],
"windows": {
"args": [
"--path",
".tmp\\debug\\Testvideo_Cars-Cyclist_FR20_2020-01-01_00-00-00.mp4",
"--filetypes",
"mp4",
"--weights",
"yolov5s"
]
Expand Down
10 changes: 10 additions & 0 deletions Dockerfile.detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Use ubuntu as base image instead of a python image, because the rest of the layers
# will be the same in the cuda container
FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime
WORKDIR /OpenTrafficCam/OTVision
COPY requirements_detect.txt requirements_detect.txt
RUN pip install --no-cache-dir -r requirements_detect.txt
briemla marked this conversation as resolved.
Show resolved Hide resolved
ENV PYTHONPATH /OpenTrafficCam/OTVision
COPY OTVision OTVision
COPY detect.py .
ENTRYPOINT [ "python3.10", "detect.py", "--config", "config/user_config.otvision.yaml" ]
11 changes: 11 additions & 0 deletions Dockerfile.track
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use ubuntu as base image instead of a python image, because the rest of the layers
# will be the same in the cuda container
FROM python:3.10-bullseye
WORKDIR /OpenTrafficCam/OTVision
COPY requirements_track.txt requirements_track.txt
RUN pip3.10 install --no-cache-dir -r requirements_track.txt

ENV PYTHONPATH /OpenTrafficCam/OTVision
COPY OTVision OTVision
COPY track.py .
ENTRYPOINT [ "python3.10", "track.py", "--config", "config/user_config.otvision.yaml" ]
11 changes: 0 additions & 11 deletions OTVision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,3 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.


# TODO: Might need to change this
from .convert.convert import main as convert
from .detect.detect import main as detect
from .track.track import main as track
from .transform.transform import main as transform

# from .view.view import main as view

__all__: list = ["detect", "track", "convert", "transform"]
8 changes: 4 additions & 4 deletions OTVision/view/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import tkinter as tk

from OTVision.config import CONFIG, PAD
from OTVision.helpers.machine import ON_LINUX, ON_WINDOWS
from OTVision.helpers.machine import ON_WINDOWS
from OTVision.view.view_convert import FrameConvert
from OTVision.view.view_detect import FrameDetect
from OTVision.view.view_helpers import FrameFileTree, FrameRunChained
Expand All @@ -40,10 +40,10 @@ def __init__(self, **kwargs):
self.iconbitmap(CONFIG["GUI"]["OTC ICON"])
self.set_layout()
self.minsize(900, 620)
if ON_LINUX:
self.state("normal")
else:
try:
self.state("zoomed")
except tk.TclError:
self.attributes("-zoomed", True)

def set_layout(self):
for col in range(3):
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,62 @@ make PY_VERSION=3.10 run
make PY_VERSION=3.10 install
```

## Docker and container

In the long run it is planned to ship modules of OTVision as dedicated containers. Allowing users to configure the container input (mount data storage and config file) and run OTVision in a container environment. The container contains all necessary dependencies. There is no need to install anything more than the container engine. Therefore, two docker files are prepared.

The container were tested on a slurm cluster. Unfortunately, the container for detection grow extremly in size (about 5GB). Therefore, the approach was set on hold. For the next steps, the base images of the containers should be checked. nvidia, pytorch and yolo provide base containers to use for ml tasks. One of them could be a good start.

### Dockerfile.detect

`Dockerfile.detect` runs OTVisions detection. The following bash-Script shows the usage of the container. The name of the container and its version are parameters of the script together with the config for OTVision to run detection.

```bash
#!/bin/sh

if [ 3 -gt $# ]; then
echo "Please provide a container name and a version and a config name!"
exit 1
fi

host_input_dir="/scratch/ws/1/labr704e-p_trafficcam_t_30"
base_container="/OpenTrafficCam/OTVision"
home_dir=$(realpath ~)
container_folder=/projects/p_trafficcam/container
container_name=$1
container_version=$2
config_name=$3
execution_path=${container_folder}/"${container_name}"-"${container_version}".sif

singularity run --nv --contain \
-B "${home_dir}" \
--bind "${host_input_dir}"/config/"${config_name}":"${base_container}"/config/user_config.otvision.yaml:ro \
--bind "${host_input_dir}"/data:"${base_container}"/data \
--bind "${host_input_dir}"/models:"${base_container}"/models \
--pwd ${base_container}/ \
--env PYTHONPATH=${base_container} \
"${execution_path}"
```

### Dockerfile.track

`Dockerfile.track` runs OTVisions tracking. The following bash-Script shows the usage of the container.

```bash
#!/bin/sh

otvision_dir=../OTVision
host_input_dir=$(realpath ${otvision_dir})
base_container="/OpenTrafficCam/OTVision"
config_name="user_config.otvision.miovision.yaml"

docker run -it \
--mount type=bind,source="${host_input_dir}"/models,target=${base_container}/models \
--mount type=bind,source="${host_input_dir}"/config/${config_name},target=${base_container}/config/user_config.otvision.yaml,readonly \
--mount type=bind,source="${host_input_dir}"/data,target=${base_container}/data \
otvision:0.1.3-track
```

## Development

For development please install also the ```requirements_dev.txt``` (and use flake8 for linting and black for autoformatting with line length 88).
Expand Down
4 changes: 2 additions & 2 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import logging
from pathlib import Path

import OTVision
import OTVision.config as config
from OTVision.convert.convert import main as convert
from OTVision.helpers.files import check_if_all_paths_exist
from OTVision.helpers.log import LOGGER_NAME, VALID_LOG_LEVELS, log

Expand Down Expand Up @@ -193,7 +193,7 @@ def main(argv: list[str] | None = None) -> None: # sourcery skip: assign-if-exp
log.info(f"Arguments: {vars(args)}")

try:
OTVision.convert(
convert(
paths=paths,
input_fps=input_fps,
fps_from_filename=fps_from_filename,
Expand Down
4 changes: 2 additions & 2 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import logging
from pathlib import Path

import OTVision
import OTVision.config as config
from OTVision.detect.detect import main as detect
from OTVision.helpers.files import check_if_all_paths_exist
from OTVision.helpers.log import LOGGER_NAME, VALID_LOG_LEVELS, log

Expand Down Expand Up @@ -257,7 +257,7 @@ def main(argv: list[str] | None = None) -> None: # sourcery skip: assign-if-exp
log.info(f"Arguments: {vars(args)}")

try:
OTVision.detect(
detect(
paths=paths,
weights=weights,
conf=conf,
Expand Down
2 changes: 2 additions & 0 deletions hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignored:
- DL3008
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-r requirements_detect.txt
-r requirements_track.txt
geopandas==0.12.1
IPython==8.10.0
matplotlib==3.6.2
Expand Down
17 changes: 17 additions & 0 deletions requirements_detect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# geopandas==0.12.1
IPython==8.10.0
matplotlib==3.6.2
moviepy==1.0.3
# numpy==1.23.5
opencv-python==4.6.0.66
pandas==1.5.2
# progressbar==2.5
psutil==5.9.4
# pyogrio==0.5.0
PyYAML==5.4.1
seaborn==0.12.1
# Follow instructions at https://pytorch.org to install torch with CUDA
torch==1.13.1 # NOTE: Omit if using torch with CUDA and install manually
torchvision==0.14.1 # NOTE: Omit if using torch with CUDA and install manually
tqdm==4.64.1
ujson==5.7.0
3 changes: 3 additions & 0 deletions requirements_track.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy==1.23.5
PyYAML==5.4.1
ujson==5.7.0
4 changes: 2 additions & 2 deletions track.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import logging
from pathlib import Path

import OTVision
import OTVision.config as config
from OTVision.helpers.files import check_if_all_paths_exist
from OTVision.helpers.log import LOGGER_NAME, VALID_LOG_LEVELS, log
from OTVision.track.track import main as track


def parse(argv: list[str] | None) -> argparse.Namespace:
Expand Down Expand Up @@ -220,7 +220,7 @@ def main(argv: list[str] | None = None) -> None: # sourcery skip: assign-if-exp
log.info(f"Arguments: {vars(args)}")

try:
OTVision.track(
track(
paths=paths,
sigma_l=sigma_l,
sigma_h=sigma_h,
Expand Down
4 changes: 2 additions & 2 deletions transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import logging
from pathlib import Path

import OTVision
import OTVision.config as config
from OTVision.helpers.files import check_if_all_paths_exist
from OTVision.helpers.log import LOGGER_NAME, VALID_LOG_LEVELS, log
from OTVision.transform.transform import main as transform


def parse() -> argparse.Namespace:
Expand Down Expand Up @@ -172,7 +172,7 @@ def main() -> None:
log.info(f"Arguments: {vars(args)}")

try:
OTVision.transform(paths=paths, refpts_file=refpts_file, overwrite=overwrite)
transform(paths=paths, refpts_file=refpts_file, overwrite=overwrite)
except FileNotFoundError:
log.exception(f"One of the following files cannot be found: {paths}")
raise
Expand Down