-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abstract object detection ms to ms dir
Signed-off-by: greg pereira <grpereir@redhat.com>
- Loading branch information
1 parent
1964c56
commit a3f169b
Showing
19 changed files
with
363 additions
and
31 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
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,87 @@ | ||
name: object_detection | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
# paths: | ||
# - ./recipes/computer_vision/object_detection/** | ||
# - .github/workflows/object_detection.yaml | ||
push: | ||
branches: | ||
- main | ||
# paths: | ||
# - ./recipes/computer_vision/object_detection/** | ||
# - .github/workflows/object_detection.yaml | ||
|
||
workflow_dispatch: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: object_detection | ||
COMPONENT: app | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
services: | ||
registry: | ||
image: registry:2.8.3 | ||
ports: | ||
- 5000:5000 | ||
steps: | ||
- uses: actions/checkout@v4.1.1 | ||
|
||
- name: Install qemu dependency | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y qemu-user-static | ||
- name: Build Image | ||
id: build_image | ||
uses: redhat-actions/buildah-build@v2.13 | ||
with: | ||
image: ${{ env.REGISTRY }}/${{ github.event.repository.name }}/${{ env.COMPONENT }}/${{ env.IMAGE_NAME }} | ||
tags: latest | ||
platforms: linux/amd64, linux/arm64 | ||
containerfiles: ./recipes/computer_vision/${{ env.IMAGE_NAME }}/app/Containerfile | ||
context: recipes/computer_vision/${{ env.IMAGE_NAME }}/app | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5.0.0 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install Dependencies | ||
working-directory: ./recipes/computer_vision/${{ env.IMAGE_NAME }} | ||
run: make install | ||
|
||
- name: Download model | ||
working-directory: ./model_servers/object_detection_python | ||
run: make mistralfacebook/detr-resnet-101 | ||
|
||
# COMING SOON | ||
# - name: Run Functional Tests | ||
# shell: bash | ||
# run: make functional-tests | ||
# working-directory: ./recipes/computer_vision/${{ env.IMAGE_NAME }} | ||
|
||
- name: Login to Registry | ||
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
uses: redhat-actions/podman-login@v1.7 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Push Image | ||
id: push_image | ||
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
uses: redhat-actions/push-to-registry@v2.8 | ||
with: | ||
image: ${{ steps.build_image.outputs.image }} | ||
tags: ${{ steps.build_image.outputs.tags }} | ||
registry: ${{ env.REGISTRY }} |
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
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
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,66 @@ | ||
PORT ?= 8000 | ||
APP ?= object_detection_python | ||
REGIISTRY ?= quay.io | ||
REGISTYR_ORG ?= ai-lab | ||
COMPONENT := model_servers | ||
|
||
IMAGE := $(REGIISTRY)/$(REGISTYR_ORG)/$(COMPONENT)/$(APP):latest | ||
CUDA_IMAGE := $(REGIISTRY)/$(REGISTYR_ORG)/$(COMPONENT)/$(APP)_cuda:latest | ||
VULKAN_IMAGE := $(REGIISTRY)/$(REGISTYR_ORG)/$(COMPONENT)/$(APP)_vulkan:latest | ||
|
||
MODEL_NAME ?= facebook/detr-resnet-101 | ||
MODEL_PATH := /models/facebook/detr-resnet-101 | ||
|
||
BIND_MOUNT_OPTIONS := ro | ||
OS := $(shell uname -s) | ||
SED_BUILD_COMMAND := | ||
ifeq ($(OS),Linux) | ||
BIND_MOUNT_OPTIONS := ro,Z | ||
endif | ||
|
||
.PHONY: all | ||
all: build download-model-python run | ||
|
||
.PHONY: install | ||
install: | ||
pip install -r requirements.txt | ||
|
||
.PHONY: download-model-python | ||
download-model-python: | ||
pip install -r ../../convert_models/requirements.txt | ||
python3 ../../convert_models/download_huggingface.py -m $(MODEL_NAME) | ||
cp -r converted_models/* ../../models | ||
rm -rf converted_models | ||
rm -rf ../../models/cache | ||
|
||
.PHONY: build | ||
build: | ||
sed -i '' 's/EXPOSE 8000/EXPOSE ${PORT}/g' base/Containerfile | ||
podman build -t $(IMAGE) . -f base/Containerfile | ||
sed -i '' 's/EXPOSE ${PORT}/EXPOSE 8000/g' base/Containerfile | ||
|
||
.PHONY: run | ||
run: | ||
cd ../../models && \ | ||
podman run -it -d -p $(PORT):$(PORT) -v ./$(MODEL_NAME):$(MODEL_PATH):$(BIND_MOUNT_OPTIONS) \ | ||
-e MODEL_PATH=$(MODEL_PATH) -e HOST=0.0.0.0 -e PORT=$(PORT) --net=host $(IMAGE) | ||
|
||
.PHONY: test | ||
test: | ||
$(MAKE) facebook/detr-resnet-101 | ||
PORT=$(PORT) MODEL_NAME=$(MODEL_NAME) MODEL_PATH=$(MODEL_PATH) PORT=$(PORT) IMAGE=$(IMAGE) PULL_ALWAYS=0 pytest -s -vvv | ||
$(MAKE) -i clean | ||
|
||
.PHONY: clean | ||
clean: | ||
-rm -rf $(MODEL_NAME) | ||
-rm -rf .pytest_cache | ||
-rm -rf facebook | ||
|
||
|
||
.PHONY: facebook/detr-resnet-101 | ||
facebook/detr-resnet-101: | ||
pip install -r ../../convert_models/requirements.txt | ||
python3.11 ../../convert_models/download_huggingface.py -m facebook/detr-resnet-101 | ||
cp -r converted_models/facebook ./ | ||
rm -rf converted_models/ |
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
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ requests | |
transformers | ||
torch | ||
uvicorn | ||
|
||
timm |
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
Empty file.
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,55 @@ | ||
import pytest_container | ||
import pytest | ||
import os | ||
import logging | ||
import platform | ||
|
||
if 'PORT' not in os.environ: | ||
PORT = 8000 | ||
else: | ||
PORT = os.environ['PORT'] | ||
try: | ||
PORT = int(PORT) | ||
except: | ||
PORT = 8000 | ||
|
||
if 'IMAGE' not in os.environ: | ||
IMAGE = 'quay.io/ai-lab/model_servers/object_detection_python:latest' | ||
else: | ||
IMAGE = os.environ['IMAGE'] | ||
|
||
MODEL_NAME=os.environ['MODEL_NAME'] | ||
MODEL_PATH=os.environ['MODEL_PATH'] | ||
|
||
BIND_MOUNT_OPTIONS = 'ro' | ||
if platform.system() == 'Linux': | ||
BIND_MOUNT_OPTIONS = 'ro,Z' | ||
|
||
MS = pytest_container.Container( | ||
url=f"containers-storage:{IMAGE}", | ||
volume_mounts=[ | ||
pytest_container.container.BindMount( | ||
container_path=f"{MODEL_PATH}", | ||
host_path=f"./{MODEL_NAME}", | ||
flags=[BIND_MOUNT_OPTIONS] | ||
) | ||
], | ||
extra_environment_variables={ | ||
"MODEL_PATH": f"{MODEL_PATH}", | ||
"HOST": "0.0.0.0", | ||
"PORT": f"{PORT}" | ||
}, | ||
forwarded_ports=[ | ||
pytest_container.PortForwarding( | ||
container_port=PORT, | ||
host_port=PORT | ||
) | ||
], | ||
) | ||
|
||
def pytest_addoption(parser): | ||
pytest_container.add_logging_level_options(parser) | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
pytest_container.auto_container_parametrize(metafunc) |
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,8 @@ | ||
pip==24.0 | ||
pytest-container==0.4.0 | ||
pytest-selenium==4.1.0 | ||
pytest-testinfra==10.1.0 | ||
pytest==8.1.1 | ||
requests==2.31.0 | ||
selenium==4.19.0 | ||
tenacity==8.2.3 |
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,13 @@ | ||
import pytest_container | ||
from .conftest import MS | ||
import tenacity | ||
|
||
CONTAINER_IMAGES = [MS] | ||
|
||
|
||
def test_etc_os_release_present(auto_container: pytest_container.container.ContainerData): | ||
assert auto_container.connection.file("/etc/os-release").exists | ||
|
||
@tenacity.retry(stop=tenacity.stop_after_attempt(5), wait=tenacity.wait_exponential()) | ||
def test_alive(auto_container: pytest_container.container.ContainerData, host): | ||
host.run_expect([0],f"curl http://localhost:{auto_container.forwarded_ports[0].host_port}",).stdout.strip() |
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,48 @@ | ||
|
||
APP := object_detection_client | ||
COMPONENT := app | ||
|
||
PORT ?= 8501 | ||
REGISTRY ?= quay.io | ||
REGISTRY_ORG ?= ai-lab | ||
|
||
IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/$(COMPONENT)/$(APP):latest | ||
|
||
MODEL_NAME ?= facebook/detr-resnet-101 | ||
MODEL_PATH := /models/facebook/detr-resnet-101 | ||
|
||
.PHONY: install | ||
install: | ||
pip install -r app/requirements.txt | ||
|
||
.PHONY: all | ||
all: build-and-run-server build run | ||
|
||
.PHONY: build | ||
build: | ||
sed -i '' 's/EXPOSE 8501/EXPOSE ${PORT}/g' app/Containerfile | ||
podman build -t $(IMAGE) app/ | ||
sed -i '' 's/EXPOSE ${PORT}/EXPOSE 8501/g' app/Containerfile | ||
|
||
# .PHONY: facebook/detr-resnet-101 # THIS WILL BE USED FOR FUNCTIONAL TESTS | ||
# facebook/detr-resnet-101: | ||
# pip install -r ../../../convert_models/requirements.txt | ||
# python3.11 ../../../convert_models/download_huggingface.py -m facebook/detr-resnet-101 | ||
# cp -r converted_models/facebook ./ | ||
# rm -rf converted_models/ | ||
|
||
.PHONY: clean | ||
clean: | ||
-rm -rf $(MODEL_NAME) | ||
-rm -rf .pytest_cache | ||
-rm -rf facebook | ||
|
||
.PHONY: run | ||
run: | ||
podman run -p $(PORT):$(PORT) -e MODEL_ENDPOINT=http://10.88.0.1:8000/detection $(IMAGE) | ||
|
||
.PHONY: build-and-run-server | ||
build-and-run-server: | ||
cd ../../../model_servers/object_detection_python/ && \ | ||
$(MAKE) all | ||
|
Oops, something went wrong.