From 46b9582dab47af19afe1ac800d93b8ccdb0b6b10 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 27 Sep 2024 08:30:37 +0200 Subject: [PATCH 01/36] support for multiple tool versions --- docker/rvc2/Dockerfile | 73 +++++++++++++++--------- docker/rvc2/entrypoint.sh | 10 +++- docker/rvc2/requirements.txt | 2 + modelconverter/__main__.py | 50 +++++++++++++--- modelconverter/packages/rvc2/exporter.py | 52 ++++++++++++----- modelconverter/utils/docker_utils.py | 53 ++++++++++++++--- 6 files changed, 181 insertions(+), 59 deletions(-) diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index 5b1234a..ab25eab 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -1,34 +1,51 @@ FROM python:3.8-slim as BASE -RUN apt-get update && \ - apt-get install -y \ - cmake unzip perl libatomic1 libc++-dev ffmpeg libcurl4 libncurses5 llvm-14-runtime patch git - -COPY --link docker/scripts /scripts -RUN bash /scripts/install_openssl.sh - -COPY --link docker/extra_packages/openvino_2022_3_vpux_drop_patched.tar.gz . -RUN mkdir /opt/intel -RUN tar xvf openvino_2022_3_vpux_drop_patched.tar.gz \ - -C /opt/intel/ --strip-components 1 -RUN sed -i 's/libtbb2/libtbbmalloc2/g' \ - /opt/intel/install_dependencies/install_openvino_dependencies.sh && \ - bash /opt/intel/install_dependencies/install_openvino_dependencies.sh -y - -RUN pip install --upgrade pip +ARG VERSION=2022.3.0 +ENV VERSION=${VERSION} + + +RUN <> ~/.bashrc && \ - chmod +x /app/entrypoint.sh && \ - mkdir /app/modelconverter +RUN <> ~/.bashrc +chmod +x /app/entrypoint.sh +mkdir /app/modelconverter +EOF COPY --link modelconverter pyproject.toml /app/modelconverter/ RUN cd modelconverter && pip install -e . --no-deps --no-cache-dir -ENV IN_DOCKER= ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/docker/rvc2/entrypoint.sh b/docker/rvc2/entrypoint.sh index 09fd290..3e8f2b9 100644 --- a/docker/rvc2/entrypoint.sh +++ b/docker/rvc2/entrypoint.sh @@ -7,7 +7,15 @@ for arg in "${args[@]}"; do done set -- -source /opt/intel/setupvars.sh +if [ -f /opt/intel/setupvars.sh ]; then + source /opt/intel/setupvars.sh +elif [ -f /opt/intel/*openvino*/bin/setupvars.sh ]; then + source /opt/intel/*openvino*/bin/setupvars.sh +fi + +if [[ $PYTHONPATH != *: ]]; then + export PYTHONPATH=$PYTHONPATH: +fi export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/python3.8/site-packages/openvino/libs/ diff --git a/docker/rvc2/requirements.txt b/docker/rvc2/requirements.txt index 081a415..fb1ac24 100644 --- a/docker/rvc2/requirements.txt +++ b/docker/rvc2/requirements.txt @@ -1,2 +1,4 @@ tflite2onnx bsdiff4 +openvino==${VERSION} +openvino-dev==${VERSION} diff --git a/modelconverter/__main__.py b/modelconverter/__main__.py index a596240..05a7ee4 100644 --- a/modelconverter/__main__.py +++ b/modelconverter/__main__.py @@ -59,6 +59,32 @@ class Format(str, Enum): help="One of the supported formats.", ), ] +VersionOption: TypeAlias = Annotated[ + Optional[str], + typer.Option( + help="""Version of the underlying conversion tools to use. + Only takes effect when --dev is used. + Available options differ based on the target platform: + + - `RVC2`: + - `2021.4.0` + - `2022.3.0` (default) + + - `RVC3`: + - `2022.3.0` (default) + + - `RVC4`: + - `2.22.10` + - `2.23.0` (default) + - `2.24.0` + - `2.25.0` + - `2.26.2` + + - `HAILO`: + - `2024.04` (default)""", + show_default=False, + ), +] PathOption: TypeAlias = Annotated[ Optional[str], typer.Option( @@ -234,6 +260,7 @@ def infer( ), ] = None, dev: DevOption = False, + version: VersionOption = None, gpu: Annotated[ bool, typer.Option(help="Use GPU for conversion. Only relevant for HAILO."), @@ -243,8 +270,6 @@ def infer( """Runs inference on the specified target platform.""" tag = "dev" if dev else "latest" - if dev: - docker_build(target.value, tag=tag) if in_docker(): setup_logging(file="modelconverter.log", use_rich=True) @@ -262,6 +287,9 @@ def infer( logger.exception("Encountered an unexpected error!") exit(2) else: + image = None + if dev: + image = docker_build(target.value, tag=tag, version=version) args = [ "infer", target.value, @@ -276,16 +304,19 @@ def infer( args.extend(["--output-dir", output_dir]) if opts is not None: args.extend(opts) - docker_exec(target.value, *args, tag=tag, use_gpu=gpu) + docker_exec(target.value, *args, tag=tag, use_gpu=gpu, image=image) @app.command() def shell( - target: TargetArgument, dev: DevOption = False, gpu: GPUOption = True + target: TargetArgument, + dev: DevOption = False, + version: VersionOption = None, + gpu: GPUOption = True, ): """Boots up a shell inside a docker container for the specified target platform.""" if dev: - docker_build(target.value, tag="dev") + image = docker_build(target.value, tag="dev", version=version) docker_exec(target.value, tag="dev" if dev else "latest", use_gpu=gpu) @@ -360,6 +391,7 @@ def convert( dev: DevOption = False, to: FormatOption = Format.NATIVE, gpu: GPUOption = True, + version: VersionOption = None, main_stage: Annotated[ Optional[str], typer.Option( @@ -385,8 +417,6 @@ def convert( """Exports the model for the specified target platform.""" tag = "dev" if dev else "latest" - if dev: - docker_build(target.value.lower(), tag=tag) if archive_preprocess and to != Format.NN_ARCHIVE: raise ValueError( @@ -489,6 +519,10 @@ def convert( logger.exception("Encountered an unexpected error!") exit(2) else: + image = None + if dev: + image = docker_build(target.value, tag=tag, version=version) + args = [ "convert", target.value, @@ -506,7 +540,7 @@ def convert( args.extend(["--path", path]) if opts is not None: args.extend(opts) - docker_exec(target.value, *args, tag=tag, use_gpu=gpu) + docker_exec(target.value, *args, tag=tag, use_gpu=gpu, image=image) @app.command() diff --git a/modelconverter/packages/rvc2/exporter.py b/modelconverter/packages/rvc2/exporter.py index f29e48c..1cf5739 100644 --- a/modelconverter/packages/rvc2/exporter.py +++ b/modelconverter/packages/rvc2/exporter.py @@ -1,5 +1,6 @@ import subprocess import tempfile +from importlib.metadata import version from functools import partial from logging import getLogger from multiprocessing import Pool, cpu_count @@ -16,15 +17,28 @@ subprocess_run, ) from modelconverter.utils.config import SingleStageConfig -from modelconverter.utils.types import Encoding, InputFileType, Target +from modelconverter.utils.types import ( + DataType, + Encoding, + InputFileType, + Target, +) from ..base_exporter import Exporter logger = getLogger(__name__) -COMPILE_TOOL: Final[ - str -] = f'{env["INTEL_OPENVINO_DIR"]}/tools/compile_tool/compile_tool' +OV_VERSION: Final[str] = version("openvino") +COMPILE_TOOL: str + +OV_2021: Final[bool] = OV_VERSION.startswith("2021") + +if OV_2021: + COMPILE_TOOL = f'{env["INTEL_OPENVINO_DIR"]}/deployment_tools/tools/compile_tool/compile_tool' +else: + COMPILE_TOOL = ( + f'{env["INTEL_OPENVINO_DIR"]}/tools/compile_tool/compile_tool' + ) DEFAULT_SUPER_SHAVES: Final[int] = 8 @@ -57,7 +71,10 @@ def _export_openvino_ir(self) -> Path: args, ["--output", ",".join(name for name in self.outputs)] ) if self.compress_to_fp16: - self._add_args(args, ["--compress_to_fp16"]) + if OV_2021: + self._add_args(args, ["--data_type", "FP16"]) + else: + self._add_args(args, ["--compress_to_fp16"]) if "--input" not in args: inp_str = "" @@ -66,9 +83,13 @@ def _export_openvino_ir(self) -> Path: inp_str += "," inp_str += name if inp.shape is not None: - inp_str += f'[{",".join(map(str, inp.shape))}]' + inp_str += f'[{" ".join(map(str, inp.shape))}]' if inp.data_type is not None: - inp_str += f"{{{inp.data_type.as_openvino_dtype()}}}" + if OV_2021 and self.compress_to_fp16: + data_type = DataType("float16") + else: + data_type = inp.data_type + inp_str += f"{{{data_type.as_openvino_dtype()}}}" if inp.frozen_value is not None: if len(inp.frozen_value) == 1: value = inp.frozen_value[0] @@ -122,7 +143,8 @@ def _check_reverse_channels(self): @staticmethod def _write_config(shaves: int, slices: int) -> str: with tempfile.NamedTemporaryFile(suffix=".conf", delete=False) as conf: - conf.write(b"MYRIAD_ENABLE_MX_BOOT NO\n") + if not OV_2021: + conf.write(b"MYRIAD_ENABLE_MX_BOOT NO\n") conf.write(f"MYRIAD_NUMBER_OF_SHAVES {shaves}\n".encode()) conf.write(f"MYRIAD_NUMBER_OF_CMX_SLICES {slices}\n".encode()) conf.write(b"MYRIAD_THROUGHPUT_STREAMS 1\n") @@ -151,16 +173,18 @@ def _transform_tflite_to_onnx(self) -> None: if lt[-1] == "C": if len(lt) == 4 and lt[0] == "N": - self._add_args( - self.mo_args, ["--layout", f"{name}(nchw->nhwc)"] - ) + if not OV_2021: + self._add_args( + self.mo_args, ["--layout", f"{name}(nchw->nhwc)"] + ) inp.shape = [sh[0], sh[3], sh[1], sh[2]] inp.layout = f"{lt[0]}{lt[3]}{lt[1]}{lt[2]}" elif len(inp.layout) == 3: - self._add_args( - self.mo_args, ["--layout", f"{name}(chw->hwc)"] - ) + if not OV_VERSION.startswith("2021.4"): + self._add_args( + self.mo_args, ["--layout", f"{name}(chw->hwc)"] + ) inp.shape = [sh[2], sh[0], sh[1]] inp.layout = f"{lt[2]}{lt[0]}{lt[1]}" diff --git a/modelconverter/utils/docker_utils.py b/modelconverter/utils/docker_utils.py index 072c048..3aa6169 100644 --- a/modelconverter/utils/docker_utils.py +++ b/modelconverter/utils/docker_utils.py @@ -4,7 +4,7 @@ import subprocess import tempfile from pathlib import Path -from typing import cast +from typing import Literal, Optional, cast import yaml from luxonis_ml.utils import environ @@ -16,6 +16,17 @@ logger = logging.getLogger(__name__) +def get_default_target_version( + target: Literal["rvc2", "rvc3", "rvc4", "hailo"], +) -> str: + return { + "rvc2": "2022.3.0", + "rvc3": "2022.3.0", + "rvc4": "2.23.0", + "hailo": "2024.04", + }[target] + + def generate_compose_config(image: str, gpu: bool = False) -> str: config = { "services": { @@ -65,20 +76,38 @@ def check_docker() -> None: # NOTE: docker SDK is not used here because it's too slow -def docker_build(target: str, tag: str) -> str: +def docker_build( + target: Literal["rvc2", "rvc3", "rvc4", "hailo"], + tag: str, + version: Optional[str] = None, +) -> str: check_docker() + if version is None: + version = get_default_target_version(target) + + tag = f"{tag}-{version}" repository = f"luxonis/modelconverter-{target}:{tag}" - result = subprocess.run( - f"docker build -f docker/{target}/Dockerfile " - f"-t {repository} .".split(), - ) + args = [ + "docker", + "build", + "-f", + f"docker/{target}/Dockerfile", + "-t", + repository, + ".", + ] + if version is not None: + args += ["--build-arg", f"VERSION={version}"] + result = subprocess.run(args) if result.returncode != 0: raise RuntimeError("Failed to build the docker image") return repository -def get_docker_image(target: str, tag: str) -> str: +def get_docker_image( + target: Literal["rvc2", "rvc3", "rvc4", "hailo"], tag: str +) -> str: check_docker() client = docker.from_env() @@ -102,8 +131,14 @@ def get_docker_image(target: str, tag: str) -> str: return image_name -def docker_exec(target: str, *args: str, tag: str, use_gpu: bool) -> None: - image = get_docker_image(target, tag) +def docker_exec( + target: Literal["rvc2", "rvc3", "rvc4", "hailo"], + *args: str, + tag: str, + use_gpu: bool, + image: Optional[str] = None, +) -> None: + image = image or get_docker_image(target, tag) with tempfile.NamedTemporaryFile(delete=False) as f: f.write( From 0bd200dab5671a75189330332791eedefcf9252a Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 27 Sep 2024 10:16:10 +0200 Subject: [PATCH 02/36] cleaned up rvc2 dockerfile --- docker/rvc2/Dockerfile | 89 +++++++++++++++++++++++++++------------ docker/rvc2/entrypoint.sh | 7 +-- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index ab25eab..364646e 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -6,45 +6,78 @@ ENV VERSION=${VERSION} RUN <> ~/.bashrc -chmod +x /app/entrypoint.sh -mkdir /app/modelconverter + COMPILE_TOOL=$(find /opt/intel -name compile_tool -type f) + echo "alias compile_tool=${COMPILE_TOOL}" >> ~/.bashrc + chmod +x /app/entrypoint.sh + pip install -e ./modelconverter --no-deps --no-cache-dir + EOF -COPY --link modelconverter pyproject.toml /app/modelconverter/ -RUN cd modelconverter && pip install -e . --no-deps --no-cache-dir ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/docker/rvc2/entrypoint.sh b/docker/rvc2/entrypoint.sh index 3e8f2b9..2be490d 100644 --- a/docker/rvc2/entrypoint.sh +++ b/docker/rvc2/entrypoint.sh @@ -7,10 +7,11 @@ for arg in "${args[@]}"; do done set -- -if [ -f /opt/intel/setupvars.sh ]; then + +if [ ${VERSION} = "2021.4.0" ]; then + source /opt/intel/bin/setupvars.sh +else source /opt/intel/setupvars.sh -elif [ -f /opt/intel/*openvino*/bin/setupvars.sh ]; then - source /opt/intel/*openvino*/bin/setupvars.sh fi if [[ $PYTHONPATH != *: ]]; then From 47d65e57cb8f3db65b8a393e1ab52fdc4001fcfd Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 27 Sep 2024 10:16:21 +0200 Subject: [PATCH 03/36] fixed version in convert command --- modelconverter/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modelconverter/__main__.py b/modelconverter/__main__.py index 05a7ee4..981d640 100644 --- a/modelconverter/__main__.py +++ b/modelconverter/__main__.py @@ -317,7 +317,9 @@ def shell( """Boots up a shell inside a docker container for the specified target platform.""" if dev: image = docker_build(target.value, tag="dev", version=version) - docker_exec(target.value, tag="dev" if dev else "latest", use_gpu=gpu) + docker_exec( + target.value, tag="dev" if dev else "latest", use_gpu=gpu, image=image + ) @app.command( From 47ebbc1f2e108a33357ba18ffed0fbdf8f457439 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 27 Sep 2024 10:23:16 +0200 Subject: [PATCH 04/36] fixed missing libraries --- docker/rvc2/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index 364646e..a8e9cd0 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -42,7 +42,6 @@ RUN < Date: Fri, 27 Sep 2024 11:37:49 +0200 Subject: [PATCH 05/36] multi-version support for rvc4 --- docker/rvc4/Dockerfile | 93 ++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/docker/rvc4/Dockerfile b/docker/rvc4/Dockerfile index 0227236..ade75fa 100644 --- a/docker/rvc4/Dockerfile +++ b/docker/rvc4/Dockerfile @@ -1,38 +1,70 @@ FROM python:3.10-slim as BASE -RUN apt-get update && \ - apt-get install -y \ - cmake unzip perl libatomic1 libc++-dev ffmpeg \ - libcurl4 libncurses5 llvm-14-runtime git - -COPY --link docker/extra_packages/snpe.zip . -RUN unzip snpe.zip -d /opt - -RUN ls /opt/quairt && mv /opt/qairt/* /opt/snpe || true - -RUN rm -rf /opt/snpe/Uninstall && \ - rm -rf /opt/snpe/docs && \ - rm -rf /opt/snpe/examples && \ - rm -rf /opt/snpe/lib/hexagon* && \ - rm -rf /opt/snpe/lib/*android* && \ - rm -rf /opt/snpe/lib/*ubuntu* && \ - rm -rf /opt/snpe/lib/*windows* && \ - rm -rf /opt/snpe/bin/*windows* && \ - rm -rf /opt/snpe/bin/*android* && \ +ARG VERSION=2.23.0 +ENV VERSION=${VERSION} + +RUN < Date: Fri, 27 Sep 2024 12:00:51 +0200 Subject: [PATCH 06/36] cleaned dockerfiles --- docker/rvc2/Dockerfile | 8 +++-- docker/rvc3/Dockerfile | 80 +++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index a8e9cd0..0359dae 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -21,9 +21,11 @@ RUN <> ~/.bashrc chmod +x /app/entrypoint.sh - pip install -e ./modelconverter --no-deps --no-cache-dir EOF diff --git a/docker/rvc3/Dockerfile b/docker/rvc3/Dockerfile index 7b3c34c..e1ffceb 100644 --- a/docker/rvc3/Dockerfile +++ b/docker/rvc3/Dockerfile @@ -1,33 +1,61 @@ FROM python:3.8-slim as BASE -RUN apt-get update && \ - apt-get install -y \ - cmake unzip perl libatomic1 libc++-dev ffmpeg libcurl4 libncurses5 llvm-14-runtime patch git +RUN <> ~/.bashrc && \ - chmod +x /app/entrypoint.sh && \ - mkdir /app/modelconverter +RUN <> ~/.bashrc + chmod +x /app/entrypoint.sh + +EOF -COPY --link modelconverter pyproject.toml /app/modelconverter/ -RUN cd modelconverter && pip install -e . --no-deps --no-cache-dir -ENV IN_DOCKER= ENTRYPOINT ["/app/entrypoint.sh"] From 9f6172ea9246cc7e8badc599e05818f9c9271a85 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 27 Sep 2024 12:02:36 +0200 Subject: [PATCH 07/36] removed unused commands --- docker/rvc3/Dockerfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docker/rvc3/Dockerfile b/docker/rvc3/Dockerfile index e1ffceb..34818c2 100644 --- a/docker/rvc3/Dockerfile +++ b/docker/rvc3/Dockerfile @@ -17,9 +17,6 @@ RUN < Date: Sat, 28 Sep 2024 01:16:37 +0200 Subject: [PATCH 08/36] updated publish actions to use versions --- .github/workflows/hailo_publish.yaml | 1 + .github/workflows/publish.yaml | 117 ++++++++++++--------------- .github/workflows/rvc2_publish.yaml | 7 ++ .github/workflows/rvc3_publish.yaml | 1 + .github/workflows/rvc4_publish.yaml | 13 +++ 5 files changed, 72 insertions(+), 67 deletions(-) diff --git a/.github/workflows/hailo_publish.yaml b/.github/workflows/hailo_publish.yaml index f62c48e..450bded 100644 --- a/.github/workflows/hailo_publish.yaml +++ b/.github/workflows/hailo_publish.yaml @@ -14,4 +14,5 @@ jobs: secrets: inherit with: package: hailo + version: "2024.04" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 96c873d..3eda504 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -7,22 +7,31 @@ on: required: true type: string description: Which package to publish + version: + required: true + type: string + description: > + Which version of underlying conversion tools to use permissions: contents: read packages: write env: - PROJECT_ID: easyml-394818 GAR_LOCATION: us-central1 DOCKERFILE: docker/${{ inputs.package }}/Dockerfile PACKAGE: ${{ inputs.package }} NAME: luxonis/modelconverter-${{ inputs.package }} STEM: modelconverter-${{ inputs.package }} + VERSION: ${{ inputs.version }} + GS_BUILD_ARTIFACTS: gs://luxonis-test-bucket/modelconverter/build-artifacts + GAR_STEM: us-central1-docker.pkg.dev/easyml-394818 jobs: ghcr-publish: runs-on: ubuntu-latest + env: + LOCAL_NAME: ${NAME}:${VERSION}-latest" steps: - name: Checkout code @@ -35,58 +44,6 @@ jobs: credentials_json: ${{ secrets.GCP_CREDENTIALS }} token_format: access_token - - name: Docker login to GHCR - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Get modelconverter version - id: commit - run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@v1 - - - name: Download file from GCS - run: | - cd docker/extra_packages - if [ "$PACKAGE" = "rvc4" ]; then - gsutil cp gs://luxonis-test-bucket/modelconverter/build-artifacts/snpe.zip snpe.zip - elif [ "$PACKAGE" = "rvc2" ] || [ "$PACKAGE" = "rvc3" ]; then - gsutil cp gs://luxonis-test-bucket/modelconverter/build-artifacts/openvino_2022_3_vpux_drop_patched.tar.gz openvino_2022_3_vpux_drop_patched.tar.gz - fi - - name: Publish latest - run: | - docker build -f $DOCKERFILE -t $NAME:latest . - docker tag $NAME:latest ghcr.io/$NAME:latest - docker push ghcr.io/$NAME:latest - - - name: Publish tagged - run: | - VERSION=${{ steps.commit.outputs.sha }} - docker tag $NAME:latest ghcr.io/$NAME:$VERSION - docker push ghcr.io/$NAME:$VERSION - - gar-publish: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Get modelconverter version - id: commit - run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - - name: Authenticate to Google Cloud - id: google-auth - uses: google-github-actions/auth@v2 - with: - credentials_json: ${{ secrets.GCP_CREDENTIALS }} - token_format: access_token - - name: Docker login to GAR uses: docker/login-action@v3 with: @@ -105,29 +62,55 @@ jobs: uses: google-github-actions/setup-gcloud@v1 - name: Download file from GCS + if: ${{ inputs.package }} != hailo run: | cd docker/extra_packages if [ "$PACKAGE" = "rvc4" ]; then - gsutil cp gs://luxonis-test-bucket/modelconverter/build-artifacts/snpe.zip snpe.zip + gcloud storage cp \ + "${GS_BUILD_ARTIFACTS}/snpe-${VERSION}.zip" \ + "snpe-${VERSION}.zip" elif [ "$PACKAGE" = "rvc2" ] || [ "$PACKAGE" = "rvc3" ]; then - gsutil cp gs://luxonis-test-bucket/modelconverter/build-artifacts/openvino_2022_3_vpux_drop_patched.tar.gz openvino_2022_3_vpux_drop_patched.tar.gz + gcloud storage cp \ + "${GS_BUILD_ARTIFACTS}/openvino-${VERSION}.tar.gz" \ + "openvino-${VERSION}.tar.gz" fi - - name: Publish + - name: Build image + run: | + docker build -f "${DOCKERFILE}" -t "${LOCAL_NAME}" . + + - name: GHCR publish latest run: | - docker build -f $DOCKERFILE -t $NAME:latest . + GHCR_NAME="ghcr.io/${LOCAL_NAME}" + docker tag "${LOCAL_NAME}" "${GHCR_NAME}" + docker push "${GHCR_NAME}" - VERSION=${{ steps.commit.outputs.sha }} - GAR_NAME="$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/internal/$STEM" + - name: GHCR publish SHA + run: | + SHA=$(git rev-parse --short HEAD) + GHCR_NAME="ghcr.io/${NAME}:${VERSION}-${SHA}" + docker tag "${LOCAL_NAME}" "${GHCR_NAME}" + docker push "${GHCR_NAME}" - for tag in latest $VERSION; do - docker tag "$NAME:latest" "$GAR_NAME:$tag" - docker push "$GAR_NAME:$tag" - done + - name: GAR publish latest + run: | + GAR_NAME="${GAR_STEM}/internal/${STEM}:${VERSION}-latest" + docker tag "${LOCAL_NAME}" "${GAR_NAME}" + docker push "${GAR_NAME}" + + - name: GAR publish SHA + run: | + SHA=$(git rev-parse --short HEAD) + GAR_NAME="${GAR_STEM}/internal/${STEM}:${VERSION}-${SHA}" + docker tag "${LOCAL_NAME}" "${GAR_NAME}" + docker push "${GAR_NAME}" + + - name: GAR publish clients + run: | + read -r -a REPO_ARRAY <<< "${{ vars.EXTERNAL_CLIENTS }}" - IFS=' ' read -r -a REPO_ARRAY <<< "${{ vars.EXTERNAL_CLIENTS }}" for REPO in "${REPO_ARRAY[@]}"; do - GAR_CLIENT_TAG="$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPO/$STEM:$VERSION" - docker tag "$NAME:latest" "$GAR_CLIENT_TAG" - docker push "$GAR_CLIENT_TAG" + GAR_CLIENT_NAME="${GAR_STEM}/${REPO}/${STEM}:${VERSION}-${SHA}" + docker tag "${LOCAL_NAME}" "${GAR_CLIENT_NAME}" + docker push "${GAR_CLIENT_NAME}" done diff --git a/.github/workflows/rvc2_publish.yaml b/.github/workflows/rvc2_publish.yaml index a8808ae..150c3f1 100644 --- a/.github/workflows/rvc2_publish.yaml +++ b/.github/workflows/rvc2_publish.yaml @@ -10,7 +10,14 @@ on: jobs: rvc2-publish: + + strategy: + fail-fast: false + matrix: + version: ["2021.4.0", "2022.3.0"] + uses: ./.github/workflows/publish.yaml secrets: inherit with: package: rvc2 + verison: ${{ matrix.version }} diff --git a/.github/workflows/rvc3_publish.yaml b/.github/workflows/rvc3_publish.yaml index 7d1f297..037c590 100644 --- a/.github/workflows/rvc3_publish.yaml +++ b/.github/workflows/rvc3_publish.yaml @@ -14,3 +14,4 @@ jobs: secrets: inherit with: package: rvc3 + version: "2022.3.0" diff --git a/.github/workflows/rvc4_publish.yaml b/.github/workflows/rvc4_publish.yaml index 61aa5a1..7bba205 100644 --- a/.github/workflows/rvc4_publish.yaml +++ b/.github/workflows/rvc4_publish.yaml @@ -10,7 +10,20 @@ on: jobs: rvc4-publish: + + strategy: + fail-fast: false + matrix: + version: + - "2.21.0" + - "2.22.10" + - "2.23.0" + - "2.24.0" + - "2.25.0" + - "2.26.2" + uses: ./.github/workflows/publish.yaml secrets: inherit with: package: rvc4 + version: ${{ matrix.version }} From fef09d0e4927ba41d5f3d8233606cc66917e6a8e Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Mon, 30 Sep 2024 02:57:17 +0200 Subject: [PATCH 09/36] typo --- .github/workflows/publish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 3eda504..3f153a4 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -31,7 +31,7 @@ jobs: ghcr-publish: runs-on: ubuntu-latest env: - LOCAL_NAME: ${NAME}:${VERSION}-latest" + LOCAL_NAME: ${NAME}:${VERSION}-latest steps: - name: Checkout code From f55b194fb0dd32488b44acef41f68674e5daefba Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Mon, 30 Sep 2024 06:02:38 +0200 Subject: [PATCH 10/36] updated readme --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8fe5230..d43364b 100644 --- a/README.md +++ b/README.md @@ -51,20 +51,33 @@ Otherwise follow the installation instructions for your OS from the [official we `ModelConverter` is in an experimental public beta stage. Some parts might change in the future. -To build the images, you need to download additional packages depending on the selected target. +To build the images, you need to download additional packages depending on the selected target and the desired version of the underlying conversion tools. -**RVC2 and RVC3** +**RVC2** -Requires `openvino_2022_3_vpux_drop_patched.tar.gz` to be present in `docker/extra_packages`. -You can download the archive [here](https://drive.google.com/file/d/1IXtYi1Mwpsg3pr5cDXlEHdSUZlwJRTVP/view?usp=share_link). +Requires `openvino-`.tar.gz` to be present in `docker/extra_packages`. + +- Version `2023.2.0` archive can be downloaded from [here](https://drive.google.com/file/d/1IXtYi1Mwpsg3pr5cDXlEHdSUZlwJRTVP/view?usp=share_link). + +- Version `2021.4.0` archive can be downloaded from [here](https://storage.openvinotoolkit.org/repositories/openvino/packages/2021.4/l_openvino_toolkit_dev_ubuntu20_p_2021.4.582.tgz) + +You only need to rename the archive to either `openvino-2023.2.0.tar.gz` or `openvino-2021.4.0.tar.gz` and place it in the `docker/extra_packages` directory. + +**RVC3** + +Only the version `2023.2.0` of `OpenVino` is supported for `RVC3`. Follow the instructions for `RVC2` to use the correct archive. **RVC4** -Requires `snpe.zip` archive to be present in `docker/extra_packages`. You can download an archive with the current version [here](https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.23.0.24.06.24.zip). You only need to rename it to `snpe.zip` and place it in the `docker/extra_packages` directory. +Requires `snpe-.zip` archive to be present in `docker/extra_packages`. You can download version `2.23.0` from [here](https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.23.0.24.06.24.zip). You only need to rename it to `snpe-2.23.0.zip` and place it in the `docker/extra_packages` directory. **HAILO** -Requires `hailo_ai_sw_suite_2024-04:1` docker image to be present on the system. You can download the image from the [Hailo website](https://developer.hailo.ai/developer-zone/sw-downloads/). Furthermore, you need to use the `docker/hailo/Dockerfile.public` file to build the image. The `docker/hailo/Dockerfile` is for internal use only. +Requires `hailo_ai_sw_suite_:1` docker image to be present on the system. You can obtain the image by following the instructions on [Hailo website](https://developer.hailo.ai/developer-zone/sw-downloads/). + +After you obtain the image, you need to rename it to `hailo_ai_sw_suite_:1` using `docker tag hailo_ai_sw_suite_:1`. + +Furthermore, you need to use the `docker/hailo/Dockerfile.public` file to build the image. The `docker/hailo/Dockerfile` is for internal use only. ### Instructions From bc51b621aed3d6d3edea9f6c51b6c900369bd94d Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Wed, 9 Oct 2024 13:26:42 +0200 Subject: [PATCH 11/36] updated hailo image --- docker/bases/Dockerfile.base-hailo | 30 ------------------------- docker/hailo/Dockerfile | 24 +++++++++++++------- docker/hailo/Dockerfile.base | 36 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 38 deletions(-) delete mode 100644 docker/bases/Dockerfile.base-hailo create mode 100644 docker/hailo/Dockerfile.base diff --git a/docker/bases/Dockerfile.base-hailo b/docker/bases/Dockerfile.base-hailo deleted file mode 100644 index 8d027da..0000000 --- a/docker/bases/Dockerfile.base-hailo +++ /dev/null @@ -1,30 +0,0 @@ -FROM hailo_ai_sw_suite_2024-07:1 -USER root - -COPY requirements.txt requirements.txt - -RUN pip install --upgrade pip && \ - pip install -r requirements.txt && \ - pip install --extra-index-url \ - https://developer.download.nvidia.com/compute/redist \ - nvidia-dali-cuda110 && \ - pip install --extra-index-url \ - https://developer.download.nvidia.com/compute/redist \ - nvidia-dali-tf-plugin-cuda110 - -RUN rm -rf \ - /local/workspace/tappas \ - /opt/google \ - /local/workspace/doc \ - /local/workspace/hailort_examples \ - /usr/share \ - /usr/bin/docker* \ - /usr/bin/containerd* \ - /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_tutorials - -RUN pip install pip-autoremove && \ - pip-autoremove -y torch jupyter plotly matplotlib ipython \ - tensorboard pip-autoremove && \ - pip install psutil && \ - pip cache purge && \ - rm -rf ~/.cache diff --git a/docker/hailo/Dockerfile b/docker/hailo/Dockerfile index 75b6ca5..99a6afd 100644 --- a/docker/hailo/Dockerfile +++ b/docker/hailo/Dockerfile @@ -2,18 +2,26 @@ # If you want to build the Model Converter Docker image, # please use the Dockerfile.public file instead. -FROM ghcr.io/luxonis/modelconverter-base-hailo:latest +ARG VERSION=2.23.0 + +FROM ghcr.io/luxonis/modelconverter-base-hailo:${VERSION}-latest + +ENV IN_DOCKER= +ENV VERSION=${VERSION} WORKDIR /app -COPY docker/hailo/entrypoint.sh /app/entrypoint.sh -RUN chmod +x /app/entrypoint.sh +COPY --link docker/hailo/entrypoint.sh /app/entrypoint.sh +COPY --link modelconverter pyproject.toml /app/modelconverter/ -COPY modelconverter pyproject.toml requirements.txt /app/modelconverter/ -RUN cd modelconverter -RUN cd modelconverter && pip install -e . --no-deps +RUN < /etc/profile.d/certifi.sh + echo "export SSL_CERT_FILE=$(python -m certifi)" \ + > /etc/profile.d/certifi.sh + + pip install -e ./modelconverter --no-deps --no-cache-dir + chmod +x /app/entrypoint.sh + +EOF -ENV IN_DOCKER= ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/docker/hailo/Dockerfile.base b/docker/hailo/Dockerfile.base new file mode 100644 index 0000000..cb6c711 --- /dev/null +++ b/docker/hailo/Dockerfile.base @@ -0,0 +1,36 @@ +ARG VERSION=2024.07 + +FROM hailo_ai_sw_suite_${VERSION/./-}:1 as BASE +USER root + + +RUN pip install --upgrade pip + +COPY requirements.txt requirements.txt + +RUN pip install -r requirements.txt +RUN pip install --extra-index-url \ + https://developer.download.nvidia.com/compute/redist \ + nvidia-dali-cuda110 + +RUN pip install --extra-index-url \ + https://developer.download.nvidia.com/compute/redist \ + nvidia-dali-tf-plugin-cuda110 + +RUN rm -rf \ + /local/workspace/tappas \ + /opt/google \ + /local/workspace/doc \ + /local/workspace/hailort_examples \ + /usr/share \ + /usr/bin/docker* \ + /usr/bin/containerd* \ + /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_tutorials + +RUN pip install pip-autoremove +RUN pip-autoremove -y torch jupyter plotly matplotlib \ + ipython tensorboard pip-autoremove + +RUN pip install psutil +RUN pip cache purge +RUN rm -rf ~/.cache From 6a313c6cc5c9cc65d9b50f88567550a7f2856ba2 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Wed, 9 Oct 2024 13:27:20 +0200 Subject: [PATCH 12/36] updated actions --- .github/workflows/modelconverter_test.yaml | 20 ++++++++++++++++++++ .github/workflows/publish.yaml | 3 ++- .github/workflows/rvc2_test.yaml | 1 + .github/workflows/rvc3_test.yaml | 1 + .github/workflows/rvc4_test.yaml | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/modelconverter_test.yaml b/.github/workflows/modelconverter_test.yaml index 82bd2a6..a04eb23 100644 --- a/.github/workflows/modelconverter_test.yaml +++ b/.github/workflows/modelconverter_test.yaml @@ -8,6 +8,12 @@ on: type: string description: Which package to test + version: + required: true + type: string + description: > + Which version of underlying conversion tools to use + permissions: contents: read packages: read @@ -53,6 +59,20 @@ jobs: credentials_json: ${{ secrets.GCP_CREDENTIALS }} token_format: access_token + - name: Download build files from GCS + if: ${{ inputs.package }} != hailo + run: | + cd docker/extra_packages + if [ "$PACKAGE" = "rvc4" ]; then + gcloud storage cp \ + "${GS_BUILD_ARTIFACTS}/snpe-${VERSION}.zip" \ + "snpe-${VERSION}.zip" + elif [ "$PACKAGE" = "rvc2" ] || [ "$PACKAGE" = "rvc3" ]; then + gcloud storage cp \ + "${GS_BUILD_ARTIFACTS}/openvino-${VERSION}.tar.gz" \ + "openvino-${VERSION}.tar.gz" + fi + - name: Run Tests run: | pytest -s --verbose "tests/test_packages/test_$PACKAGE.py" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 3f153a4..d399164 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -7,6 +7,7 @@ on: required: true type: string description: Which package to publish + version: required: true type: string @@ -61,7 +62,7 @@ jobs: - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v1 - - name: Download file from GCS + - name: Download build files from GCS if: ${{ inputs.package }} != hailo run: | cd docker/extra_packages diff --git a/.github/workflows/rvc2_test.yaml b/.github/workflows/rvc2_test.yaml index 4b3c312..7fc026c 100644 --- a/.github/workflows/rvc2_test.yaml +++ b/.github/workflows/rvc2_test.yaml @@ -20,3 +20,4 @@ jobs: secrets: inherit with: package: rvc2 + version: "2022.3.0" diff --git a/.github/workflows/rvc3_test.yaml b/.github/workflows/rvc3_test.yaml index 1b5c263..282f6cc 100644 --- a/.github/workflows/rvc3_test.yaml +++ b/.github/workflows/rvc3_test.yaml @@ -20,3 +20,4 @@ jobs: secrets: inherit with: package: rvc3 + version: "2022.3.0" diff --git a/.github/workflows/rvc4_test.yaml b/.github/workflows/rvc4_test.yaml index 9045a4e..fb62158 100644 --- a/.github/workflows/rvc4_test.yaml +++ b/.github/workflows/rvc4_test.yaml @@ -20,3 +20,4 @@ jobs: secrets: inherit with: package: rvc4 + version: "2.23.0" From e5177419718b52340ce0e00554af769b2c6dea3a Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Wed, 9 Oct 2024 13:27:48 +0200 Subject: [PATCH 13/36] fix shell build --- modelconverter/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modelconverter/__main__.py b/modelconverter/__main__.py index 981d640..689eff1 100644 --- a/modelconverter/__main__.py +++ b/modelconverter/__main__.py @@ -315,6 +315,7 @@ def shell( gpu: GPUOption = True, ): """Boots up a shell inside a docker container for the specified target platform.""" + image = None if dev: image = docker_build(target.value, tag="dev", version=version) docker_exec( @@ -606,7 +607,7 @@ def archive( def version_callback(value: bool): if value: - typer.echo(f"ModelConverter Version: {version(__package__)}") + typer.echo(f"ModelConverter Version: {version('modelconverter')}") raise typer.Exit() From 0848fcceca5c1c55f7a4537599c3ee66094e86d6 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Wed, 9 Oct 2024 13:27:57 +0200 Subject: [PATCH 14/36] updated tag --- modelconverter/utils/docker_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modelconverter/utils/docker_utils.py b/modelconverter/utils/docker_utils.py index 3aa6169..cfdc349 100644 --- a/modelconverter/utils/docker_utils.py +++ b/modelconverter/utils/docker_utils.py @@ -85,7 +85,7 @@ def docker_build( if version is None: version = get_default_target_version(target) - tag = f"{tag}-{version}" + tag = f"{version}-{tag}" repository = f"luxonis/modelconverter-{target}:{tag}" args = [ From 82cd711cce06818295ef63712198a20dfa36deb7 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Wed, 9 Oct 2024 13:55:55 +0200 Subject: [PATCH 15/36] fixed env --- .github/workflows/modelconverter_test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/modelconverter_test.yaml b/.github/workflows/modelconverter_test.yaml index a04eb23..fa993d8 100644 --- a/.github/workflows/modelconverter_test.yaml +++ b/.github/workflows/modelconverter_test.yaml @@ -23,6 +23,7 @@ env: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_S3_ENDPOINT_URL: ${{ secrets.AWS_S3_ENDPOINT_URL }} PACKAGE: ${{ inputs.package }} + VERSION: ${{ inputs.version }} jobs: tests: @@ -61,6 +62,8 @@ jobs: - name: Download build files from GCS if: ${{ inputs.package }} != hailo + env: + GS_BUILD_ARTIFACTS: gs://luxonis-test-bucket/modelconverter/build-artifacts run: | cd docker/extra_packages if [ "$PACKAGE" = "rvc4" ]; then From 1eb2c363574dc7d480988a11d8cd508c93b4506e Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Wed, 9 Oct 2024 15:16:58 +0200 Subject: [PATCH 16/36] fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d43364b..315ce36 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ To build the images, you need to download additional packages depending on the s **RVC2** -Requires `openvino-`.tar.gz` to be present in `docker/extra_packages`. +Requires `openvino-.tar.gz` to be present in `docker/extra_packages/`. - Version `2023.2.0` archive can be downloaded from [here](https://drive.google.com/file/d/1IXtYi1Mwpsg3pr5cDXlEHdSUZlwJRTVP/view?usp=share_link). From 0ecc9e26e1eed55bf3fea1084185c0c9a25511c3 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 00:56:26 +0200 Subject: [PATCH 17/36] updated hailo public image --- docker/hailo/Dockerfile.public | 60 ++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/docker/hailo/Dockerfile.public b/docker/hailo/Dockerfile.public index 9171c31..159a102 100644 --- a/docker/hailo/Dockerfile.public +++ b/docker/hailo/Dockerfile.public @@ -1,17 +1,6 @@ FROM hailo_ai_sw_suite_2024-07:1 USER root -COPY requirements.txt . - -RUN pip install --upgrade pip && \ - pip install -r requirements.txt && \ - pip install --extra-index-url \ - https://developer.download.nvidia.com/compute/redist \ - nvidia-dali-cuda110 && \ - pip install --extra-index-url \ - https://developer.download.nvidia.com/compute/redist \ - nvidia-dali-tf-plugin-cuda110 - RUN rm -rf \ /local/workspace/tappas \ /opt/google \ @@ -22,22 +11,51 @@ RUN rm -rf \ /usr/bin/containerd* \ /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_tutorials -RUN pip install pip-autoremove && \ - pip-autoremove -y torch jupyter plotly matplotlib ipython \ - tensorboard pip-autoremove && \ - pip install psutil && \ - pip cache purge && \ +COPY requirements.txt . + +RUN < /etc/profile.d/certifi.sh + chmod +x /app/entrypoint.sh -COPY modelconverter pyproject.toml requirements.txt /app/modelconverter/ -RUN cd modelconverter -RUN cd modelconverter && pip install -e . --no-deps +EOF -RUN echo "export SSL_CERT_FILE=$(python -m certifi)" > /etc/profile.d/certifi.sh ENTRYPOINT ["/app/entrypoint.sh"] From 96a0ccdb39629f351f0fd980d9642e00c790df77 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 01:22:39 +0200 Subject: [PATCH 18/36] changed hailo base tag --- docker/hailo/Dockerfile | 2 +- docker/hailo/Dockerfile.base | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docker/hailo/Dockerfile b/docker/hailo/Dockerfile index 99a6afd..7af6f0d 100644 --- a/docker/hailo/Dockerfile +++ b/docker/hailo/Dockerfile @@ -4,7 +4,7 @@ ARG VERSION=2.23.0 -FROM ghcr.io/luxonis/modelconverter-base-hailo:${VERSION}-latest +FROM ghcr.io/luxonis/modelconverter-hailo:${VERSION}-base ENV IN_DOCKER= ENV VERSION=${VERSION} diff --git a/docker/hailo/Dockerfile.base b/docker/hailo/Dockerfile.base index cb6c711..69981ad 100644 --- a/docker/hailo/Dockerfile.base +++ b/docker/hailo/Dockerfile.base @@ -3,11 +3,20 @@ ARG VERSION=2024.07 FROM hailo_ai_sw_suite_${VERSION/./-}:1 as BASE USER root +RUN rm -rf \ + /local/workspace/tappas \ + /opt/google \ + /local/workspace/doc \ + /local/workspace/hailort_examples \ + /usr/share \ + /usr/bin/docker* \ + /usr/bin/containerd* \ + /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_tutorials -RUN pip install --upgrade pip COPY requirements.txt requirements.txt +RUN pip install --upgrade pip RUN pip install -r requirements.txt RUN pip install --extra-index-url \ https://developer.download.nvidia.com/compute/redist \ @@ -17,15 +26,6 @@ RUN pip install --extra-index-url \ https://developer.download.nvidia.com/compute/redist \ nvidia-dali-tf-plugin-cuda110 -RUN rm -rf \ - /local/workspace/tappas \ - /opt/google \ - /local/workspace/doc \ - /local/workspace/hailort_examples \ - /usr/share \ - /usr/bin/docker* \ - /usr/bin/containerd* \ - /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_tutorials RUN pip install pip-autoremove RUN pip-autoremove -y torch jupyter plotly matplotlib \ From 785ceefa61438751c054374552252ac5a8841bb3 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 04:25:32 +0200 Subject: [PATCH 19/36] updated dockerfiles --- docker/hailo/Dockerfile | 9 +++++++++ docker/hailo/Dockerfile.base | 4 ---- docker/rvc2/Dockerfile | 11 ++++++----- docker/rvc3/Dockerfile | 10 +++++----- docker/rvc4/Dockerfile | 10 +++++----- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/docker/hailo/Dockerfile b/docker/hailo/Dockerfile index 7af6f0d..09c9be8 100644 --- a/docker/hailo/Dockerfile +++ b/docker/hailo/Dockerfile @@ -9,6 +9,15 @@ FROM ghcr.io/luxonis/modelconverter-hailo:${VERSION}-base ENV IN_DOCKER= ENV VERSION=${VERSION} +COPY requirements.txt requirements.txt + +RUN <> ~/.bashrc diff --git a/docker/rvc3/Dockerfile b/docker/rvc3/Dockerfile index 34818c2..2c8f654 100644 --- a/docker/rvc3/Dockerfile +++ b/docker/rvc3/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8-slim as BASE +FROM python:3.8-slim AS base RUN < Date: Thu, 10 Oct 2024 06:03:37 +0200 Subject: [PATCH 20/36] updated version --- modelconverter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modelconverter/__init__.py b/modelconverter/__init__.py index ca853c8..a8861ab 100644 --- a/modelconverter/__init__.py +++ b/modelconverter/__init__.py @@ -1,7 +1,7 @@ import pkg_resources from luxonis_ml.utils import PUT_FILE_REGISTRY -__version__ = "0.2.0" +__version__ = "0.3.0" def load_put_file_plugins() -> None: From 8ecc8890a0691be0a4a4396a3fef57ac78ea44ee Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 06:03:48 +0200 Subject: [PATCH 21/36] fixed failing docker build due to dynamic version --- docker/hailo/Dockerfile | 9 +++++++-- docker/hailo/Dockerfile.public | 11 +++++++++-- docker/rvc2/Dockerfile | 16 +++++++++++++--- docker/rvc3/Dockerfile | 16 ++++++++++++++-- docker/rvc4/Dockerfile | 13 +++++++++++-- 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/docker/hailo/Dockerfile b/docker/hailo/Dockerfile index 09c9be8..944848b 100644 --- a/docker/hailo/Dockerfile +++ b/docker/hailo/Dockerfile @@ -13,6 +13,8 @@ COPY requirements.txt requirements.txt RUN < /etc/profile.d/certifi.sh - pip install -e ./modelconverter --no-deps --no-cache-dir + pip install -e . --no-deps --no-cache-dir chmod +x /app/entrypoint.sh EOF diff --git a/docker/hailo/Dockerfile.public b/docker/hailo/Dockerfile.public index 159a102..20ceb03 100644 --- a/docker/hailo/Dockerfile.public +++ b/docker/hailo/Dockerfile.public @@ -15,6 +15,8 @@ COPY requirements.txt . RUN < /etc/profile.d/certifi.sh chmod +x /app/entrypoint.sh diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index 87fdc80..ba9617a 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -30,6 +30,8 @@ COPY --link docker/extra_packages/mo_patch.diff . RUN <> ~/.bashrc chmod +x /app/entrypoint.sh diff --git a/docker/rvc3/Dockerfile b/docker/rvc3/Dockerfile index 2c8f654..c9f0ffe 100644 --- a/docker/rvc3/Dockerfile +++ b/docker/rvc3/Dockerfile @@ -2,6 +2,8 @@ FROM python:3.8-slim AS base RUN <> ~/.bashrc chmod +x /app/entrypoint.sh diff --git a/docker/rvc4/Dockerfile b/docker/rvc4/Dockerfile index 5032b73..5d3ad4d 100644 --- a/docker/rvc4/Dockerfile +++ b/docker/rvc4/Dockerfile @@ -5,6 +5,8 @@ ENV VERSION=${VERSION} RUN < Date: Thu, 10 Oct 2024 08:31:45 +0200 Subject: [PATCH 22/36] fixed --version --- modelconverter/__main__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modelconverter/__main__.py b/modelconverter/__main__.py index 689eff1..b7bebe6 100644 --- a/modelconverter/__main__.py +++ b/modelconverter/__main__.py @@ -479,9 +479,7 @@ def convert( archive_cfg, preprocessing, main_stage, - exporter.inference_model_path - if isinstance(exporter, Exporter) - else exporter.exporters[main_stage].inference_model_path, + out_models[0], ) generator = ArchiveGenerator( archive_name=f"{cfg.name}.{target.value.lower()}", @@ -607,7 +605,7 @@ def archive( def version_callback(value: bool): if value: - typer.echo(f"ModelConverter Version: {version('modelconverter')}") + typer.echo(f"ModelConverter Version: {version('modelconv')}") raise typer.Exit() @@ -616,6 +614,7 @@ def common( _: Annotated[ bool, typer.Option( + "-v", "--version", callback=version_callback, help="Show version and exit.", From 6b7dcd2970b0c3d1067477ceafb185e843da6341 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 08:46:24 +0200 Subject: [PATCH 23/36] fixed mean/scale --- modelconverter/packages/rvc2/exporter.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modelconverter/packages/rvc2/exporter.py b/modelconverter/packages/rvc2/exporter.py index cd1440d..7a0817f 100644 --- a/modelconverter/packages/rvc2/exporter.py +++ b/modelconverter/packages/rvc2/exporter.py @@ -1,6 +1,5 @@ import subprocess import tempfile -from importlib.metadata import version from functools import partial from importlib.metadata import version from logging import getLogger @@ -8,7 +7,7 @@ from os import environ as env from os import path from pathlib import Path -from typing import Any, Dict, Final +from typing import Any, Dict, Final, Iterable import tflite2onnx from rich.progress import track @@ -68,9 +67,7 @@ def __init__(self, config: SingleStageConfig, output_dir: Path): def _export_openvino_ir(self) -> Path: args = self.mo_args self._add_args(args, ["--output_dir", self.intermediate_outputs_dir]) - self._add_args( - args, ["--output", ",".join(name for name in self.outputs)] - ) + self._add_args(args, ["--output", ",".join(self.outputs)]) if self.compress_to_fp16: if OV_2021: self._add_args(args, ["--data_type", "FP16"]) @@ -84,7 +81,7 @@ def _export_openvino_ir(self) -> Path: inp_str += "," inp_str += name if inp.shape is not None: - inp_str += f'[{" ".join(map(str, inp.shape))}]' + inp_str += f"{_lst_join(inp.shape, sep=' ')}" if inp.data_type is not None: if OV_2021 and self.compress_to_fp16: data_type = DataType("float16") @@ -95,7 +92,7 @@ def _export_openvino_ir(self) -> Path: if len(inp.frozen_value) == 1: value = inp.frozen_value[0] else: - value = f'[{",".join(map(str, inp.frozen_value))}]' + value = f"{_lst_join(inp.frozen_value)}" inp_str += f"->{value}" args.extend(["--input", inp_str]) @@ -121,11 +118,13 @@ def _export_openvino_ir(self) -> Path: for name, inp in self.inputs.items(): if inp.mean_values is not None: self._add_args( - args, ["--mean_values", f"{name}{inp.mean_values}"] + args, + ["--mean_values", f"{name}{_lst_join(inp.mean_values)}"], ) if inp.scale_values is not None: self._add_args( - args, ["--scale_values", f"{name}{inp.scale_values}"] + args, + ["--scale_values", f"{name}{_lst_join(inp.scale_values)}"], ) if inp.reverse_input_channels: self._add_args(args, ["--reverse_input_channels"]) @@ -353,3 +352,7 @@ def exporter_buildinfo(self) -> Dict[str, Any]: "target_devices": [self.device], **self._device_specific_buildinfo, } + + +def _lst_join(args: Iterable[Any], sep: str = ",") -> str: + return f"[{sep.join(map(str, args))}]" From 031b46accfdcab7b12387ca4f6f2699698b0ec69 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 19:10:49 +0200 Subject: [PATCH 24/36] added mo 2021.4 patch --- docker/patches/mo-2021.4.patch | 26 +++++++++++++++++++ .../mo_patch.diff => patches/mo-2022.3.patch} | 4 +-- docker/rvc2/Dockerfile | 14 ++++++---- docker/scripts/install_openssl.sh | 12 --------- 4 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 docker/patches/mo-2021.4.patch rename docker/{extra_packages/mo_patch.diff => patches/mo-2022.3.patch} (99%) delete mode 100644 docker/scripts/install_openssl.sh diff --git a/docker/patches/mo-2021.4.patch b/docker/patches/mo-2021.4.patch new file mode 100644 index 0000000..86fcc83 --- /dev/null +++ b/docker/patches/mo-2021.4.patch @@ -0,0 +1,26 @@ +--- /opt/intel/deployment_tools/model_optimizer/mo/main.py 2021-06-22 20:30:31.000000000 +0000 ++++ shared_with_container/main.py 2024-10-10 12:47:05.718612915 +0000 +@@ -29,7 +29,7 @@ + from mo.utils.cli_parser import get_placeholder_shapes, get_tuple_values, get_model_name, \ + get_common_cli_options, get_caffe_cli_options, get_tf_cli_options, get_mxnet_cli_options, get_kaldi_cli_options, \ + get_onnx_cli_options, get_mean_scale_dictionary, parse_tuple_pairs, get_freeze_placeholder_values, get_meta_info, \ +- parse_transform, check_available_transforms ++ parse_transform, check_available_transforms, parse_input_value + from mo.utils.error import Error, FrameworkError + from mo.utils.find_ie_version import find_ie_version + from mo.utils.get_ov_update_message import get_ov_update_message +@@ -206,7 +206,13 @@ + + mean_values = parse_tuple_pairs(argv.mean_values) + scale_values = parse_tuple_pairs(argv.scale_values) +- mean_scale = get_mean_scale_dictionary(mean_values, scale_values, argv.input) ++ ++ __input_names = [] ++ for input_value in argv.input.split(','): ++ __node_name = parse_input_value(input_value)[0] ++ __input_names.append(__node_name) ++ __input_names = ",".join(__input_names) ++ mean_scale = get_mean_scale_dictionary(mean_values, scale_values, __input_names) + argv.mean_scale_values = mean_scale + + if not os.path.exists(argv.output_dir): diff --git a/docker/extra_packages/mo_patch.diff b/docker/patches/mo-2022.3.patch similarity index 99% rename from docker/extra_packages/mo_patch.diff rename to docker/patches/mo-2022.3.patch index f9aaf7d..79e23b7 100644 --- a/docker/extra_packages/mo_patch.diff +++ b/docker/patches/mo-2022.3.patch @@ -1,11 +1,11 @@ --- convert_impl.py 2023-08-09 14:48:35.300720667 +0000 +++ /usr/local/lib/python3.8/site-packages/openvino/tools/mo/convert_impl.py 2023-08-09 14:50:48.555078595 +0000 @@ -275,7 +275,7 @@ - + mean_values = parse_tuple_pairs(argv.mean_values) scale_values = parse_tuple_pairs(argv.scale_values) - mean_scale = get_mean_scale_dictionary(mean_values, scale_values, argv.input) + mean_scale = get_mean_scale_dictionary(mean_values, scale_values, ','.join(argv.inputs_list)) argv.mean_scale_values = mean_scale argv.layout_values = get_layout_values(argv.layout, argv.source_layout, argv.target_layout) - + diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index ba9617a..2e04545 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -26,8 +26,6 @@ COPY --link docker/extra_packages/openvino-${VERSION}.tar.gz . COPY --link requirements.txt requirements.txt COPY --link docker/rvc2/requirements.txt requirements-rvc2.txt -COPY --link docker/extra_packages/mo_patch.diff . - RUN < /etc/ld.so.conf.d/openssl-1.1.1b.conf -cd /opt/openssl/openssl-1.1.1b -./config --prefix=/opt/openssl --openssldir=/opt/openssl/ssl -make -make install From 73231e68f7b7e21b76b4b842eab39d057528af4e Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 19:14:43 +0200 Subject: [PATCH 25/36] fixed nn archive export for rvc2 2021.4 --- modelconverter/__main__.py | 4 ++- modelconverter/utils/metadata.py | 57 ++++++++++++++++++++++++++++++-- modelconverter/utils/types.py | 26 +++++++++++++-- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/modelconverter/__main__.py b/modelconverter/__main__.py index b7bebe6..fac2772 100644 --- a/modelconverter/__main__.py +++ b/modelconverter/__main__.py @@ -479,7 +479,9 @@ def convert( archive_cfg, preprocessing, main_stage, - out_models[0], + exporter.inference_model_path + if isinstance(exporter, Exporter) + else exporter.exporters[main_stage].inference_model_path, ) generator = ArchiveGenerator( archive_name=f"{cfg.name}.{target.value.lower()}", diff --git a/modelconverter/utils/metadata.py b/modelconverter/utils/metadata.py index 685ac6b..8d020c7 100644 --- a/modelconverter/utils/metadata.py +++ b/modelconverter/utils/metadata.py @@ -1,4 +1,5 @@ import io +from importlib.metadata import version from dataclasses import dataclass from pathlib import Path from typing import Dict, List @@ -76,6 +77,58 @@ def _get_metadata_dlc(model_path: Path) -> Metadata: def _get_metadata_ir(bin_path: Path, xml_path: Path) -> Metadata: + if version("openvino") == "2021.4.0": + return _get_metadata_ir_ie(bin_path, xml_path) + return _get_metadata_ir_runtime(bin_path, xml_path) + + +def _get_metadata_ir_ie(bin_path: Path, xml_path: Path) -> Metadata: + """ + Extracts metadata from an OpenVINO IR model using the Inference Engine API. + + Args: + bin_path (Path): Path to the model's .bin file. + xml_path (Path): Path to the model's .xml file. + + Returns: + Metadata: An object containing input/output shapes and data types. + """ + from openvino.inference_engine import IECore + + ie = IECore() + try: + network = ie.read_network(model=str(xml_path), weights=str(bin_path)) + except Exception as e: + raise ValueError( + f"Failed to load IR model: `{bin_path}` and `{xml_path}`" + ) from e + + input_shapes = {} + input_dtypes = {} + output_shapes = {} + output_dtypes = {} + + for input_name, input_info in network.input_info.items(): + input_shapes[input_name] = list(input_info.input_data.shape) + + ie_precision = input_info.input_data.precision + input_dtypes[input_name] = DataType.from_ir_ie_dtype(ie_precision) + + for output_name, output_data in network.outputs.items(): + output_shapes[output_name] = list(output_data.shape) + + ie_precision = output_data.precision + output_dtypes[output_name] = DataType.from_ir_ie_dtype(ie_precision) + + return Metadata( + input_shapes=input_shapes, + input_dtypes=input_dtypes, + output_shapes=output_shapes, + output_dtypes=output_dtypes, + ) + + +def _get_metadata_ir_runtime(bin_path: Path, xml_path: Path) -> Metadata: from openvino.runtime import Core ie = Core() @@ -94,13 +147,13 @@ def _get_metadata_ir(bin_path: Path, xml_path: Path) -> Metadata: for inp in model.inputs: name = list(inp.names)[0] input_shapes[name] = list(inp.shape) - input_dtypes[name] = DataType.from_ir_dtype( + input_dtypes[name] = DataType.from_ir_runtime_dtype( inp.element_type.get_type_name() ) for output in model.outputs: name = list(output.names)[0] output_shapes[name] = list(output.shape) - output_dtypes[name] = DataType.from_ir_dtype( + output_dtypes[name] = DataType.from_ir_runtime_dtype( output.element_type.get_type_name() ) diff --git a/modelconverter/utils/types.py b/modelconverter/utils/types.py index 26c77f7..fee1d89 100644 --- a/modelconverter/utils/types.py +++ b/modelconverter/utils/types.py @@ -1,7 +1,7 @@ from enum import Enum from pathlib import Path - from typing import Union + import numpy as np from onnx.onnx_pb import TensorProto @@ -131,7 +131,27 @@ def from_numpy_dtype(cls, dtype: np.dtype) -> "DataType": return cls(dtype_map[dtype]) @classmethod - def from_ir_dtype(cls, dtype: str) -> "DataType": + def from_ir_ie_dtype(cls, dtype: str) -> "DataType": + dtype_map = { + "FP16": "float16", + "FP32": "float32", + "FP64": "float64", + "I8": "int8", + "I16": "int16", + "I32": "int32", + "I64": "int64", + "U8": "uint8", + "U16": "uint16", + "U32": "uint32", + "U64": "uint64", + "BOOL": "boolean", + } + if dtype not in dtype_map: + raise ValueError(f"Unsupported IR data type: `{dtype}`") + return cls(dtype_map[dtype]) + + @classmethod + def from_ir_runtime_dtype(cls, dtype: str) -> "DataType": dtype_map = { "f16": "float16", "f32": "float32", @@ -147,7 +167,7 @@ def from_ir_dtype(cls, dtype: str) -> "DataType": "boolean": "boolean", } if dtype not in dtype_map: - raise ValueError(f"Unsupported IR data type: `{dtype}`") + raise ValueError(f"Unsupported IR runtime data type: `{dtype}`") return cls(dtype_map[dtype]) def as_numpy_dtype(self) -> np.dtype: From b73c4de581dcd55d70ca3f7ef3e1b722d31fc61d Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 19:15:18 +0200 Subject: [PATCH 26/36] updated actions --- .github/workflows/hailo_publish.yaml | 8 +++++++- .github/workflows/hailo_test.yaml | 7 +++++++ .github/workflows/rvc2_test.yaml | 8 +++++++- .github/workflows/rvc3_test.yaml | 8 +++++++- .github/workflows/rvc4_test.yaml | 14 +++++++++++++- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/.github/workflows/hailo_publish.yaml b/.github/workflows/hailo_publish.yaml index 450bded..2dacdde 100644 --- a/.github/workflows/hailo_publish.yaml +++ b/.github/workflows/hailo_publish.yaml @@ -10,9 +10,15 @@ on: jobs: hailo-publish: + + strategy: + fail-fast: false + matrix: + version: ["2024.04", "2024.07"] + uses: ./.github/workflows/publish.yaml secrets: inherit with: package: hailo - version: "2024.04" + version: ${{ matrix.version }} diff --git a/.github/workflows/hailo_test.yaml b/.github/workflows/hailo_test.yaml index 047de74..4ddb609 100644 --- a/.github/workflows/hailo_test.yaml +++ b/.github/workflows/hailo_test.yaml @@ -16,8 +16,15 @@ on: jobs: hailo-test: + + strategy: + fail-fast: false + matrix: + version: ["2024.04", "2024.07"] + uses: ./.github/workflows/modelconverter_test.yaml secrets: inherit with: package: hailo + version: ${{ matrix.version }} diff --git a/.github/workflows/rvc2_test.yaml b/.github/workflows/rvc2_test.yaml index 7fc026c..0957110 100644 --- a/.github/workflows/rvc2_test.yaml +++ b/.github/workflows/rvc2_test.yaml @@ -16,8 +16,14 @@ on: jobs: rvc2-test: + + strategy: + fail-fast: false + matrix: + version: ["2021.4.0", "2022.3.0"] + uses: ./.github/workflows/modelconverter_test.yaml secrets: inherit with: package: rvc2 - version: "2022.3.0" + version: ${{ matrix.version }} diff --git a/.github/workflows/rvc3_test.yaml b/.github/workflows/rvc3_test.yaml index 282f6cc..ad70920 100644 --- a/.github/workflows/rvc3_test.yaml +++ b/.github/workflows/rvc3_test.yaml @@ -16,8 +16,14 @@ on: jobs: rvc3-test: + + strategy: + fail-fast: false + matrix: + version: ["2021.4.0", "2022.3.0"] + uses: ./.github/workflows/modelconverter_test.yaml secrets: inherit with: package: rvc3 - version: "2022.3.0" + version: ${{ matrix.version }} diff --git a/.github/workflows/rvc4_test.yaml b/.github/workflows/rvc4_test.yaml index fb62158..7607395 100644 --- a/.github/workflows/rvc4_test.yaml +++ b/.github/workflows/rvc4_test.yaml @@ -16,8 +16,20 @@ on: jobs: rvc4-test: + + strategy: + fail-fast: false + matrix: + version: + - "2.21.0" + - "2.22.10" + - "2.23.0" + - "2.24.0" + - "2.25.0" + - "2.26.2" + uses: ./.github/workflows/modelconverter_test.yaml secrets: inherit with: package: rvc4 - version: "2.23.0" + version: ${{ matrix.version }} From f3291a59589f1de54a88dd877e530a9103fdacbc Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 19:20:32 +0200 Subject: [PATCH 27/36] fixed test action --- .github/workflows/modelconverter_test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/modelconverter_test.yaml b/.github/workflows/modelconverter_test.yaml index fa993d8..d093d96 100644 --- a/.github/workflows/modelconverter_test.yaml +++ b/.github/workflows/modelconverter_test.yaml @@ -65,6 +65,7 @@ jobs: env: GS_BUILD_ARTIFACTS: gs://luxonis-test-bucket/modelconverter/build-artifacts run: | + mkdir -p docker/extra_packages cd docker/extra_packages if [ "$PACKAGE" = "rvc4" ]; then gcloud storage cp \ From 54338624fd7366662c5b785edbaf37dee858fab9 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 20:23:48 +0200 Subject: [PATCH 28/36] added --tool-version argument to pytest --- .github/workflows/modelconverter_test.yaml | 6 +++--- .github/workflows/publish.yaml | 2 +- modelconverter/packages/rvc2/inferer.py | 3 ++- tests/conftest.py | 19 ++++++++++++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/modelconverter_test.yaml b/.github/workflows/modelconverter_test.yaml index d093d96..05d210f 100644 --- a/.github/workflows/modelconverter_test.yaml +++ b/.github/workflows/modelconverter_test.yaml @@ -67,11 +67,11 @@ jobs: run: | mkdir -p docker/extra_packages cd docker/extra_packages - if [ "$PACKAGE" = "rvc4" ]; then + if [ "${PACKAGE}" = "rvc4" ]; then gcloud storage cp \ "${GS_BUILD_ARTIFACTS}/snpe-${VERSION}.zip" \ "snpe-${VERSION}.zip" - elif [ "$PACKAGE" = "rvc2" ] || [ "$PACKAGE" = "rvc3" ]; then + elif [ "${PACKAGE}" = "rvc2" ] || [ "${PACKAGE}" = "rvc3" ]; then gcloud storage cp \ "${GS_BUILD_ARTIFACTS}/openvino-${VERSION}.tar.gz" \ "openvino-${VERSION}.tar.gz" @@ -79,5 +79,5 @@ jobs: - name: Run Tests run: | - pytest -s --verbose "tests/test_packages/test_$PACKAGE.py" + pytest -s --verbose "tests/test_packages/test_${PACKAGE}.py" --tool-version "$VERSION" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index d399164..07c980c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -70,7 +70,7 @@ jobs: gcloud storage cp \ "${GS_BUILD_ARTIFACTS}/snpe-${VERSION}.zip" \ "snpe-${VERSION}.zip" - elif [ "$PACKAGE" = "rvc2" ] || [ "$PACKAGE" = "rvc3" ]; then + elif [ "${PACKAGE}" = "rvc2" ] || [ "${PACKAGE}" = "rvc3" ]; then gcloud storage cp \ "${GS_BUILD_ARTIFACTS}/openvino-${VERSION}.tar.gz" \ "openvino-${VERSION}.tar.gz" diff --git a/modelconverter/packages/rvc2/inferer.py b/modelconverter/packages/rvc2/inferer.py index 1adaa21..18113cf 100644 --- a/modelconverter/packages/rvc2/inferer.py +++ b/modelconverter/packages/rvc2/inferer.py @@ -2,7 +2,6 @@ from typing import Dict import numpy as np -from openvino.inference_engine.ie_api import IECore from modelconverter.utils import read_image @@ -11,6 +10,8 @@ class RVC2Inferer(Inferer): def setup(self): + from openvino.inference_engine.ie_api import IECore + self.xml_path = self.model_path self.bin_path = self.model_path.with_suffix(".bin") ie = IECore() diff --git a/tests/conftest.py b/tests/conftest.py index 0d1552b..c317781 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -91,11 +91,25 @@ setup_logging(use_rich=True) +def pytest_addoption(parser): + parser.addoption( + "--tool-version", + action="store", + required=True, + help="Version of the internal conversion tool", + ) + + +@pytest.fixture(scope="session") +def tool_version(request): + return request.config.getoption("--tool-version") + + def prepare_fixture( service, model_name, dataset_url, metric, input_names, extra_args ): @pytest.fixture(scope="session") - def _fixture(): + def _fixture(tool_version): return prepare( service=service, model_name=model_name, @@ -103,6 +117,7 @@ def _fixture(): metric=metric, input_names=input_names, extra_args=extra_args, + tool_version=tool_version, ) return _fixture @@ -130,6 +145,7 @@ def prepare( dataset_url: str, metric: Type[Metric], input_names: List[str], + tool_version: str, model_type: str = "onnx", extra_args: str = "", ) -> Tuple[ @@ -195,6 +211,7 @@ def prepare( f"--path {config_url} " f"--output-dir _{model_name}-test " "--dev " + f"--version {tool_version} " "--no-gpu " f"input_model {file_url} " "hailo.compression_level 0 " From 9a2d90e30bf014dd6068ea826c8d52d03e067627 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Thu, 10 Oct 2024 23:55:55 +0200 Subject: [PATCH 29/36] fix infer version for tests --- .github/workflows/modelconverter_test.yaml | 2 +- tests/test_packages/common.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/modelconverter_test.yaml b/.github/workflows/modelconverter_test.yaml index 05d210f..50f9c73 100644 --- a/.github/workflows/modelconverter_test.yaml +++ b/.github/workflows/modelconverter_test.yaml @@ -79,5 +79,5 @@ jobs: - name: Run Tests run: | - pytest -s --verbose "tests/test_packages/test_${PACKAGE}.py" --tool-version "$VERSION" + pytest -s --verbose "tests/test_packages/test_${PACKAGE}.py" --tool-version "${VERSION}" diff --git a/tests/test_packages/common.py b/tests/test_packages/common.py index 5692ef6..15b31e1 100644 --- a/tests/test_packages/common.py +++ b/tests/test_packages/common.py @@ -24,7 +24,7 @@ def check_convert(convert_env): assert result.returncode == 0 -def mnist_infer(mnist_env): +def mnist_infer(mnist_env, tool_version: str): ( config_url, converted_model_path, @@ -46,6 +46,7 @@ def mnist_infer(mnist_env): f"--input-path {input_files_dir.parent} " f"--path {config_url} " "--dev " + f"--version {tool_version} " "--no-gpu" ) assert result.returncode == 0, result.stderr + result.stdout @@ -60,7 +61,7 @@ def mnist_infer(mnist_env): compare_metrics(metric.get_result(), expected_metric) -def resnet18_infer(resnet18_env): +def resnet18_infer(resnet18_env, tool_version: str): ( config_url, converted_model_path, @@ -87,6 +88,7 @@ def resnet18_infer(resnet18_env): f"--input-path {input_files_dir.parent} " f"--path {config_url} " "--dev " + f"--version {tool_version} " "--no-gpu" ) assert result.returncode == 0, result.stderr + result.stdout @@ -101,7 +103,7 @@ def resnet18_infer(resnet18_env): compare_metrics(metric.get_result(), expected_metric) -def yolov6n_infer(yolov6n_env): +def yolov6n_infer(yolov6n_env, tool_version: str): output_names = [f"output{i}_yolov6r2" for i in range(1, 4)] ( config_url, @@ -132,6 +134,7 @@ def yolov6n_infer(yolov6n_env): f"--input-path {input_files_dir.parent} " f"--path {config_url} " "--dev " + f"--version {tool_version} " "--no-gpu" ) assert result.returncode == 0, result.stderr + result.stdout From 79592564d37e8fef1ad728289242d20f048774f8 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 11 Oct 2024 00:01:50 +0200 Subject: [PATCH 30/36] patching rvc3 mo --- docker/rvc3/Dockerfile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docker/rvc3/Dockerfile b/docker/rvc3/Dockerfile index c9f0ffe..5c1cb1a 100644 --- a/docker/rvc3/Dockerfile +++ b/docker/rvc3/Dockerfile @@ -24,8 +24,6 @@ COPY --link docker/extra_packages/openvino-2022.3.0.tar.gz . COPY --link requirements.txt requirements.txt COPY --link docker/rvc3/requirements.txt requirements-rvc3.txt -COPY --link docker/extra_packages/mo_patch.diff . - RUN < Date: Fri, 11 Oct 2024 00:27:39 +0200 Subject: [PATCH 31/36] fixed tests --- modelconverter/utils/config.py | 1 - modelconverter/utils/metadata.py | 5 ++-- tests/test_packages/test_hailo.py | 26 ++++++-------------- tests/test_packages/test_rvc2.py | 16 ++++++------- tests/test_packages/test_rvc3.py | 40 +++++++------------------------ tests/test_packages/test_rvc4.py | 22 +++++++++-------- 6 files changed, 38 insertions(+), 72 deletions(-) diff --git a/modelconverter/utils/config.py b/modelconverter/utils/config.py index 8be54c4..aab6582 100644 --- a/modelconverter/utils/config.py +++ b/modelconverter/utils/config.py @@ -534,7 +534,6 @@ def _validate_single_stage_name(self) -> Self: return self - def _extract_bin_xml_from_ir(ir_path: Any) -> Tuple[Path, Path]: """Extracts the corresponding second path from a single IR path. diff --git a/modelconverter/utils/metadata.py b/modelconverter/utils/metadata.py index 8d020c7..bdfe802 100644 --- a/modelconverter/utils/metadata.py +++ b/modelconverter/utils/metadata.py @@ -1,6 +1,6 @@ import io -from importlib.metadata import version from dataclasses import dataclass +from importlib.metadata import version from pathlib import Path from typing import Dict, List @@ -83,8 +83,7 @@ def _get_metadata_ir(bin_path: Path, xml_path: Path) -> Metadata: def _get_metadata_ir_ie(bin_path: Path, xml_path: Path) -> Metadata: - """ - Extracts metadata from an OpenVINO IR model using the Inference Engine API. + """Extracts metadata from an OpenVINO IR model using the Inference Engine API. Args: bin_path (Path): Path to the model's .bin file. diff --git a/tests/test_packages/test_hailo.py b/tests/test_packages/test_hailo.py index 509da80..ecd0ccf 100644 --- a/tests/test_packages/test_hailo.py +++ b/tests/test_packages/test_hailo.py @@ -1,37 +1,25 @@ -import pytest - -from .common import check_convert, mnist_infer, resnet18_infer, yolov6n_infer +from .common import check_convert, mnist_infer, resnet18_infer def test_mnist_convert(hailo_mnist_onnx_env): check_convert(hailo_mnist_onnx_env) -def test_mnist_infer(hailo_mnist_onnx_env): - mnist_infer(hailo_mnist_onnx_env) +def test_mnist_infer(hailo_mnist_onnx_env, tool_version): + mnist_infer(hailo_mnist_onnx_env, tool_version) def test_resnet18_convert(hailo_resnet18_onnx_env): check_convert(hailo_resnet18_onnx_env) -def test_resnet18_infer(hailo_resnet18_onnx_env): - resnet18_infer(hailo_resnet18_onnx_env) +def test_resnet18_infer(hailo_resnet18_onnx_env, tool_version): + resnet18_infer(hailo_resnet18_onnx_env, tool_version) def test_resnet18_archive_convert(hailo_resnet18_archive_env): check_convert(hailo_resnet18_archive_env) -def test_resnet18_archive_infer(hailo_resnet18_archive_env): - resnet18_infer(hailo_resnet18_archive_env) - - -@pytest.mark.skip(reason="Cannot be converted.") -def test_yolov6_convert(hailo_yolov6n_env): - check_convert(hailo_yolov6n_env) - - -@pytest.mark.skip(reason="Cannot be converted.") -def test_yolov6n_infer(hailo_yolov6n_onnx_env): - yolov6n_infer(hailo_yolov6n_onnx_env) +def test_resnet18_archive_infer(hailo_resnet18_archive_env, tool_version): + resnet18_infer(hailo_resnet18_archive_env, tool_version) diff --git a/tests/test_packages/test_rvc2.py b/tests/test_packages/test_rvc2.py index 3f3fe0b..d4724a0 100644 --- a/tests/test_packages/test_rvc2.py +++ b/tests/test_packages/test_rvc2.py @@ -7,8 +7,8 @@ def test_mnist_convert(rvc2_mnist_onnx_env): check_convert(rvc2_mnist_onnx_env) -def test_mnist_infer(rvc2_mnist_onnx_env): - mnist_infer(rvc2_mnist_onnx_env) +def test_mnist_infer(rvc2_mnist_onnx_env, tool_version): + mnist_infer(rvc2_mnist_onnx_env, tool_version) def test_resnet18_convert(rvc2_resnet18_onnx_env): @@ -23,20 +23,20 @@ def test_resnet18_archive_convert(rvc2_resnet18_archive_env): check_convert(rvc2_resnet18_archive_env) -def test_resnet18_infer(rvc2_resnet18_onnx_env): - resnet18_infer(rvc2_resnet18_onnx_env) +def test_resnet18_infer(rvc2_resnet18_onnx_env, tool_version): + resnet18_infer(rvc2_resnet18_onnx_env, tool_version) -def test_resnet18_archive_infer(rvc2_resnet18_archive_env): - resnet18_infer(rvc2_resnet18_archive_env) +def test_resnet18_archive_infer(rvc2_resnet18_archive_env, tool_version): + resnet18_infer(rvc2_resnet18_archive_env, tool_version) def test_yolov6_convert(rvc2_yolov6n_onnx_env): check_convert(rvc2_yolov6n_onnx_env) -def test_yolov6n_infer(rvc2_yolov6n_onnx_env): - yolov6n_infer(rvc2_yolov6n_onnx_env) +def test_yolov6n_infer(rvc2_yolov6n_onnx_env, tool_version): + yolov6n_infer(rvc2_yolov6n_onnx_env, tool_version) def test_resnet18_superblob_convert(rvc2_superblob_resnet18_onnx_env): diff --git a/tests/test_packages/test_rvc3.py b/tests/test_packages/test_rvc3.py index 1848fa8..35026f4 100644 --- a/tests/test_packages/test_rvc3.py +++ b/tests/test_packages/test_rvc3.py @@ -1,18 +1,16 @@ -import pytest - -from .common import check_convert, mnist_infer, resnet18_infer, yolov6n_infer +from .common import check_convert, mnist_infer, resnet18_infer def test_mnist_convert(rvc3_mnist_onnx_env): check_convert(rvc3_mnist_onnx_env) -def test_mnist_infer(rvc3_mnist_onnx_env): - mnist_infer(rvc3_mnist_onnx_env) +def test_mnist_infer(rvc3_mnist_onnx_env, tool_version): + mnist_infer(rvc3_mnist_onnx_env, tool_version) -def test_mnist_infer_quant(rvc3_quant_mnist_onnx_env): - mnist_infer(rvc3_quant_mnist_onnx_env) +def test_mnist_infer_quant(rvc3_quant_mnist_onnx_env, tool_version): + mnist_infer(rvc3_quant_mnist_onnx_env, tool_version) def test_resnet18_convert(rvc3_resnet18_onnx_env): @@ -31,29 +29,9 @@ def test_resnet18_archive_convert(rvc3_resnet18_archive_env): check_convert(rvc3_resnet18_archive_env) -def test_resnet18_infer(rvc3_resnet18_onnx_env): - resnet18_infer(rvc3_resnet18_onnx_env) - - -def test_resnet18_archive_infer(rvc3_resnet18_archive_env): - resnet18_infer(rvc3_resnet18_archive_env) - - -@pytest.mark.skip(reason="Cannot be converted for RVC3") -def test_yolov6_convert(rvc3_yolov6n_env): - check_convert(rvc3_yolov6n_env) - - -@pytest.mark.skip(reason="Cannot be converted for RVC3") -def test_yolov6n_infer(rvc3_yolov6n_onnx_env): - yolov6n_infer(rvc3_yolov6n_onnx_env) - - -@pytest.mark.xfail(reason="Too degraded accuracy") -def test_resnet18_infer_quant(rvc3_quant_resnet18_onnx_env): - resnet18_infer(rvc3_quant_resnet18_onnx_env) +def test_resnet18_infer(rvc3_resnet18_onnx_env, tool_version): + resnet18_infer(rvc3_resnet18_onnx_env, tool_version) -@pytest.mark.skip(reason="Cannot be converted for RVC3") -def test_yolov6n_infer_quant(rvc3_quant_yolov6n_onnx_env): - yolov6n_infer(rvc3_quant_yolov6n_onnx_env) +def test_resnet18_archive_infer(rvc3_resnet18_archive_env, tool_version): + resnet18_infer(rvc3_resnet18_archive_env, tool_version) diff --git a/tests/test_packages/test_rvc4.py b/tests/test_packages/test_rvc4.py index 1bd8274..54f1eb4 100644 --- a/tests/test_packages/test_rvc4.py +++ b/tests/test_packages/test_rvc4.py @@ -10,37 +10,39 @@ def test_mnist_convert(rvc4_mnist_onnx_env): check_convert(rvc4_mnist_onnx_env) -def test_mnist_infer(rvc4_mnist_onnx_env): - mnist_infer(rvc4_mnist_onnx_env) +def test_mnist_infer(rvc4_mnist_onnx_env, tool_version): + mnist_infer(rvc4_mnist_onnx_env, tool_version) def test_resnet18_convert(rvc4_resnet18_onnx_env): check_convert(rvc4_resnet18_onnx_env) -def test_resnet18_infer(rvc4_resnet18_onnx_env): - resnet18_infer(rvc4_resnet18_onnx_env) +def test_resnet18_infer(rvc4_resnet18_onnx_env, tool_version): + resnet18_infer(rvc4_resnet18_onnx_env, tool_version) def test_resnet18_non_quant_convert(rvc4_non_quant_resnet18_onnx_env): check_convert(rvc4_non_quant_resnet18_onnx_env) -def test_resnet18_non_quant_infer(rvc4_non_quant_resnet18_onnx_env): - resnet18_infer(rvc4_non_quant_resnet18_onnx_env) +def test_resnet18_non_quant_infer( + rvc4_non_quant_resnet18_onnx_env, tool_version +): + resnet18_infer(rvc4_non_quant_resnet18_onnx_env, tool_version) def test_resnet18_archive_convert(rvc4_resnet18_archive_env): check_convert(rvc4_resnet18_archive_env) -def test_resnet18_archive_infer(rvc4_resnet18_archive_env): - resnet18_infer(rvc4_resnet18_archive_env) +def test_resnet18_archive_infer(rvc4_resnet18_archive_env, tool_version): + resnet18_infer(rvc4_resnet18_archive_env, tool_version) def test_yolov6_convert(rvc4_yolov6n_onnx_env): check_convert(rvc4_yolov6n_onnx_env) -def test_yolov6n_infer(rvc4_yolov6n_onnx_env): - yolov6n_infer(rvc4_yolov6n_onnx_env) +def test_yolov6n_infer(rvc4_yolov6n_onnx_env, tool_version): + yolov6n_infer(rvc4_yolov6n_onnx_env, tool_version) From f0b12a4e8843511821f8a2f0ed7baa3b31678d60 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 11 Oct 2024 00:30:43 +0200 Subject: [PATCH 32/36] fixed unittests --- tests/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index c317781..4c675d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -95,7 +95,8 @@ def pytest_addoption(parser): parser.addoption( "--tool-version", action="store", - required=True, + required=False, + default="0.0.0", help="Version of the internal conversion tool", ) From ec40a4ff613fba908f6bf14ee8650058e0121f96 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 11 Oct 2024 10:09:58 +0200 Subject: [PATCH 33/36] fix tests --- .github/workflows/rvc3_test.yaml | 8 +------- .github/workflows/rvc4_test.yaml | 1 - docker/rvc2/Dockerfile | 2 ++ docker/rvc3/Dockerfile | 13 ++++--------- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rvc3_test.yaml b/.github/workflows/rvc3_test.yaml index ad70920..282f6cc 100644 --- a/.github/workflows/rvc3_test.yaml +++ b/.github/workflows/rvc3_test.yaml @@ -16,14 +16,8 @@ on: jobs: rvc3-test: - - strategy: - fail-fast: false - matrix: - version: ["2021.4.0", "2022.3.0"] - uses: ./.github/workflows/modelconverter_test.yaml secrets: inherit with: package: rvc3 - version: ${{ matrix.version }} + version: "2022.3.0" diff --git a/.github/workflows/rvc4_test.yaml b/.github/workflows/rvc4_test.yaml index 7607395..ae032e1 100644 --- a/.github/workflows/rvc4_test.yaml +++ b/.github/workflows/rvc4_test.yaml @@ -21,7 +21,6 @@ jobs: fail-fast: false matrix: version: - - "2.21.0" - "2.22.10" - "2.23.0" - "2.24.0" diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index 2e04545..2440a8e 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -81,6 +81,8 @@ RUN < Date: Fri, 11 Oct 2024 10:17:00 +0200 Subject: [PATCH 34/36] fix rvc2 docker --- docker/rvc2/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index 2440a8e..bb4fcec 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -76,12 +76,12 @@ RUN < Date: Fri, 11 Oct 2024 10:54:30 +0200 Subject: [PATCH 35/36] remove removing whl files --- docker/rvc2/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/rvc2/Dockerfile b/docker/rvc2/Dockerfile index bb4fcec..2a26b2e 100644 --- a/docker/rvc2/Dockerfile +++ b/docker/rvc2/Dockerfile @@ -76,7 +76,6 @@ RUN < Date: Fri, 11 Oct 2024 11:17:14 +0200 Subject: [PATCH 36/36] changed snpe versions --- .github/workflows/rvc4_publish.yaml | 3 +-- .github/workflows/rvc4_test.yaml | 2 +- modelconverter/__main__.py | 7 +++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rvc4_publish.yaml b/.github/workflows/rvc4_publish.yaml index 7bba205..604cd40 100644 --- a/.github/workflows/rvc4_publish.yaml +++ b/.github/workflows/rvc4_publish.yaml @@ -15,12 +15,11 @@ jobs: fail-fast: false matrix: version: - - "2.21.0" - - "2.22.10" - "2.23.0" - "2.24.0" - "2.25.0" - "2.26.2" + - "2.27.0" uses: ./.github/workflows/publish.yaml secrets: inherit diff --git a/.github/workflows/rvc4_test.yaml b/.github/workflows/rvc4_test.yaml index ae032e1..468b524 100644 --- a/.github/workflows/rvc4_test.yaml +++ b/.github/workflows/rvc4_test.yaml @@ -21,11 +21,11 @@ jobs: fail-fast: false matrix: version: - - "2.22.10" - "2.23.0" - "2.24.0" - "2.25.0" - "2.26.2" + - "2.27.0" uses: ./.github/workflows/modelconverter_test.yaml secrets: inherit diff --git a/modelconverter/__main__.py b/modelconverter/__main__.py index fac2772..869bc80 100644 --- a/modelconverter/__main__.py +++ b/modelconverter/__main__.py @@ -62,6 +62,8 @@ class Format(str, Enum): VersionOption: TypeAlias = Annotated[ Optional[str], typer.Option( + "-v", + "--version", help="""Version of the underlying conversion tools to use. Only takes effect when --dev is used. Available options differ based on the target platform: @@ -74,14 +76,15 @@ class Format(str, Enum): - `2022.3.0` (default) - `RVC4`: - - `2.22.10` - `2.23.0` (default) - `2.24.0` - `2.25.0` - `2.26.2` + - `2.27.0` - `HAILO`: - - `2024.04` (default)""", + - `2024.04` (default), + - `2024.07` (default)""", show_default=False, ), ]