diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index f4d733d2..00000000 --- a/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -ARG BASE -FROM ${BASE} - -WORKDIR /usr/src/app - -# install mmdetection -ENV FORCE_CUDA="1" -COPY ./external /usr/src/app/external - -# prerequisite for the mmdetection -RUN apt-get update && apt-get install -y git && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -RUN pip install --upgrade pip -RUN cd ./external/mmdetection/ && \ - pip install -r requirements/build.txt && \ - pip install -v -e . && \ - pip install -r requirements/runtime.txt && \ - cd - - -# install mmsegmentation -RUN cd ./external/mmsegmentation/ && \ - pip install -r requirements && \ - pip install -v -e . && \ - cd - - -# install MDA -RUN pip install -v -e ./external/mda - -# install HPO -RUN pip install -v -e ./external/hpo - -# install ote-sdk -RUN pip install -v -e ./external/training_extensions/ote_sdk - -COPY ./requirements.txt . -RUN pip install -r ./requirements.txt - -# copying unittest stuffs -COPY ./pytest.ini . -COPY ./.coveragerc . diff --git a/Dockerfile.ci.cpu.test b/Dockerfile.ci.cpu.test deleted file mode 100644 index 566ff317..00000000 --- a/Dockerfile.ci.cpu.test +++ /dev/null @@ -1,94 +0,0 @@ -FROM openvino/ubuntu18_dev:2021.4 - -ARG ver_pytorch -RUN echo "version of pytorch: ${ver_pytorch}" - -ARG uid -ARG gid - -# set work directory -WORKDIR /usr/src/app - -# set environment variables -# to prevent generation of __pycache__ folders -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -USER root - -# install dependencies -RUN apt-get update && \ - apt-get install -y build-essential curl libgtk-3-dev - -# install dependencies for OTE-SDK -RUN apt-get install -y libsasl2-dev python-dev libldap2-dev libssl-dev - -RUN curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - chmod +x ~/miniconda.sh && \ - ~/miniconda.sh -b -p /opt/conda && \ - rm ~/miniconda.sh -ENV PATH /opt/conda/bin:$PATH - -RUN conda install -y python=3.8 cython -RUN conda install -y pytorch=$ver_pytorch torchvision cpuonly -c pytorch-lts && conda clean -ya - -RUN pip install --no-cache-dir mmcv-full==1.3.0 -f https://download.openmmlab.com/mmcv/dist/cpu/torch${ver_pytorch}/index.html - -COPY ./requirements.txt . -COPY ./constraints.txt . -ENV FORCE_CUDA="1" -RUN pip install --upgrade pip -RUN pip install -r ./requirements.txt -c ./constraints.txt - -ARG PYPI_PROTOCOL=http -ARG PYPI_SERVER=pypi.sclab.intel.com -ARG PYPI_PORT=8000 -ARG PYTHON_PIP_NO_CACHE_DIR= - -COPY ./tests /usr/src/app/tests -RUN mkdir -p .cache\pip && \ - pip download -d .cache/pip \ - --trusted-host ${PYPI_SERVER} \ - --extra-index-url ${PYPI_PROTOCOL}://${PYPI_SERVER}:${PYPI_PORT} \ - -r ./tests/requirements.txt && \ - pip ${PYTHON_PIP_NO_CACHE_DIR} install -f .cache/pip \ - --upgrade-strategy only-if-needed \ - --ignore-installed PyYAML \ - -r ./tests/requirements.txt - -# install mmdetection -COPY ./external /usr/src/app/external -RUN cd ./external/mmdetection/ && \ - pip install -r requirements/build.txt && \ - pip install -v -e . && \ - pip install -r requirements/runtime.txt && \ - cd - - -# install mmsegmentation -RUN cd ./external/mmsegmentation/ && \ - pip install -r requirements.txt && \ - pip install -v -e . && \ - cd - - -# install MDA -RUN pip install -v -e ./external/mda - -# install HPO -RUN pip install -v -e ./external/hpo - -# install ote-sdk -RUN pip install -v -e ./external/training_extensions/ote_sdk - -ENV NO_PROXY=*.sclab.intel.com,*.devtools.intel.com,localhost,127.0.0.1 -ENV HTTP_PROXY=http://proxy-mu.intel.com:911 -ENV HTTPS_PROXY=http://proxy-mu.intel.com:912 -ENV FTP_PROXY=http://proxy-mu.intel.com:911 - -# RUN groupadd -r -g ${gid} mpa && useradd -r -m mpa -s /bin/bash -g ${gid} -u ${uid} && echo "${gid}:${uid}" -RUN chown -R 1000:1000 /usr/src/app - -USER 1000 - -RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> ~/.bash_profile -ENV BASH_ENV "~/.bash_profile" -ENV XDG_CACHE_HOME="/usr/src/app/data/.cache" \ No newline at end of file diff --git a/Dockerfile.ci.gpu.test b/Dockerfile.ci.gpu.test deleted file mode 100644 index 55b50505..00000000 --- a/Dockerfile.ci.gpu.test +++ /dev/null @@ -1,101 +0,0 @@ -ARG cuda_tag - -FROM nvidia/cuda:${cuda_tag} - -ARG cuda_tag -RUN echo "building image based on nvidia/cuda:${cuda_tag}" - -ARG ver_pytorch -RUN echo "version of pytorch: ${ver_pytorch}" -# ARG ver_torchvision -# RUN echo "version of torchvision: ${ver_torchvision}" - -ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX" - -ARG uid -ARG gid - -# set work directory -WORKDIR /usr/src/app - -# set environment variables -# to prevent generation of __pycache__ folders -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -# install dependencies -RUN apt-get update && \ - apt-get install -y build-essential curl libgtk-3-dev - -# install dependencies for OTE-SDK -RUN apt-get install -y libsasl2-dev python-dev libldap2-dev libssl-dev - -COPY --from=openvino/ubuntu18_dev:2021.4 /opt/intel/openvino /opt/intel/openvino - -RUN curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - chmod +x ~/miniconda.sh && \ - ~/miniconda.sh -b -p /opt/conda && \ - rm ~/miniconda.sh -ENV PATH /opt/conda/bin:$PATH - -RUN conda install -y python=3.8 cython -RUN conda install -y pytorch=$ver_pytorch torchvision cudatoolkit=$ver_cuda -c pytorch-lts -c nvidia && conda clean -ya - -COPY ./requirements.txt . -COPY ./constraints.txt . -ENV FORCE_CUDA="1" -RUN pip install --upgrade pip -RUN pip install -r ./requirements.txt - -ARG PYPI_PROTOCOL=http -ARG PYPI_SERVER=pypi.sclab.intel.com -ARG PYPI_PORT=8000 -ARG PYTHON_PIP_NO_CACHE_DIR= - -COPY ./tests /usr/src/app/tests -RUN mkdir -p .cache\pip && \ - pip download -d .cache/pip \ - --trusted-host ${PYPI_SERVER} \ - --extra-index-url ${PYPI_PROTOCOL}://${PYPI_SERVER}:${PYPI_PORT} \ - -r ./tests/requirements.txt && \ - pip ${PYTHON_PIP_NO_CACHE_DIR} install -f .cache/pip \ - --upgrade-strategy only-if-needed \ - --ignore-installed PyYAML \ - -r ./tests/requirements.txt - -# install mmdetection -COPY ./external /usr/src/app/external -RUN cd ./external/mmdetection/ && \ - pip install -r requirements/build.txt && \ - pip install -v -e . && \ - pip install -r requirements/runtime.txt && \ - cd - - -# install mmsegmentation -RUN cd ./external/mmsegmentation/ && \ - pip install -r requirements.txt && \ - pip install -v -e . && \ - cd - - -# install MDA -RUN pip install -v -e ./external/mda - -# install HPO -RUN pip install -v -e ./external/hpo - -# install ote-sdk -RUN pip install -v -e ./external/training_extensions/ote_sdk - -ENV NO_PROXY=*.sclab.intel.com,*.devtools.intel.com,localhost,127.0.0.1 -ENV HTTP_PROXY=http://proxy-mu.intel.com:911 -ENV HTTPS_PROXY=http://proxy-mu.intel.com:912 -ENV FTP_PROXY=http://proxy-mu.intel.com:911 - -RUN groupadd -r -g ${gid} mpa && useradd -r -m mpa -s /bin/bash -g ${gid} -u ${uid} && echo "${gid}:${uid}" -RUN chown -R mpa:mpa /usr/src/app - -USER mpa - -RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> /home/mpa/.bash_profile -ENV BASH_ENV "/home/mpa/.bash_profile" -ENV XDG_CACHE_HOME="/usr/src/app/data/.cache" \ No newline at end of file diff --git a/Dockerfile.cpu.test b/Dockerfile.cpu.test deleted file mode 100644 index 61b5e4a5..00000000 --- a/Dockerfile.cpu.test +++ /dev/null @@ -1,95 +0,0 @@ -FROM openvino/ubuntu18_dev:2021.4 - -ARG ver_pytorch -RUN echo "version of pytorch: ${ver_pytorch}" - -ARG ver_mmcv -RUN echo "versio of mmcv: ${ver_mmcv}" - -# set work directory -WORKDIR /usr/src/app - -# set environment variables -# to prevent generation of __pycache__ folders -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -# OpenVINO base image is configured as non-root privilege. so, need to change user to root -# for using 'apt-get' commands -USER root - -# install dependencies -RUN apt-get --allow-releaseinfo-change update && \ - apt-get install -y build-essential curl libgtk-3-dev git - -# COPY --from=openvino/ubuntu18_dev:2021.4 /opt/intel/openvino /opt/intel/openvino -RUN curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - chmod +x ~/miniconda.sh && \ - ~/miniconda.sh -b -p /opt/conda && \ - rm ~/miniconda.sh -ENV PATH /opt/conda/bin:$PATH - -RUN conda install -y python=3.8 cython -RUN conda install -y pytorch=$ver_pytorch torchvision cpuonly -c pytorch-lts && conda clean -ya - -COPY ./requirements.txt . -COPY ./constraints.txt . -COPY ./constraints_test.txt . -ENV FORCE_CUDA="0" -RUN pip install --upgrade pip - -# install mmcv -RUN pip install --no-cache-dir mmcv-full==${ver_mmcv} -f https://download.openmmlab.com/mmcv/dist/cpu/torch$}ver_pytorch}/index.html -c ./constraints.txt -RUN pip install -r ./requirements.txt -c ./constraints.txt - -ARG PYPI_PROTOCOL=http -ARG PYPI_SERVER=pypi.sclab.intel.com -ARG PYPI_PORT=8000 -ARG PYTHON_PIP_NO_CACHE_DIR= - -COPY ./tests /usr/src/app/tests -COPY ./pytest.ini . -COPY ./.coveragerc . -RUN mkdir -p .cache\pip && \ - pip download -d .cache/pip \ - --trusted-host ${PYPI_SERVER} \ - --extra-index-url ${PYPI_PROTOCOL}://${PYPI_SERVER}:${PYPI_PORT} \ - -r ./tests/requirements.txt -c ./constraints_test.txt && \ - pip ${PYTHON_PIP_NO_CACHE_DIR} install -f .cache/pip \ - --upgrade-strategy only-if-needed \ - --ignore-installed PyYAML \ - -r ./tests/requirements.txt -c ./constraints_test.txt - -# install mmdetection -COPY ./external /usr/src/app/external -RUN cd ./external/mmdetection/ && \ - pip install -r requirements/build.txt && \ - pip install -v -e . && \ - pip install -r requirements/runtime.txt && \ - cd - - -# install mmsegmentation -RUN cd ./external/mmsegmentation/ && \ - pip install -r requirements.txt && \ - pip install -v -e . && \ - cd - - -# install MDA -RUN pip install -v -e ./external/mda - -# install HPO -RUN pip install -v -e ./external/hpo - -# install ote-sdk -RUN pip install -v -e ./external/training_extensions/ote_sdk - -# install albumentations for temporal purpose -RUN pip install albumentations - -ENV NO_PROXY=*.sclab.intel.com,*.devtools.intel.com,localhost,127.0.0.1 -ENV HTTP_PROXY=http://proxy-mu.intel.com:911 -ENV HTTPS_PROXY=http://proxy-mu.intel.com:912 -ENV FTP_PROXY=http://proxy-mu.intel.com:911 - -RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> /home/$USER/.bash_profile -ENV BASH_ENV "/home/$USER/.bash_profile" diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 8f099ae5..00000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,24 +0,0 @@ -ARG VER_CUDA - -FROM registry.toolbox.iotg.sclab.intel.com/mpa/cu${VER_CUDA}/cli:latest - -ARG uid -ARG gid - -RUN groupadd -r -g ${gid} mpa && useradd -r -m mpa -s /bin/bash -g ${gid} -u ${uid} && echo "${gid}:${uid}" - -# to install additional dependencies for the newly added tasks. -# once mpa docker images are updated, following pip installation command should be removed. -# RUN pip install scikit-image -# RUN pip install instaboostfast --no-deps -# RUN pip install albumentations - -# set work directory -WORKDIR /usr/src/app -RUN chown -R mpa:mpa /usr/src/app - -USER mpa - -RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> /home/mpa/.bash_profile -ENV BASH_ENV="/home/mpa/.bash_profile" -ENV XDG_CACHE_HOME="/usr/src/app/data/.cache" \ No newline at end of file diff --git a/Dockerfile.gpu.dev b/Dockerfile.gpu.dev deleted file mode 100644 index d1caaa46..00000000 --- a/Dockerfile.gpu.dev +++ /dev/null @@ -1,79 +0,0 @@ -ARG ver_torchvision -ARG ver_pytorch -ARG cuda_tag - -FROM nvidia/cuda:${cuda_tag} - -ARG cuda_tag -RUN echo "building image based on nvidia/cuda:${cuda_tag}" - -ARG ver_pytorch -RUN echo "version of pytorch: ${ver_pytorch}" -ARG ver_torchvision -RUN echo "version of torchvision: ${ver_torchvision}" - -ARG uid -ARG gid - -RUN groupadd -r -g ${gid} mpa && useradd -r -m mpa -s /bin/bash -g ${gid} -u ${uid} && echo "${gid}:${uid}" - -ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX" - -# set work directory -WORKDIR /usr/src/app - -# set environment variables -# to prevent generation of __pycache__ folders -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -# install dependencies -RUN apt-get update && \ - apt-get install -y build-essential curl libgtk-3-dev - -COPY --from=openvino/ubuntu18_dev:2020.3 /opt/intel/openvino /opt/intel/openvino - -RUN curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - chmod +x ~/miniconda.sh && \ - ~/miniconda.sh -b -p /opt/conda && \ - rm ~/miniconda.sh -ENV PATH /opt/conda/bin:$PATH - -RUN conda install -y python=3.7 cython -RUN conda install -y pytorch=$ver_pytorch torchvision=$ver_torchvision -c pytorch && conda clean -ya - -COPY ./requirements.txt . -ENV FORCE_CUDA="1" -RUN pip install --upgrade pip -RUN pip install -r ./requirements.txt - -# install mmdetection -COPY ./external /usr/src/app/external -RUN cd ./external/mmdetection/ && \ - pip install -r requirements/build.txt && \ - pip install -v -e . && \ - pip install -r requirements/runtime.txt && \ - cd - - -# install mmsegmentation -RUN cd ./external/mmsegmentation/ && \ - pip install -r requirements.txt && \ - pip install -v -e . && \ - cd - - -# install MDA -RUN cd ./external/mda/ && \ - pip install -v -e . && \ - cd - - -# install HPO -RUN cd ./external/hpo/ && \ - pip install -v -e . && \ - cd - - -RUN chown -R mpa:mpa /usr/src/app - -USER mpa - -RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> /home/mpa/.bash_profile -ENV BASH_ENV "/home/mpa/.bash_profile" diff --git a/Dockerfile.gpu.test b/Dockerfile.gpu.test deleted file mode 100644 index a77fd9bf..00000000 --- a/Dockerfile.gpu.test +++ /dev/null @@ -1,99 +0,0 @@ -ARG cuda_tag - -FROM nvidia/cuda:${cuda_tag} - -ARG cuda_tag -RUN echo "building image based on nvidia/cuda:${cuda_tag}" - -ARG ver_pytorch -RUN echo "version of pytorch: ${ver_pytorch}" -# ARG ver_torchvision -# RUN echo "version of torchvision: ${ver_torchvision}" -ARG ver_mmcv -RUN echo "version of mmcv: ${ver_mmcv}" - -ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX" - -# set work directory -WORKDIR /usr/src/app - -# set environment variables -# to prevent generation of __pycache__ folders -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -# install dependencies -RUN apt-get update && \ - apt-get install -y build-essential curl libgtk-3-dev git - -COPY --from=openvino/ubuntu18_dev:2021.4 /opt/intel/openvino /opt/intel/openvino - -RUN curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - chmod +x ~/miniconda.sh && \ - ~/miniconda.sh -b -p /opt/conda && \ - rm ~/miniconda.sh -ENV PATH /opt/conda/bin:$PATH - -RUN conda install -y python=3.8 cython -RUN conda install -y pytorch=$ver_pytorch torchvision cudatoolkit=$ver_cuda -c pytorch-lts -c nvidia && conda clean -ya - -COPY ./requirements.txt . -COPY ./constraints.txt . -COPY ./constraints_test.txt . -ENV FORCE_CUDA="1" -RUN pip install --upgrade pip -RUN pip install --no-cache-dir mmcv-full==${ver_mmcv} -f https://download.openmmlab.com/mmcv/dist/cu${ver_cuda}/torch${ver_pytorch}/index.html -c ./constraints.txt -RUN pip install -r ./requirements.txt -c ./constraints.txt - -ARG PYPI_PROTOCOL=http -ARG PYPI_SERVER=pypi.sclab.intel.com -ARG PYPI_PORT=8000 -ARG PYTHON_PIP_NO_CACHE_DIR= - -COPY ./tests /usr/src/app/tests -COPY ./pytest.ini . -COPY ./.coveragerc . -RUN mkdir -p .cache\pip && \ - pip download -d .cache/pip \ - --trusted-host ${PYPI_SERVER} \ - --extra-index-url ${PYPI_PROTOCOL}://${PYPI_SERVER}:${PYPI_PORT} \ - -r ./tests/requirements.txt -c ./constraints_test.txt && \ - pip ${PYTHON_PIP_NO_CACHE_DIR} install -f .cache/pip \ - --upgrade-strategy only-if-needed \ - --ignore-installed PyYAML \ - -r ./tests/requirements.txt -c ./constraints_test.txt && \ - cd - - -# install mmdetection -COPY ./external /usr/src/app/external -RUN cd ./external/mmdetection/ && \ - pip install -r requirements/build.txt && \ - pip install -v -e . && \ - pip install -r requirements/runtime.txt && \ - cd - - -# install mmsegmentation -RUN cd ./external/mmsegmentation/ && \ - pip install -r requirements.txt && \ - pip install -v -e . && \ - cd - - -# install MDA -RUN pip install -v -e ./external/mda - -# install HPO -RUN pip install -v -e ./external/hpo - -# install ote-sdk -RUN pip install -v -e ./external/training_extensions/ote_sdk - -# install albumentations for temporal purpose -RUN pip install albumentations - -ENV NO_PROXY=*.sclab.intel.com,*.devtools.intel.com,localhost,127.0.0.1 -ENV HTTP_PROXY=http://proxy-mu.intel.com:911 -ENV HTTPS_PROXY=http://proxy-mu.intel.com:912 -ENV FTP_PROXY=http://proxy-mu.intel.com:911 - -RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> /home/$USER/.bash_profile -ENV BASH_ENV "/home/$USER/.bash_profile" diff --git a/constraints.txt b/constraints.txt index b5a1d72f..ce9b3045 100644 --- a/constraints.txt +++ b/constraints.txt @@ -2,9 +2,9 @@ mmcv-full>=1.3.1 mmcls>=0.9.0 # numpy>=1.21.1 numpy==1.19.5 -pillow==8.2.0 -networkx>=2.5 -scikit-image>=0.17.2 +pillow>=9.0.1 +networkx>=2.7 +scikit-image>=0.17.2 instaboostfast>=0.1.2 # torch>=1.7.1,<=1.9.0 # torchvision>=0.8.1,<=0.10.0 diff --git a/docker-compose.ci.cpu.test.yaml b/docker-compose.ci.cpu.test.yaml deleted file mode 100644 index 696c599a..00000000 --- a/docker-compose.ci.cpu.test.yaml +++ /dev/null @@ -1,26 +0,0 @@ -version: '3.5' - -services: - cli: - shm_size: '5g' - build: - context: . - dockerfile: Dockerfile.ci.cpu.test - args: - uid: ${UID} - gid: ${GID} - ver_pytorch: ${VER_PYTORCH} - volumes: - - ./data:/usr/src/app/data - - ./models:/usr/src/app/models - - ./recipes:/usr/src/app/recipes - - ./recipes_old:/usr/src/app/recipes_old - - ./samples:/usr/src/app/samples - - ./tests:/usr/src/app/tests - - ./mpa:/usr/src/app/mpa - - ./tools:/usr/src/app/tools - - ./logs:/usr/src/app/logs - - ./.reports:/usr/src/app/.reports - command: - - /bin/sleep - - infinity diff --git a/docker-compose.ci.gpu.test.yaml b/docker-compose.ci.gpu.test.yaml deleted file mode 100644 index cbe7c68d..00000000 --- a/docker-compose.ci.gpu.test.yaml +++ /dev/null @@ -1,33 +0,0 @@ -version: "3.5" - -services: - cli: - shm_size: '5g' - build: - context: . - dockerfile: Dockerfile.ci.gpu.test - args: - uid: ${UID} - gid: ${GID} - cuda_tag: ${CUDA_TAG} - ver_pytorch: ${VER_PYTORCH} - runtime: nvidia - environment: - CUDA_VISIBLE_DEVICES: ${CUDA_VISIBLE_DEVICES} - CUDA_HOME: /usr/local/cuda - NVIDIA_VISIBLE_DEVICES: ${CUDA_VISIBLE_DEVICES} - NVIDIA_DRIVER_CAPABILITIES: compute,utility - volumes: - - ./data:/usr/src/app/data - - ./models:/usr/src/app/models - - ./recipes:/usr/src/app/recipes - - ./recipes_old:/usr/src/app/recipes_old - - ./samples:/usr/src/app/samples - - ./tests:/usr/src/app/tests - - ./mpa:/usr/src/app/mpa - - ./tools:/usr/src/app/tools - - ./logs:/usr/src/app/logs - - ./.reports:/usr/src/app/.reports - command: - - /bin/sleep - - infinity diff --git a/docker-compose.cpu.test.yaml b/docker-compose.cpu.test.yaml deleted file mode 100644 index 85e20f12..00000000 --- a/docker-compose.cpu.test.yaml +++ /dev/null @@ -1,30 +0,0 @@ -version: '2.2' - -services: - ci-worker: - privileged: true - shm_size: '5g' - cpuset: 0-23 - networks: - - mpa_cpu - container_name: mpa_cpu_image_${BUILD_NAME_SEED} - image: registry.toolbox.iotg.sclab.intel.com/${MPA_IMAGE_NAME}:${MPA_IMAGE_TAG} - volumes: - - /validation/components-data/mpa/data:/usr/src/app/data - - ./models:/usr/src/app/models - - ./recipes:/usr/src/app/recipes - - ./recipes_old:/usr/src/app/recipes_old - - ./samples:/usr/src/app/samples - - ./tests:/usr/src/app/tests - - ./mpa:/usr/src/app/mpa - - ./tools:/usr/src/app/tools - - ./.reports:/usr/src/app/.reports - - ${BUILD_LOGS}:/usr/src/app/logs - command: - - /bin/sleep - - infinity - -networks: - mpa_cpu: - driver: bridge - name: mpa_cpu_${BUILD_NAME_SEED} diff --git a/docker-compose.gpu.test.yaml b/docker-compose.gpu.test.yaml deleted file mode 100644 index 811c5e2a..00000000 --- a/docker-compose.gpu.test.yaml +++ /dev/null @@ -1,36 +0,0 @@ -version: '3.5' - -services: - ci-worker: - privileged: true - shm_size: '5g' - networks: - - mpa_gpu - container_name: mpa_gpu_image_${BUILD_NAME_SEED} - image: registry.toolbox.iotg.sclab.intel.com/${MPA_IMAGE_NAME}:${MPA_IMAGE_TAG} - environment: - CUDA_HOME: /usr/local/cuda - NVIDIA_DRIVER_CAPABILITIES: compute,utility - volumes: - - /validation/components-data/mpa/data:/usr/src/app/data - - ./models:/usr/src/app/models - - ./recipes:/usr/src/app/recipes - - ./recipes_old:/usr/src/app/recipes_old - - ./samples:/usr/src/app/samples - - ./tests:/usr/src/app/tests - - ./mpa:/usr/src/app/mpa - - ./tools:/usr/src/app/tools - - ./.reports:/usr/src/app/.reports - - ${BUILD_LOGS}:/usr/src/app/logs - command: - - /bin/sleep - - infinity - -volumes: - logs: - driver: local - -networks: - mpa_gpu: - driver: bridge - name: mpa_gpu_${BUILD_NAME_SEED} diff --git a/docker/Dockerfile.torch-base b/docker/Dockerfile.torch-base deleted file mode 100644 index 06f65628..00000000 --- a/docker/Dockerfile.torch-base +++ /dev/null @@ -1,52 +0,0 @@ -ARG ver_cuda="11.1" -ARG ver_cudnn="8" -ARG ver_python="3.8" -ARG ver_pytorch="1.8.2" # LTS version of pytorch -ARG cuda_tag="${ver_cuda}-cudnn${ver_cudnn}-devel-ubuntu18.04" - -FROM nvidia/cuda:${cuda_tag} - -ARG cuda_tag -RUN echo "building image based on nvidia/cuda:${cuda_tag}" - -ARG ver_pytorch -RUN echo "version of pytorch: ${ver_pytorch}" - -ARG ver_python -RUN echo "version of python: ${ver_python}" - -ARG ver_cuda -RUN echo "version of cuda: ${ver_cuda}" - -ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX" - -# set work directory -WORKDIR /usr/src/app - -# set environment variables -# to prevent generation of __pycache__ folders -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -# install dependencies -RUN apt-get update && \ - apt-get install -y build-essential curl libgtk-3-dev && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# # install dependencies for OTE-SDK -# RUN apt-get install -y libsasl2-dev python-dev libldap2-dev libssl-dev - -COPY --from=openvino/ubuntu18_dev:2021.4 /opt/intel/openvino /opt/intel/openvino - -RUN curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - chmod +x ~/miniconda.sh && \ - ~/miniconda.sh -b -p /opt/conda && \ - rm ~/miniconda.sh -ENV PATH /opt/conda/bin:$PATH - -RUN conda install -y python=${ver_python} cython -RUN conda install -y pytorch=$ver_pytorch torchvision cudatoolkit=$ver_cuda -c pytorch-lts -c nvidia && conda clean -ya - -RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> ~/.bash_profile -ENV BASH_ENV "~/.bash_profile" diff --git a/docker/Dockerfile.torch-base.test b/docker/Dockerfile.torch-base.test deleted file mode 100644 index db5ffb0c..00000000 --- a/docker/Dockerfile.torch-base.test +++ /dev/null @@ -1,13 +0,0 @@ -ARG BASE -FROM ${BASE} - -# install unittest dependencies -RUN mkdir /tmp/whl -WORKDIR /tmp/whl -COPY wheels/* /tmp/whl/ - -# RUN pip install --trusted-host pypi.sclab.intel.com --extra-index-url http://pypi.sclab.intel.com:8000 e2e-test-framework~=1.172.0 -RUN pip install e2e_test_framework-1.172.20210519111305-py3-none-any.whl -RUN rm -rf /tmp/whl - -RUN pip install pytest pytest-cov bandit flake8 mypy pylint coverage testfixtures diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index 94ce91e2..00000000 --- a/docker/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# How to build base docker image for MPA -You can build docker image by following instructions. Target version of some modules / components below should be changed for your environment. -## Create pytorch base image and tag it as base image -```bash -$ docker build -f docker/Dockerfile.torch-base --build-arg ver_cuda="10.2" --build-arg ver_cudnn="7" --build-arg ver_pytorch="1.7.1" --tag torch-base:1.7.1-cu10.2 docker -``` -## Create test image with iotg e2e framework -```bash -$ docker build -f docker/Dockerfile.torch-base.test --build-arg BASE=torch-base:1.7.1-cu10.2 --tag torch-base-test:1.7.1-cu10.2 docker -``` - -## Create MPA docker image -* build image using [Dockerfile](mpa/Dockerfile) -```bash -$ docker build -f Dockerfile --build-arg BASE=torch-base-test:1.7.1-cu10.2 --tag mpa/cu10.2/cli:1.0.0 . -``` - -## Tag and push docker image -```bash -$ docker tag mpa/cu10.2/cli:1.0.0 registry.toolbox.iotg.sclab.intel.com/mpa/cu10.2/cli:1.0.0 -$ docker tag registry.toolbox.iotg.sclab.intel.com/mpa/cu10.2/cli:1.0.0 \ -registry.toolbox.iotg.sclab.intel.com/mpa/cu10.2/cli:latest -$ docker push registry.toolbox.iotg.sclab.intel.com/mpa/cu10.2/cli:1.0.0 -$ docker push registry.toolbox.iotg.sclab.intel.com/mpa/cu10.2/cli:latest -``` \ No newline at end of file diff --git a/docker/wheels/e2e_test_framework-1.172.20210519111305-py3-none-any.whl b/docker/wheels/e2e_test_framework-1.172.20210519111305-py3-none-any.whl deleted file mode 100644 index 7fc1d7da..00000000 Binary files a/docker/wheels/e2e_test_framework-1.172.20210519111305-py3-none-any.whl and /dev/null differ diff --git a/requirements.txt b/requirements.txt index 0a607eb6..6440a78e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,11 +3,11 @@ mmcv-full mmcls==0.9.0 scipy==1.5.4 pandas==1.1.5 -pillow==8.2.0 -networkx==2.5.1 +pillow==9.0.1 +networkx==2.7.1 defusedxml==0.7.1 tensorboard==2.4.1 scikit-image>=0.17.2 torch>=1.7.1,<=1.9.0 torchvision>=0.8.1,<=0.10.0 -pytest-cov==2.11.* \ No newline at end of file +pytest-cov==2.11.* diff --git a/run-cli.sh b/run-cli.sh deleted file mode 100755 index e7af315e..00000000 --- a/run-cli.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash -if [ -z "$CUDA_VISIBLE_DEVICES" ]; then - VER_CUDA="10.2" - RUNTIME_ARG="" - ENV_ARG="" -else - if [ -z "$VER_CUDA" ]; then - VER_CUDA="$(nvidia-smi | awk -F"CUDA Version:" 'NR==3{split($2,a," ");print a[1]}')" - fi - RUNTIME_ARG="--runtime=nvidia" - ENV_ARG="--env CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES}" -fi - -# pull latest image from registry if there is updates -if [ -z "$SKIP_PULL" ]; then - docker pull registry.toolbox.iotg.sclab.intel.com/mpa/cu${VER_CUDA}/cli:latest -fi - -echo "*" > .dockerignore -export GID=$(id -g) -docker build -f Dockerfile.dev \ ---build-arg gid=$GID \ ---build-arg uid=$UID \ ---build-arg VER_CUDA=${VER_CUDA} \ ---tag mpa-cli-dev:latest .; RET=$? -rm .dockerignore - -if [ $RET -ne 0 ]; then - echo "failed to build mpa-cli-dev image" - unset GID - exit -1 -fi - -# create folders to be mounted to mpa/cli container if not exists -mkdir -p logs -mkdir -p data -mkdir -p .reports - -if [ -z "$TT_UNIT_TESTS" ]; then - TT_UNIT_TESTS="False" -fi -if [ -z "$TT_COMPONENT_TESTS" ]; then - TT_COMPONENT_TESTS="False" -fi - -if [ $TT_UNIT_TESTS == "False" ] && [ $TT_COMPONENT_TESTS == "False" ]; then - TT_UNIT_TESTS="True" -fi - -MPA_ARGS="$@" -echo "run with args: ${MPA_ARGS}" -docker run -t --rm ${RUNTIME_ARG} ${ENV_ARG} \ ---env TT_COMPONENT_TESTS=${TT_COMPONENT_TESTS} \ ---env TT_UNIT_TESTS=${TT_UNIT_TESTS} \ ---shm-size 5g \ --v $(pwd)/data:/usr/src/app/data \ --v $(pwd)/models:/usr/src/app/models \ --v $(pwd)/recipes:/usr/src/app/recipes \ --v $(pwd)/recipes_old:/usr/src/app/recipes_old \ --v $(pwd)/samples:/usr/src/app/samples \ --v $(pwd)/mpa:/usr/src/app/mpa \ --v $(pwd)/tools:/usr/src/app/tools \ --v $(pwd)/tests:/usr/src/app/tests \ --v $(pwd)/logs:/usr/src/app/logs \ --v $(pwd)/.reports:/usr/src/app/.reports \ --u mpa \ -mpa-cli-dev:latest /bin/bash -c "python -m $MPA_ARGS" diff --git a/run-test.sh b/run-test.sh deleted file mode 100755 index 112a3262..00000000 --- a/run-test.sh +++ /dev/null @@ -1,170 +0,0 @@ -#!/bin/bash -################################################################# -# this script is deprecated one for running unittests -# do not use it for your testing. it could be used only -# to check availability of docker-compose based (as a service) -# mpa execution only. -################################################################# - -export UID=$(id -u) -export GID=$(id -g) - -# -# create share folders - will be mounted to the MPA container. -# -mkdir -p logs -mkdir -p data - -# -# Variables -# -ARTIFACT_DIR="./.reports" -OUTPUT_FILE="unit-tests.xml" -COV_REPORT="none" -BUILD_NAME_SEED="0" -if [ $(pwd | cut -d "/" -f2) == "ci" ]; then - RUNNER_PREFIX=$(pwd | cut -d "/" -f7) -fi - -if [ -z "$TEST_TYPE" ]; then - TEST_TYPE="auto" -fi - -# -# Get arguments via commandline -# - -while [[ $# -gt 0 ]]; -do - key="$1" - - case "$key" in - # -ad|--artifact-dir) - # ARTIFACT_DIR=$(realpath "$2") - # shift - # shift - # ;; - -o|--output_file) - OUTPUT_FILE=$2 - shift - shift - ;; - -cr|--cov-report) - COV_REPORT=$2 - shift - shift - ;; - *) - esac -done - -# -# Run tests with docker-compose based on $MODE -# - -# if [ -d $REPORT_DIR ] ; then -rm -rf $ARTIFACT_DIR/* -# fi -mkdir -p "$ARTIFACT_DIR" - -if [ -z "$CUDA_VISIBLE_DEVICES" ]; then - PROJECT_NAME="mpa_cpu${BUILD_NAME_SEED}_${TEST_TYPE}" - echo "Running tests on CPUs" - YAML_FILES="-p ${PROJECT_NAME} -f docker-compose.ci.cpu.test.yaml" - WAIT_SECS=5 -else - PROJECT_NAME="mpa_gpu${BUILD_NAME_SEED}_${TEST_TYPE}" - echo "Running tests on GPUs" - YAML_FILES="-p ${PROJECT_NAME} -f docker-compose.ci.gpu.test.yaml" - WAIT_SECS=5 - if [ -z "$VER_CUDA" ]; then - VER_CUDA="$(nvidia-smi | awk -F"CUDA Version:" 'NR==3{split($2,a," ");print a[1]}')" - # export VER_CUDA="11.1" - echo "recommended CUDA version = $VER_CUDA" - fi -fi - -CONTAINER_NAME="cli" - -if [ -z "$VER_CUDA" ]; then - echo "no CUDA version is specified." - export VER_PYTORCH=1.8.2 - # export VER_TORCHVISION=0.7 -else - if (( $(echo "$VER_CUDA >= 11.0" |bc -l) )); then - VER_CUDNN=8 - export VER_PYTORCH=1.8.2 - # export VER_TORCHVISION=0.8 - else - VER_CUDNN=7 - export VER_PYTORCH=1.8.2 - # export VER_TORCHVISION=0.7 - fi - - export CUDA_TAG=$(wget -q https://registry.hub.docker.com/v1/repositories/nvidia/cuda/tags -O - | \ - sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}' | grep cudnn${VER_CUDNN}-devel-ubuntu18.04 | \ - grep ${VER_CUDA} | awk -F "" 'END{print}') -fi - -if [ -z "$TT_UNIT_TESTS" ]; then - TT_UNIT_TESTS="False" -fi -if [ -z "$TT_COMPONENT_TESTS" ]; then - TT_COMPONENT_TESTS="False" -fi - -if [ $TT_UNIT_TESTS == "False" ] && [ $TT_COMPONENT_TESTS == "False" ]; then - TT_UNIT_TESTS="True" -fi - -cp -f .dockerignore.bak .dockerignore -docker-compose ${YAML_FILES} up --build -d; RET=$? -rm .dockerignore - -if [ $RET -ne 0 ]; then - echo "failed to build and start application" - unset GID - unset VER_PYTORCH - # unset VER_TORCHVISION - unset CUDA_TAG - exit -1 -fi - -echo "Waiting for the application totally up..." -sleep $WAIT_SECS - -REPORT_OPTS="-s -v --junitxml=$ARTIFACT_DIR/$OUTPUT_FILE" -if [ $COV_REPORT != "none" ]; then - REPORT_OPTS="$REPORT_OPTS --cov-report ${COV_REPORT}:${ARTIFACT_DIR}/htmlcov" -fi - -if [ $TEST_TYPE == "nightly" ]; then - REPORT_OPTS="$REPORT_OPTS tests/intg" -else - REPORT_OPTS="$REPORT_OPTS --cov mpa tests/unit" -fi - -docker-compose ${YAML_FILES} exec -T \ - --env TT_COMPONENT_TESTS=${TT_COMPONENT_TESTS} \ - --env TT_UNIT_TESTS=${TT_UNIT_TESTS} \ - $CONTAINER_NAME /bin/bash -c "python -m pytest ${REPORT_OPTS}"; RET=$? - -if [ $RET -ne 0 ]; then - echo "unittest exits with non-zero." - echo "------ LOGS FOR ${CONTAINER_NAME} ------" - docker logs ${PROJECT_NAME}_${CONTAINER_NAME}_1 -fi -# copy pytest result to artifact dir -# docker cp ${PROJECT_NAME}_${CONTAINER_NAME}_1:$REPORT_DIR/$OUTPUT_FILE $ARTIFACT_DIR; echo "[Ret code for copying pytest results: ${?}]" - -docker-compose ${YAML_FILES} down; echo "[Ret code for service stopping: ${?}]" - -if [ $RET -ne 0 ]; then - echo "test:FAILED exits with non-zero." - unset GID - unset VER_PYTORCH - # unset VER_TORCHVISION - unset CUDA_TAG - exit -1 -fi - diff --git a/run_tests2.sh b/run_tests2.sh deleted file mode 100755 index 94e2ee20..00000000 --- a/run_tests2.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash -# -# INTEL CONFIDENTIAL -# Copyright (c) 2020 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# - - -################################################################################# -# run tests -################################################################################# -OS=`uname` - -echo "BUILD_NAME_SEED=${BUILD_NAME_SEED}" -echo "MPA_IMAGE_NAME=${MPA_IMAGE_NAME}" -echo "MPA_IMAGE_TAG=${MPA_IMAGE_TAG}" - -PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $PROJECT_DIR - -if [[ $TT_XDIST_WORKERS ]]; then - XDIST_PARAMETERS="-n ${TT_XDIST_WORKERS}" -else - XDIST_PARAMETERS="" -fi - -if [ -n "$JUNITFILE" ]; then - # if this is set to true, use default location - if [ "$JUNITFILE" = "true" ]; then - JUNITXML="--junitxml=../test_log/tests.xml" - else - JUNITXML="--junitxml=${JUNITFILE}" - fi - echo "JUnit result file will be generated at '${JUNITXML}'!" -fi - -if [ $TT_TEST_TYPE == "CPU" ]; then - echo "Running tests on CPUs" - echo "PROJECT_NAME=mpa_project_cpu_name_${BUILD_NAME_SEED}" - PROJECT_NAME="mpa_project_cpu_name_${BUILD_NAME_SEED}" - echo "CONTAINER_NAME=mpa_cpu_image${BUILD_NAME_SEED}" - CONTAINER_NAME="mpa_cpu_image_${BUILD_NAME_SEED}" - YAML_FILES="-p ${PROJECT_NAME} -f docker-compose.cpu.test.yaml --compatibility" - WAIT_SECS=10 -fi - -if [ $TT_TEST_TYPE == "GPU" ]; then - echo "Running tests on GPUs" - echo "PROJECT_NAME=mpa_project_gpu_name_${BUILD_NAME_SEED}" - PROJECT_NAME="mpa_project_gpu_name_${BUILD_NAME_SEED}" - echo "CONTAINER_NAME=mpa_gpu_image${BUILD_NAME_SEED}" - CONTAINER_NAME="mpa_gpu_image_${BUILD_NAME_SEED}" - YAML_FILES="-p ${PROJECT_NAME} -f docker-compose.gpu.test.yaml" - WAIT_SECS=60 -fi - -echo "Start docker-compose" -echo "COMMAND: docker-compose ${YAML_FILES} up -d --no-recreate" -docker-compose ${YAML_FILES} up -d --no-recreate; RET=$? -if [ $RET -ne 0 ]; then - echo "failed to build and start application" - unset GID - unset VER_PYTORCH - unset VER_TORCHVISION - unset CUDA_TAG - exit -1 -fi - -echo "Waiting for the application totally up..." -sleep $WAIT_SECS - -echo "Start executing tests" -COVERAGE_FOLDER="/usr/src/app/logs/coverage" -echo "COMMAND: docker exec --env-file <(env | grep -i TT_) ${CONTAINER_NAME} /bin/bash -c "mkdir -p ${COVERAGE_FOLDER} "" -docker exec --env-file <(env | grep -i TT_) ${CONTAINER_NAME} /bin/bash -c "mkdir -p ${COVERAGE_FOLDER}"; RET=$? - -echo "COMMAND: docker exec --env-file <(env | grep -i TT_) ${CONTAINER_NAME} /bin/bash -c "python -m pytest -s -v --cov-report html:${COVERAGE_FOLDER} --cov=mpa ${TT_TESTS_DIR} ${JUNITXML} ${XDIST_PARAMETERS}"" -docker exec --env-file <(env | grep -i TT_) ${CONTAINER_NAME} /bin/bash -c "python -m pytest -s -v --cov-report html:${COVERAGE_FOLDER} --cov=mpa ${TT_TESTS_DIR} ${JUNITXML} ${XDIST_PARAMETERS}"; RET=$? - -if [ $RET -ne 0 ]; then - echo "unittest exits with non-zero." - echo "------ LOGS FOR ${CONTAINER_NAME} ------" - docker logs $CONTAINER_NAME - exit -1 -fi - -echo "Stop executing tests" -echo "COMMAND: docker-compose ${YAML_FILES} down" -docker-compose ${YAML_FILES} down; echo "[Ret code for service stopping: ${?}]" -if [ $RET -ne 0 ]; then - echo "test:FAILED exits with non-zero." - unset GID - unset VER_PYTORCH - unset VER_TORCHVISION - unset CUDA_TAG - exit -1 -fi - -echo "Finished executing tests" -echo "Quiting run_tests.sh" -exit $ret_code diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index aa37d294..00000000 --- a/tests/conftest.py +++ /dev/null @@ -1,31 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# -import e2e.fixtures -import tests.fixtures - -from e2e.conftest_utils import * # noqa -from e2e.markers import MarksRegistry -from e2e import config # noqa -from e2e.utils import get_plugins_from_packages -from tests.constants.mpa_components import MPAComponent - -pytest_plugins = get_plugins_from_packages([e2e, tests]) -MarksRegistry.MARK_ENUMS.extend([MPAComponent]) diff --git a/tests/constants/__init__.py b/tests/constants/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/constants/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/constants/mpa_components.py b/tests/constants/mpa_components.py deleted file mode 100644 index 62f9ca3a..00000000 --- a/tests/constants/mpa_components.py +++ /dev/null @@ -1,25 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# -from e2e.markers.mark_meta import MarkMeta - - -class MPAComponent(MarkMeta): - MPA = "mpa" diff --git a/tests/constants/requirements.py b/tests/constants/requirements.py deleted file mode 100644 index cd3b3c38..00000000 --- a/tests/constants/requirements.py +++ /dev/null @@ -1,26 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# - - -class Requirements: - - # Dummy requirement - REQ_1 = "Dummy requirement" diff --git a/tests/constants/setup_values.py b/tests/constants/setup_values.py deleted file mode 100644 index 10ca2042..00000000 --- a/tests/constants/setup_values.py +++ /dev/null @@ -1,31 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# -import sys - - -class IntegrationTestsSetup: - assets_path = "tests/assets" - recipes_path = "recipes" - old_recipes_path = "recipes_old" - sample_path = "samples" - model_path = "models" - argv_tmp = sys.argv - output_path = "outputs/tests/cli" diff --git a/tests/fixtures/__init__.py b/tests/fixtures/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/fixtures/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/fixtures/ote_sdk.py b/tests/fixtures/ote_sdk.py deleted file mode 100644 index 4e4a8773..00000000 --- a/tests/fixtures/ote_sdk.py +++ /dev/null @@ -1,99 +0,0 @@ -import os - -import pytest -from mpa import MPAConstants -from ote_sdk.configuration.helper import create -from ote_sdk.entities.annotation import ( - Annotation, - AnnotationSceneEntity, - AnnotationSceneKind, - NullAnnotationSceneEntity, -) -from ote_sdk.entities.datasets import DatasetEntity, DatasetItemEntity, Subset -from ote_sdk.entities.image import Image -from ote_sdk.entities.label import Domain, LabelEntity -from ote_sdk.entities.label_schema import LabelSchemaEntity -from ote_sdk.entities.model_template import parse_model_template -from ote_sdk.entities.scored_label import ScoredLabel -from ote_sdk.entities.shapes.rectangle import Rectangle -from ote_sdk.entities.task_environment import TaskEnvironment -from ote_sdk.entities.train_parameters import TrainParameters - - -@pytest.fixture(scope='function') -def fixture_task_env(): - model_template_path = os.path.join( - MPAConstants.MODELS_PATH, 'templates/detection/MobilenetV2_ATSS_semi/template.yaml') - model_template = parse_model_template(model_template_path) - hyper_parameters = create(model_template.hyper_parameters.data) - - labels_schema = LabelSchemaEntity.from_labels([ - LabelEntity(name="0", domain=Domain.DETECTION), - LabelEntity(name="1", domain=Domain.DETECTION), - LabelEntity(name="2", domain=Domain.DETECTION), - ]) - - task_env = TaskEnvironment( - model=None, - hyper_parameters=hyper_parameters, - label_schema=labels_schema, - model_template=model_template - ) - return task_env - - -# @pytest.fixture(scope='function') -# def fixture_det_hparams(): -# hyper_parameters = Mock(spec=DetectionConfig) -# return hyper_parameters - - -def create_dataset_item_entity(target_path, subset): - items = [] - for dirpath, dirs, files in os.walk(target_path): - for filename in files: - fname = os.path.join(dirpath, filename) - label = str(dirpath.split('/')[-1]) - label = LabelEntity(id=-1, name=label, domain=Domain.DETECTION) - if fname.endswith('.png'): - item = DatasetItemEntity( - media=Image(file_path=fname), - annotation_scene=NullAnnotationSceneEntity() if subset == Subset.UNLABELED - else AnnotationSceneEntity( - annotations=[ - Annotation(Rectangle(x1=0, y1=0, x2=1, y2=1), labels=[ScoredLabel(label)]) - ], - kind=AnnotationSceneKind.ANNOTATION - ), - subset=subset - ) - items.append(item) - return items - - -@pytest.fixture(scope='function') -def fixture_dataset_entity(): - total_items = [] - - target_path = os.path.join(MPAConstants.TESTS_PATH, 'assets/dirs/classification/train') - total_items.extend(create_dataset_item_entity(target_path, Subset.TRAINING)) - - target_path = os.path.join(MPAConstants.TESTS_PATH, 'assets/dirs/classification/val') - total_items.extend(create_dataset_item_entity(target_path, Subset.VALIDATION)) - - target_path = os.path.join(MPAConstants.TESTS_PATH, 'assets/dirs/classification/unlabeled') - total_items.extend(create_dataset_item_entity(target_path, Subset.UNLABELED)) - - return DatasetEntity(items=total_items) - - -# @pytest.fixture(scope='function') -# def fixture_model_entity(): -# model_entity = Mock(spec=ModelEntity) -# return model_entity - - -@pytest.fixture(scope='function') -def fixture_train_parameters(): - train_parameters = TrainParameters() - return train_parameters diff --git a/tests/fixtures/setup.py b/tests/fixtures/setup.py deleted file mode 100644 index aa64da67..00000000 --- a/tests/fixtures/setup.py +++ /dev/null @@ -1,32 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# - -import sys - -import pytest -from tests.constants.setup_values import IntegrationTestsSetup - - -@pytest.fixture(scope="function") -def finalizer_for_intg(request): - def finalizer(): - sys.argv = IntegrationTestsSetup.argv_tmp - request.addfinalizer(finalizer) diff --git a/tests/intg/__init__.py b/tests/intg/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/intg/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/intg/test_classification.py b/tests/intg/test_classification.py deleted file mode 100644 index 11dff485..00000000 --- a/tests/intg/test_classification.py +++ /dev/null @@ -1,204 +0,0 @@ -import os.path as osp -import sys -import runpy -import pytest - -from tests.constants.setup_values import IntegrationTestsSetup - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestIntegrationClassification: - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "classifier", - [ - 'mnet_v2.yaml', - 'ote_mnet_v3_small.yaml', - 'ote_mnet_v3_large.yaml', - 'ote_mnet_v3_large_075.yaml', - 'ote_effnet_b0.yaml', - 'resnet18.yaml', - 'ote_mnet_v3_large.nonlinear_head.yaml' - ] - ) - def test_recipe_cls_ft_with_classifiers(finalizer_for_intg, classifier): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/classifiers', classifier) - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/cifar10split_224_bs16.py') - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'cls.yaml') - argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} --model_cfg {model_cfg} ' \ - '--recipe_hparams runner.max_epochs=2 ' \ - f'--output_path {IntegrationTestsSetup.output_path}' - sys.argv = argv.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_finetune/latest.pth') - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "dataset", - [ - 'cifar10split_224_bs16.py', - 'svhnsplit_bs16.py' - ] - ) - def test_recipe_cls_ft_with_datasets(finalizer_for_intg, dataset): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/classifiers/mnet_v2.yaml') - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/', dataset) - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'cls.yaml') - argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} --model_cfg {model_cfg} ' \ - '--recipe_hparams runner.max_epochs=2 ' \ - f'--output_path {IntegrationTestsSetup.output_path}' - sys.argv = argv.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_finetune/latest.pth') - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "params", - [ - {'model': 'mobilenet_v2.yaml', 'ckpt': 'cifar10_5cls_mnet_v2.pth'}, - {'model': 'ote_mobilenet_v3_large_075.yaml', 'ckpt': 'cifar10_5cls_ote-mnet_v3_large075.pth'} - ] - ) - def test_recipe_cls_class_incr_with_models(finalizer_for_intg, params): - model_cfg = osp.join(IntegrationTestsSetup.model_path, 'classification/', params['model']) - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/cifar10_224_cls_inc.py') - model_ckpt = osp.join(IntegrationTestsSetup.assets_path, 'model_cfg/ckpt/', params['ckpt']) - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'cls_class_incr.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} \ - --model_cfg {model_cfg} \ - --model_ckpt {model_ckpt} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_cls-inc/latest.pth') - - assert osp.exists(output_model) - - # Efficient Mode - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} \ - --model_cfg {model_cfg} \ - --model_ckpt {model_ckpt} \ - --recipe_hparams runner.max_epochs=2 task_adapt.efficient_mode=True \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_cls-inc/latest.pth') - - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "backbone", - [ - 'mobilenet_v2.yaml', - 'ote_mobilenet_v3_small.yaml', - 'ote_mobilenet_v3_large.yaml', - 'ote_mobilenet_v3_large_075.yaml', - 'ote_efficientnet_b0.yaml' - ] - ) - def test_recipe_cls_semisl_with_backbones(finalizer_for_intg, backbone): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/backbones', backbone) - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/stl10_224-bs8-40-280.py') - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'cls_semisl.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} --model_cfg {model_cfg} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_semisl-fixmatch/latest.pth') - - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "dataset", - [ - 'cifar10_224-bs8-40-280.py', - 'stl10_224-bs8-40-280.py', - 'fmnist_224-bs8-40-280.py', - 'svhn_224-bs8-40-280.py', - ] - ) - def test_recipe_cls_semisl_with_datasets(finalizer_for_intg, dataset): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/backbones/ote_mobilenet_v3_small.yaml') - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg', dataset) - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'cls_semisl.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} --model_cfg {model_cfg} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_semisl-fixmatch/latest.pth') - - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "backbone", - [ - 'mobilenet_v2.yaml', - 'ote_mobilenet_v3_small.yaml', - 'ote_mobilenet_v3_large.yaml', - 'ote_mobilenet_v3_large_075.yaml', - 'ote_efficientnet_b0.yaml' - ] - ) - @pytest.mark.skip(reason='deprecated') - def test_recipe_cls_selfsl_with_backbones(finalizer_for_intg, backbone): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/backbones', backbone) - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/stl10split_224.py') - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'cls_selfsl.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} --model_cfg {model_cfg} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage01_cls_from_byol/latest.pth') - - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "params", - [ - {'backbone': 'backbones/mobilenet_v2.yaml', 'ckpt': 'dss18_gen_bp_lh_mnetv2.pth'}, - ] - ) - def test_recipe_cls_taskinc_with_backbones(finalizer_for_intg, params): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/', params['backbone']) - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/dss18_cls_task_incr.py') - model_ckpt = osp.join(IntegrationTestsSetup.assets_path, 'model_cfg/ckpt/', params['ckpt']) - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'cls_task_incr.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} \ - --model_cfg {model_cfg} \ - --model_ckpt {model_ckpt} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage01_task-inc/latest.pth') - - assert osp.exists(output_model) diff --git a/tests/intg/test_detection.py b/tests/intg/test_detection.py deleted file mode 100644 index 8c795b28..00000000 --- a/tests/intg/test_detection.py +++ /dev/null @@ -1,95 +0,0 @@ -import os.path as osp -import sys -import runpy -import pytest - -from tests.constants.setup_values import IntegrationTestsSetup - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements -# from e2e.constants.framework_constants import FrameworkMessages - - -@pytest.mark.components(MPAComponent.MPA) -class TestIntegrationDetection: - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "detector", - [ - # 'frcnn_r50.custom.yaml', - 'ssd_mv2w1.custom.yaml', - 'atss_mv2w1.custom.yaml', - 'vfnet_r50.custom.yaml', - ] - ) - def test_recipe_det_custom(finalizer_for_intg, detector): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/detectors', detector) - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/coco_nopipe_smallest_resize.person.py') - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'det.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} \ - --model_cfg {model_cfg} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_train/latest.pth') - - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "detector", - [ - # 'frcnn_r50.custom.yaml', - 'ssd_mv2w1.custom.yaml', - 'atss_mv2w1.custom.yaml', - 'vfnet_r50.custom.yaml', - ] - ) - def __test_recipe_det_class_incr(finalizer_for_intg, detector): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/detectors', detector) - model_ckpt = osp.join(IntegrationTestsSetup.assets_path, 'model_cfg/ckpt/frcnn_rnet50_coco-10-person.zip') - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/coco_resize_smallest_car.repeat.py') - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'det_class_incr.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} \ - --model_cfg {model_cfg} \ - --model_ckpt {model_ckpt} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_train/latest.pth') - - assert osp.exists(output_model) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "detector", - [ - # 'frcnn_r50.custom.yaml', - 'ssd_mv2w1.custom.yaml', - 'atss_mv2w1.custom.yaml', - 'vfnet_r50.custom.yaml', - ] - ) - def test_recipe_det_semisl(finalizer_for_intg, detector): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/detectors', detector) - model_ckpt = osp.join(IntegrationTestsSetup.assets_path, 'model_cfg/ckpt/frcnn_rnet50_coco-10-person.zip') - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/coco_nopipe_smallest_resize.person.semi.py') - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'det_semisl.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} \ - --model_cfg {model_cfg} \ - --model_ckpt {model_ckpt} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_train/latest.pth') - - assert osp.exists(output_model) diff --git a/tests/intg/test_segmentation.py b/tests/intg/test_segmentation.py deleted file mode 100644 index 8c0328c1..00000000 --- a/tests/intg/test_segmentation.py +++ /dev/null @@ -1,37 +0,0 @@ -import os.path as osp -import sys -import runpy -import pytest - -from tests.constants.setup_values import IntegrationTestsSetup - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestIntegrationSegmentation: - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.component - @pytest.mark.parametrize( - "segmentor", - [ - 'litehrnet18.custom.yaml' - ] - ) - def test_recipe_seg_class_incr(finalizer_for_intg, segmentor): - model_cfg = osp.join(IntegrationTestsSetup.sample_path, 'cfgs/models/segmentors', segmentor) - model_ckpt = osp.join(IntegrationTestsSetup.assets_path, 'model_cfg/ckpt/seg_cityscapes_car_imgnet.pth') - data_cfg = osp.join(IntegrationTestsSetup.assets_path, 'data_cfg/cityscapes_seg_class_incr.py') - recipe = osp.join(IntegrationTestsSetup.recipes_path, 'seg_class_incr.yaml') - sys.argv = f'tools/cli.py {recipe} --data_cfg {data_cfg} \ - --model_cfg {model_cfg} \ - --model_ckpt {model_ckpt} \ - --recipe_hparams runner.max_epochs=2 \ - --output_path {IntegrationTestsSetup.output_path}'.split() - - runpy.run_module('tools.cli', run_name='__main__') - output_model = osp.join(IntegrationTestsSetup.output_path, 'latest/stage00_train/latest.pth') - - assert osp.exists(output_model) \ No newline at end of file diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index d9092b92..00000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,16 +0,0 @@ ---trusted-host pypi.sclab.intel.com ---extra-index-url http://pypi.sclab.intel.com:8000 -e2e-test-framework~=1.172.0 -pillow==8.2.0 -bandit -flake8 -mypy -pylint -pytest -pytest-cov -coverage -# ../../../.cache/pip/e2e-test-framework/e2e_test_framework-1.172.20210519111305-py3-none-any.whl # for NL -flaky>=3.6.1 -opencv-python==4.5.* -scikit-image==0.16.2 -testfixtures>=6.14.2 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/apis/__init__.py b/tests/unit/apis/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/apis/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/apis/configs/__init__.py b/tests/unit/apis/configs/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/apis/configs/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/apis/tasks/__init__.py b/tests/unit/apis/tasks/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/apis/tasks/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/apis/tasks/test_base.py b/tests/unit/apis/tasks/test_base.py deleted file mode 100644 index 3de6ba6b..00000000 --- a/tests/unit/apis/tasks/test_base.py +++ /dev/null @@ -1,12 +0,0 @@ -import pytest - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_base_task(): - pass diff --git a/tests/unit/apis/tasks/test_detection.py b/tests/unit/apis/tasks/test_detection.py deleted file mode 100644 index 5ebda243..00000000 --- a/tests/unit/apis/tasks/test_detection.py +++ /dev/null @@ -1,267 +0,0 @@ -import time -from unittest.mock import Mock, patch - -import pytest -from mpa.apis.configs.base import TrainType -from mpa.apis.tasks.detection import DetectionTrainTask -from mpa.modules.hooks.cancel_interface_hook import CancelInterfaceHook -from mpa.utils.logger import get_logger -from ote_sdk.entities.datasets import Subset -from ote_sdk.entities.inference_parameters import InferenceParameters -from ote_sdk.entities.model import ModelEntity -from ote_sdk.entities.resultset import ResultSetEntity -# from ote_sdk.entities.train_parameters import UpdateProgressCallback -from ote_sdk.usecases.tasks.interfaces.export_interface import ExportType -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -logger = get_logger() - - -def task_worker_with_assert_called_for_patch_obj( - task, - task_attr, # task attribute to be called - task_args_dict, - mock_obj=None, - patched_target=None, # patched target - patched_attr=None, # patched object - max_epoch=5 - ): - mock_init_recipe_hparam = Mock(return_value=dict(runner=dict(max_epochs=max_epoch))) - with patch.object(DetectionTrainTask, '_init_recipe_hparam', mock_init_recipe_hparam): - if mock_obj is not None: - with patch.object(patched_target, patched_attr, mock_obj): - getattr(task, task_attr)(**task_args_dict) - mock_obj.assert_called() - else: - getattr(task, task_attr)(**task_args_dict) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_detection_task_train_progress_callback( - fixture_task_env, - fixture_dataset_entity, - fixture_train_parameters, - ): - task = DetectionTrainTask(fixture_task_env) - - output_model = ModelEntity( - fixture_dataset_entity, - fixture_task_env.get_model_configuration(), - # model_status=ModelStatus.NOT_READY - ) - - task_args_dict = dict( - dataset=fixture_dataset_entity, - output_model=output_model, - ) - - # test with empty return of _run_task() - mock_obj = Mock(return_value=dict()) - task_worker_with_assert_called_for_patch_obj( - task, - 'train', - task_args_dict, - mock_obj, - DetectionTrainTask, - '_run_task' - ) - # assert output_model.model_status == ModelStatus.FAILED - - # test with progress_callback - pcallback = Mock() - fixture_train_parameters.update_progress = pcallback - - task_args_dict['train_parameters'] = fixture_train_parameters - - task_worker_with_assert_called_for_patch_obj( - task, - 'train', - task_args_dict, - max_epoch=1 - ) - pcallback.assert_called() - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_detection_task_cancel_train( - fixture_task_env, - fixture_dataset_entity, - fixture_train_parameters - ): - - import threading - - task = DetectionTrainTask(fixture_task_env) - - output_model = ModelEntity( - fixture_dataset_entity, - fixture_task_env.get_model_configuration(), - # model_status=ModelStatus.NOT_READY - ) - - mock_obj = Mock() - # check calling of cancel_training() - task_args_dict = dict( - dataset=fixture_dataset_entity, - output_model=output_model, - ) - # run through the worker thread - logger.info('\t\t[[[ start worker thread ]]]') - worker = threading.Thread( - target=task_worker_with_assert_called_for_patch_obj, - args=( - task, - 'train', - task_args_dict, - mock_obj, - CancelInterfaceHook, - 'cancel', - ) - ) - worker.start() - logger.info('\t\t[[[ worker started and wait for starting the task (sleep 3) ]]]') - # wait for starting the task - time.sleep(3) - logger.info('\t\t[[[ request cancel to worker with mock object ]]]') - task.cancel_training() - logger.info('\t\t[[[ joining thread... ]]]') - worker.join(timeout=5) - # worker should be alived since join() has to be returned with timeout - # because cancel() interface was patched as a mock and will not do something to - # actual cancel the task. - assert worker.is_alive() - logger.info('\t\t[[[ timeout while joining thread ]]]') - worker.join() # wait for actul termination - logger.info('\t\t[[[ joined thread ]]]') - - # actual cancel training - worker = threading.Thread( - target=task_worker_with_assert_called_for_patch_obj, - args=( - task, - 'train', - task_args_dict, - ) - ) - worker.start() - logger.info('\t\t[[[ worker started and wait for starting the task (sleep 3) ]]]') - # wait for starting the task - time.sleep(3) - logger.info('\t\t[[[ request cancel to worker with mock object ]]]') - task.cancel_training() - logger.info('\t\t[[[ joining thread... ]]]') - worker.join(60) - # worker should not be alived since the task should be terminated by cancel - assert not worker.is_alive() - logger.info('\t\t[[[ joined thread ]]]') - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_detection_task_train_export_and_save( - fixture_task_env, - fixture_dataset_entity, - fixture_train_parameters - ): - task = DetectionTrainTask(fixture_task_env) - - output_model = ModelEntity( - fixture_dataset_entity, - fixture_task_env.get_model_configuration(), - # model_status=ModelStatus.NOT_READY - ) - - task_args_dict = dict( - dataset=fixture_dataset_entity, - output_model=output_model, - ) - task_worker_with_assert_called_for_patch_obj( - task, - 'train', - task_args_dict, - max_epoch=1) - - # for testing _load_model() and infer() from the task_environment - fixture_task_env.model = output_model - new_task = DetectionTrainTask(fixture_task_env) - - val_dataset = fixture_dataset_entity.get_subset(Subset.VALIDATION) - predicted_val_dataset = new_task.infer( - val_dataset.with_empty_annotations(), InferenceParameters(is_evaluation=True)) - - resultset = ResultSetEntity( - model=output_model, - ground_truth_dataset=val_dataset, - prediction_dataset=predicted_val_dataset, - ) - new_task.evaluate(resultset) - - # train - task_worker_with_assert_called_for_patch_obj( - new_task, - 'train', - task_args_dict, - max_epoch=1) - - exported_model = ModelEntity( - fixture_dataset_entity, - fixture_task_env.get_model_configuration(), - # model_status=ModelStatus.NOT_READY - ) - new_task.export(ExportType.OPENVINO, exported_model) - # assert exported_model.model_status == ModelStatus.SUCCESS - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_detection_task_hyperparams( - fixture_task_env, - fixture_dataset_entity, - fixture_train_parameters - ): - - output_model = ModelEntity( - fixture_dataset_entity, - fixture_task_env.get_model_configuration(), - # model_status=ModelStatus.NOT_READY - ) - - # not implemented train types - hyper_parameters = fixture_task_env.get_hyper_parameters() - hyper_parameters.algo_backend.train_type = TrainType.FutureWork - task = DetectionTrainTask(fixture_task_env) - with pytest.raises(Exception) as e: - task.train(fixture_dataset_entity, output_model) - assert e.type == NotImplementedError - - hyper_parameters = fixture_task_env.get_hyper_parameters() - hyper_parameters.algo_backend.train_type = TrainType.SelfSupervised - task = DetectionTrainTask(fixture_task_env) - with pytest.raises(Exception) as e: - task.train(fixture_dataset_entity, output_model) - assert e.type == NotImplementedError - - hyper_parameters = fixture_task_env.get_hyper_parameters() - hyper_parameters.algo_backend.train_type = TrainType.DynamicLabels - task = DetectionTrainTask(fixture_task_env) - with pytest.raises(Exception) as e: - task.train(fixture_dataset_entity, output_model) - assert e.type == NotImplementedError - - hyper_parameters = fixture_task_env.get_hyper_parameters() - hyper_parameters.algo_backend.train_type = TrainType.FutureWork - task = DetectionTrainTask(fixture_task_env) - with pytest.raises(Exception) as e: - task.train(fixture_dataset_entity, output_model) - assert e.type == NotImplementedError diff --git a/tests/unit/apis/utils/__init__.py b/tests/unit/apis/utils/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/apis/utils/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py deleted file mode 100644 index e5fb030f..00000000 --- a/tests/unit/conftest.py +++ /dev/null @@ -1,2 +0,0 @@ -# workaround to resolve ops kernel conflict with mmdet -# from mmcv import ops # noqa: F401 diff --git a/tests/unit/mpa/__init__.py b/tests/unit/mpa/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/det/test_evaluator.py b/tests/unit/mpa/det/test_evaluator.py deleted file mode 100644 index 6a92beac..00000000 --- a/tests/unit/mpa/det/test_evaluator.py +++ /dev/null @@ -1,73 +0,0 @@ -import unittest -import os -import shutil -import pytest -import time -from unittest.mock import patch, MagicMock, Mock - -from mmcv.utils import Config, ConfigDict - -from mpa.det.evaluator import DetectionEvaluator - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestDetectionStage(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_run(self): - recipe_cfg = Config(dict( - task_adapt=dict( - type='', - op='REPLACE', - ), - hyperparams=dict( - ), - work_dir='./logs', - log_level='INFO', - )) - model_cfg = Config(dict( - model=dict( - type='', - ), - )) - model_cfg2 = Config(dict( - model=dict( - type='', - task='other', - ), - )) - data_cfg = Config(dict( - data=dict( - ), - )) - kwargs = dict( - pretrained='pretrained.pth', - mode='eval', - ) - - with patch('mpa.det.stage.Stage.__init__'), patch('mpa.det.evaluator.json.dump'): - stage = DetectionEvaluator() - stage.cfg = recipe_cfg - stage.mode = ['eval'] - super(Config, stage.cfg).__setattr__('dump', MagicMock()) - stage.configure = MagicMock(return_value=stage.cfg) - stage.infer = MagicMock(return_value=dict(detections=[])) - stage.dataset = MagicMock() - stage.dataset.evaluate = MagicMock(return_value=dict(bbox_mAP_50=0.5)) - eval_result = stage.run(model_cfg, 'model.pth', data_cfg, **kwargs) - stage.configure.assert_called() - stage.cfg.dump.assert_called() - stage.infer.assert_called() - stage.dataset.evaluate.assert_called() - self.assertEqual(eval_result['mAP'], 0.5) - diff --git a/tests/unit/mpa/det/test_inferrer.py b/tests/unit/mpa/det/test_inferrer.py deleted file mode 100644 index 8fecd12b..00000000 --- a/tests/unit/mpa/det/test_inferrer.py +++ /dev/null @@ -1,106 +0,0 @@ -import unittest -import os -import shutil -import pytest -import time -from unittest.mock import patch, MagicMock, Mock - -from mmcv.utils import Config, ConfigDict - -from mpa.det.inferrer import DetectionInferrer - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestDetectionStage(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_run(self): - recipe_cfg = Config(dict( - task_adapt=dict( - type='', - op='REPLACE', - ), - hyperparams=dict( - ), - work_dir='./logs', - log_level='INFO', - )) - model_cfg = Config(dict( - model=dict( - type='', - ), - )) - data_cfg = Config(dict( - data=dict( - ), - )) - kwargs = dict( - pretrained='pretrained.pth', - mode='infer', - ) - - with patch('mpa.det.stage.Stage.__init__'), patch('mpa.det.inferrer.np.save'): - stage = DetectionInferrer() - stage.cfg = recipe_cfg - stage.mode = ['infer'] - super(Config, stage.cfg).__setattr__('dump', MagicMock()) - stage.configure = MagicMock(return_value=stage.cfg) - stage.infer = MagicMock(return_value=dict(detections=[])) - infer_result = stage.run(model_cfg, 'model.pth', data_cfg, **kwargs) - stage.configure.assert_called() - stage.cfg.dump.assert_called() - stage.infer.assert_called() - self.assertEqual(infer_result['output_file_path'], './logs/infer_result.npy') - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_infer(self): - cfg = Config(dict( - task_adapt=dict( - type='', - op='REPLACE', - final=['person', 'car'], - ), - hyperparams=dict( - ), - work_dir='./logs', - log_level='INFO', - load_from='pretrained.pth', - model=dict( - type='', - neck=[dict()], - ), - data=dict( - samples_per_gpu=1, - workers_per_gpu=2, - test=dict( - ann_file='test.json', - img_prefix='imgs', - classes=['person', 'car'], - ), - ), - )) - with patch('mpa.det.stage.Stage.__init__'), \ - patch('mpa.det.inferrer.build_dataset') as build_dataset, \ - patch('mpa.det.inferrer.build_dataloader') as build_dataloader, \ - patch('mpa.det.inferrer.build_detector') as build_detector, \ - patch('mpa.det.inferrer.load_checkpoint') as load_checkpoint: - stage = DetectionInferrer() - stage.cfg = cfg - stage._init_logger() - infer_result = stage.infer(cfg) - build_dataset.assert_called() - build_dataloader.assert_called() - build_detector.assert_called() - load_checkpoint.assert_called() diff --git a/tests/unit/mpa/det/test_stage.py b/tests/unit/mpa/det/test_stage.py deleted file mode 100644 index e4a6a28a..00000000 --- a/tests/unit/mpa/det/test_stage.py +++ /dev/null @@ -1,350 +0,0 @@ -import unittest -import os -import shutil -import pytest -import time -from unittest.mock import patch, MagicMock, Mock - -from mmcv.utils import Config, ConfigDict - -from mpa.det.stage import DetectionStage - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestDetectionStage(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure(self): - recipe_cfg = Config(dict( - task_adapt=dict( - type='', - op='REPLACE', - ), - hyperparams=dict( - ), - work_dir='./logs', - log_level='INFO', - )) - model_cfg = Config(dict( - model=dict( - type='', - ), - )) - model_cfg2 = Config(dict( - model=dict( - type='', - task='other', - ), - )) - data_cfg = Config(dict( - data=dict( - ), - )) - kwargs = dict( - pretrained='pretrained.pth', - ) - - with patch('mpa.det.stage.Stage.__init__'): - stage = DetectionStage() - stage.cfg = recipe_cfg - stage._init_logger() - stage.configure_model = MagicMock() - stage.configure_data = MagicMock() - stage.configure_task = MagicMock() - stage.configure_regularization = MagicMock() - stage.configure_hyperparams = MagicMock() - stage.configure_hook = MagicMock() - cfg = stage.configure(model_cfg, 'model.pth', data_cfg, training=True, **kwargs) - stage.configure_model.assert_called() - stage.configure_data.assert_called() - stage.configure_task.assert_called() - stage.configure_regularization.assert_called() - stage.configure_hyperparams.assert_called() - stage.configure_hook.assert_called() - with self.assertRaises(ValueError): - cfg = stage.configure(model_cfg2, 'model.pth', data_cfg, training=True, **kwargs) - with self.assertRaises(ValueError): - cfg = stage.configure(Config(dict(a=1)), 'model.pth', data_cfg, training=True, **kwargs) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_model(self): - cfg = Config(dict( - model=dict( - type='SSD', - super_type='UnbiasedTeacher', - backbone=dict( - type='mobilenetv2_w1', - ), - bbox_head=dict( - type='SSDHead', - ), - ), - )) - with patch('mpa.det.stage.Stage.__init__'): - DetectionStage().configure_model(cfg, training=False) - self.assertEqual(cfg.model.type, 'UnbiasedTeacher') - self.assertEqual(cfg.model.arch_type, 'SSD') - self.assertEqual(cfg.model.bbox_head.type, 'PseudoSSDHead') - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_get_model_classes(self): - cfg = Config(dict( - load_from='somewhere', - model=dict( - classes=['person', 'car',], - ), - )) - with patch('mpa.det.stage.torch.load', return_value={}): - classes = DetectionStage.get_model_classes(cfg) - self.assertEqual(classes, ['person', 'car',]) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_data(self): - cfg = Config(dict( - data=dict( - train=dict( - type='OrgType', - super_type='SuperType', - pipeline=[dict(type='TrainPipe'),], - ), - unlabeled=dict( - img_file='unlabeled.json', - ), - samples_per_gpu=2, - workers_per_gpu=2, - ), - seed=1234, - custom_hooks=[], - )) - with patch('mpa.det.stage.Stage.__init__'), patch('mpa.det.stage.Stage.configure_data') as func: - DetectionStage().configure_data(cfg, training=True) - func.assert_called() - self.assertEqual(cfg.data.train.type, 'SuperType') - self.assertEqual(cfg.data.train.org_type, 'OrgType') - self.assertEqual(cfg.data.unlabeled.pipeline, [dict(type='TrainPipe'),]) - self.assertEqual(len(cfg.custom_hooks), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_task(self): - cfg = Config(dict( - task_adapt=dict( - type='', - op='REPLACE', - ), - )) - with patch('mpa.det.stage.Stage.__init__'): - stage = DetectionStage() - - stage.configure_task_classes = MagicMock( - return_value=(['person'], ['car'], ['car']) - ) - stage.configure_task_data_pipeline = MagicMock() - stage.configure_task_eval_dataset = MagicMock() - stage.configure_task_adapt_hook = MagicMock() - stage.configure_anchor = MagicMock() - stage.configure_task_cls_incr = MagicMock() - stage.configure_task(cfg, training=True) - stage.configure_task_classes.assert_called() - stage.configure_task_data_pipeline.assert_not_called() - stage.configure_task_eval_dataset.assert_called() - stage.configure_task_adapt_hook.assert_called() - stage.configure_anchor.assert_not_called() - stage.configure_task_cls_incr.assert_called() - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_task_classes(self): - cfg = Config(dict( - task_adapt=dict( - final=[], - ), - model=dict( - task_adapt=dict( - src_classes=[], - dst_classes=[], - ), - bbox_head=dict( - num_classes=0, - ), - ), - )) - with patch('mpa.det.stage.Stage.__init__'), patch('mpa.det.stage.DetectionStage.get_model_classes', return_value=['person']), patch('mpa.det.stage.DetectionStage.get_data_classes', return_value=['car']): - stage = DetectionStage() - org_model_classes, model_classes, data_classes = \ - stage.configure_task_classes(cfg, '', 'REPLACE') - self.assertEqual(model_classes, ['car']) - self.assertEqual(cfg.model.bbox_head.num_classes, 1) - org_model_classes, model_classes, data_classes = \ - stage.configure_task_classes(cfg, '', 'MERGE') - self.assertEqual(model_classes, ['person', 'car']) - self.assertEqual(cfg.model.bbox_head.num_classes, 2) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_task_data_pipeline(self): - cfg = Config(dict( - data=dict( - train=dict( - pipeline=[ - dict(type='LoadAnnotations'), - dict(type='Other'), - ], - ), - ), - )) - with patch('mpa.det.stage.Stage.__init__'), patch('mpa.det.stage.DetectionStage.get_model_classes', return_value=['person']), patch('mpa.det.stage.DetectionStage.get_data_classes', return_value=['car']): - stage = DetectionStage() - stage.configure_task_data_pipeline(cfg, ['person', 'car'], ['car']) - self.assertEqual(len(cfg.data.train.pipeline), 3) - stage.configure_task_data_pipeline(cfg, ['person', 'car'], ['car']) - self.assertEqual(len(cfg.data.train.pipeline), 3) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_task_eval_dataset(self): - cfg = Config(dict( - data=dict( - val=dict( - type='CustomDataset', - org_type='', - model_classes=[], - ), - test=dict( - type='CustomDataset', - org_type='', - model_classes=[], - ), - ), - )) - with patch('mpa.det.stage.Stage.__init__'): - stage = DetectionStage() - stage.configure_task_eval_dataset(cfg, ['person', 'car']) - self.assertEqual(cfg.data.val.type, 'TaskAdaptEvalDataset') - self.assertEqual(cfg.data.val.org_type, 'CustomDataset') - self.assertEqual(cfg.data.val.model_classes, ['person', 'car']) - self.assertEqual(cfg.data.test.type, 'TaskAdaptEvalDataset') - self.assertEqual(cfg.data.test.org_type, 'CustomDataset') - self.assertEqual(cfg.data.test.model_classes, ['person', 'car']) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_task_adapt_hook(self): - cfg = Config(dict( - model=dict(type='VFNet'), - task_adapt=dict(), - custom_hooks=[], - )) - with patch('mpa.det.stage.Stage.__init__'): - stage = DetectionStage() - stage.configure_task_adapt_hook(cfg, ['person'], ['person', 'car']) - self.assertEqual(len(cfg.custom_hooks), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_task_cls_incr(self): - cfg = Config(dict( - task_adapt=dict( - type='mpa', - ), - model=dict( - type='SSD', - bbox_head=dict( - type='SSDHead', - ), - ), - data=dict( - train=dict( - type='CocoDataset', - ), - ), - custom_hooks=[], - )) - with patch('mpa.det.stage.Stage.__init__'), patch('mpa.det.stage.DetectionStage.get_img_ids_for_incr', return_value={}): - stage = DetectionStage() - stage.configure_task_cls_incr(cfg, 'mpa', ['person'], ['person', 'car']) - self.assertEqual(len(cfg.custom_hooks), 2) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_regularization(self): - cfg = Config(dict( - model=dict( - l2sp_weight=1.0, - pretrained='pretrained.pth', - ), - load_from='load_from.pth', - optimizer=dict( - weight_decay=0.1, - ), - )) - with patch('mpa.det.stage.Stage.__init__'): - stage = DetectionStage() - stage.configure_regularization(cfg) - self.assertEqual(cfg.model.l2sp_ckpt, 'load_from.pth') - self.assertEqual(cfg.optimizer.weight_decay, 0.0) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure_hparams(self): - cfg = Config(dict( - data=dict( - samples_per_gpu=2, - ), - optimizer=dict( - lr=0.1, - ), - )) - hparams = dict(hyperparams=dict( - bs=8, - lr=0.02, - )) - with patch('mpa.det.stage.Stage.__init__'): - DetectionStage().configure_hyperparams(cfg, training=True, **hparams) - self.assertEqual(cfg.data.samples_per_gpu, 8) - self.assertEqual(cfg.optimizer.lr, 0.02) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_update_or_add_custom_hook(self): - cfg = Config(dict( - custom_hooks=[], - )) - hook1 = dict( - type='SomeHook', - param=1, - ) - hook2 = dict( - type='SomeHook', - param=2, - ) - DetectionStage.update_or_add_custom_hook(cfg, hook1) - self.assertEqual(len(cfg.custom_hooks), 1) - DetectionStage.update_or_add_custom_hook(cfg, hook2) - self.assertEqual(len(cfg.custom_hooks), 1) - self.assertEqual(cfg.custom_hooks, [hook2]) diff --git a/tests/unit/mpa/det/test_trainer.py b/tests/unit/mpa/det/test_trainer.py deleted file mode 100644 index 390d9067..00000000 --- a/tests/unit/mpa/det/test_trainer.py +++ /dev/null @@ -1,119 +0,0 @@ -import unittest -import os -import shutil -import pytest -import time -from unittest.mock import patch, MagicMock, Mock - -from mmcv.utils import Config, ConfigDict - -from mpa.det.trainer import DetectionTrainer - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestDetectionStage(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_run(self): - cfg = Config(dict( - task_adapt=dict( - type='', - op='REPLACE', - final=['person', 'car'], - ), - hparams=dict( - #adaptive_anchor=True, - ), - work_dir='./logs', - log_level='INFO', - gpu_ids=0, - seed=1234, - checkpoint_config=dict( - ), - model=dict( - type='', - ), - data=dict( - train=dict( - ), - ), - dist_params=dict( - linear_scale_lr=True, - ), - optimizer=dict( - lr=0.001, - ), - )) - kwargs = dict( - pretrained='pretrained.pth', - mode='train', - ) - - with patch('mpa.det.stage.Stage.__init__'), \ - patch('mpa.det.trainer.collect_env', return_value={}) as collect_env, \ - patch('mpa.det.trainer.build_dataset') as build_dataset, \ - patch('mpa.det.trainer.extract_anchor_ratio') as extract_anchor_ratio, \ - patch('mpa.det.trainer.DetectionTrainer.train_worker') as train_worker, \ - patch('mpa.det.trainer.mp.spawn') as spawn, \ - patch('mpa.det.trainer.glob.glob', return_value=['best.pth']) as glob: - stage = DetectionTrainer() - stage.cfg = cfg - stage.mode = ['train'] - super(Config, stage.cfg).__setattr__('dump', MagicMock()) - stage.configure = MagicMock(return_value=stage.cfg) - stage.configure_anchor = MagicMock() - train_result = stage.run(Config(), 'model.pth', Config(), **kwargs) - collect_env.assert_called() - build_dataset.assert_called() - extract_anchor_ratio.assert_not_called() - train_worker.assert_called() - spawn.assert_not_called() - glob.assert_called() - stage.configure.assert_called() - stage.configure_anchor.assert_not_called() - stage.cfg.dump.assert_called() - self.assertEqual(train_result['final_ckpt'], 'best.pth') - cfg.gpu_ids = (0, 1) - train_result = stage.run(Config(), 'model.pth', Config(), **kwargs) - spawn.assert_called() - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_train_worker(self): - cfg = Config(dict( - gpu_ids=(0,1), - model=dict( - ), - dist_params=dict( - ), - )) - - with patch('mpa.det.trainer.torch.cuda.set_device') as set_device, \ - patch('mpa.det.trainer.dist.init_process_group') as init_process_group, \ - patch('mpa.det.trainer.dist.get_world_size') as get_world_size, \ - patch('mpa.det.trainer.dist.get_rank') as get_rank, \ - patch('mpa.det.trainer.build_detector') as build_detector, \ - patch('mpa.det.trainer.train_detector') as train_detector: - DetectionTrainer.train_worker((0,1), ['person', 'car'], [], cfg, distributed=True) - set_device.assert_called() - init_process_group.assert_called() - get_world_size.assert_called() - get_rank.assert_called() - build_detector.assert_called() - train_detector.assert_called() - DetectionTrainer.train_worker((0,1), ['person', 'car'], [], cfg, distributed=False) - set_device.assert_called_once() - init_process_group.assert_called_once() - get_world_size.assert_called_once() - get_rank.assert_called_once() diff --git a/tests/unit/mpa/modules/__init__.py b/tests/unit/mpa/modules/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/datasets/__init__.py b/tests/unit/mpa/modules/datasets/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/datasets/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/datasets/_test_cls_tv_dataset.py b/tests/unit/mpa/modules/datasets/_test_cls_tv_dataset.py deleted file mode 100644 index 1128f093..00000000 --- a/tests/unit/mpa/modules/datasets/_test_cls_tv_dataset.py +++ /dev/null @@ -1,207 +0,0 @@ -import os -import unittest -from unittest.mock import patch, Mock, MagicMock -import pytest -import numpy as np - -from torch import Tensor -from torchvision.datasets import CIFAR10 -from mmcls.datasets import build_dataset -from mpa.modules.experimental.datasets.cls_tv_dataset import ClsTVDataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClsTVDataset(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - dataset_type = 'ClsTVDataset' - img_norm_cfg = dict( - mean=[129.3, 124.1, 112.4], std=[68.2, 65.4, 70.4], to_rgb=True) - self.train_pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - self.data_cfg = dict( - type=dataset_type, - base='CIFAR10', - train=True, - pipeline=self.train_pipeline, - samples_per_gpu=16, - workers_per_gpu=4, - download=True - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_dataset(self): - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, ClsTVDataset)) - - self.data_cfg['base'] = 'CIFAR1000' - with pytest.raises(Exception) as e: - dataset = build_dataset(self.data_cfg) - self.assertEqual(e.type, AttributeError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset(self): - dataset = build_dataset(self.data_cfg) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_evaluate(self): - dataset = build_dataset(self.data_cfg) - ds_len = len(dataset) - dummy_res = [np.array([[1., 0., 0.]]) for i in range(ds_len)] - metrics = ['accuracy', 'precision', 'recall', 'f1_score'] - for metric in metrics: - eval = dataset.evaluate(dummy_res, metric) - self.assertTrue(isinstance(eval, dict)) - for k, v in eval.items(): - self.assertTrue(k.startswith(metric)) - - # class_accuracy - metric = 'class_accuracy' - eval = dataset.evaluate(dummy_res, metric) - self.assertTrue(isinstance(eval, dict)) - for k, v in eval.items(): - self.assertTrue(k.endswith('accuracy')) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_base_dataset(self): - bases = ['CIFAR10', 'CIFAR100', 'STL10', 'SVHN'] - num_images = 10 - for base in bases: - ds = ClsTVDataset( - base, - num_images=num_images, - balanced_class=False, - ) - item = ds[0] - self.assertEqual(num_images, len(ds)) - self.assertTrue('img' in item) - self.assertIsInstance(item['img'], Tensor) - self.assertTrue('gt_label' in item) - self.assertIsInstance(item['gt_label'], Tensor) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset_init(self): - base = Mock() - base.targets = [] - base.labels = [] - delattr(base, 'targets') - delattr(base, 'labels') - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base) - self.assertEqual(e.type, NotImplementedError) - - num_indices = 10 - baseset_len = 50000 - base = CIFAR10('data/torchvision/cifar10', download=True) - ds = ClsTVDataset(base) - ds2 = ClsTVDataset('CIFAR10') - self.assertEqual(len(ds), len(ds2)) - - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, include_idx=range(num_indices)) - self.assertEqual(e.type, TypeError) - - ds = ClsTVDataset(base, include_idx=list(range(num_indices))) - self.assertEqual(len(ds), num_indices) - - # test for include_idx param - ds = ClsTVDataset(base, include_idx=os.path.join(self.assets_path, 'indices/cifar10-7k.p')) - self.assertEqual(len(ds), 7000) - - logger_warning = MagicMock() - with patch('mpa.modules.datasets.cls_tv_dataset.logger.warning', logger_warning): - ds = ClsTVDataset(base, include_idx='path/not/exist.p') - logger_warning.assert_called() - del logger_warning - - # test for exclude_idx param - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, exclude_idx=range(num_indices)) - self.assertEqual(e.type, TypeError) - - ds = ClsTVDataset(base, exclude_idx=list(range(num_indices))) - self.assertEqual(len(ds), baseset_len - num_indices) - - ds = ClsTVDataset(base, exclude_idx=os.path.join(self.assets_path, 'indices/cifar10-7k.p')) - self.assertEqual(len(ds), baseset_len - 7000) - - logger_warning = MagicMock() - with patch('mpa.modules.datasets.cls_tv_dataset.logger.warning', logger_warning): - ds = ClsTVDataset(base, exclude_idx='path/not/exist.p') - logger_warning.assert_called() - - # test num_images param - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, num_images=baseset_len+1) - self.assertEqual(e.type, RuntimeError) - - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, num_images=-100) - self.assertEqual(e.type, RuntimeError) - - split_len = 100 - ds = ClsTVDataset(base, num_images=split_len) - self.assertEqual(len(ds), split_len) - - ds = ClsTVDataset(base, num_images=split_len, use_labels=False) - self.assertEqual(len(ds), split_len) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset_classes(self): - ds = ClsTVDataset( - 'CIFAR10', - ) - self.assertEqual(len(ds.CLASSES), 10) - - ds = ClsTVDataset( - 'CIFAR10', - classes=[0, 1, 2] - ) - self.assertEqual(len(ds.CLASSES), 3) - - ds = ClsTVDataset( - 'CIFAR10', - classes=[0, 1, 2] - ) - self.assertEqual(len(ds.CLASSES), 3) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_incr_data(self): - base = 'CIFAR10' - ds = ClsTVDataset( - base, - num_images=40, - classes=[0, 1, 2, 3], - new_classes=[3] - ) - self.assertEqual(len(ds.img_indices['old']), 30) - self.assertEqual(len(ds.img_indices['new']), 10) diff --git a/tests/unit/mpa/modules/datasets/sources/__init__.py b/tests/unit/mpa/modules/datasets/sources/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/datasets/sources/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/datasets/sources/test_builder.py b/tests/unit/mpa/modules/datasets/sources/test_builder.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/unit/mpa/modules/datasets/sources/test_ote_dataset_entity.py b/tests/unit/mpa/modules/datasets/sources/test_ote_dataset_entity.py deleted file mode 100644 index 492ed924..00000000 --- a/tests/unit/mpa/modules/datasets/sources/test_ote_dataset_entity.py +++ /dev/null @@ -1,35 +0,0 @@ -import pytest -# from unittest.mock import patch, Mock - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from ote_sdk.entities.datasets import Subset - -from mpa.modules.datasets.sources.ote_dataset_entity import OTEDatasetEntity -from mpa.utils.logger import get_logger - -logger = get_logger() - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_ote_dataset_entity_init(fixture_dataset_entity): - source1 = OTEDatasetEntity(fixture_dataset_entity, Subset.TRAINING, label_list=['0', '1', '2']) - assert source1.get_length() == 12 # .png image counts in tests/assets/dirs/classification/train - - source2 = OTEDatasetEntity(fixture_dataset_entity, Subset.VALIDATION, label_list=['0', '1', '2']) - assert source2.get_length() == 12 # .png image counts in tests/assets/dirs/classification/val - - source3 = OTEDatasetEntity(fixture_dataset_entity, Subset.UNLABELED, label_list=['0', '1', '2']) - assert source3.get_length() == 4 # .png image counts in tests/assets/dirs/classification/unlabeled - - for idx in range(source1.get_length()): - sample = source1.get_sample(idx) - logger.info(f"[{idx}] annotations: rectangles = {sample['rectangles']}, labels = {sample['labels']}") - assert 'rectangles' in sample.keys() - assert 'labels' in sample.keys() - assert 'img_info' in sample.keys() - assert 'img' in sample.keys() diff --git a/tests/unit/mpa/modules/datasets/test_augmix.py b/tests/unit/mpa/modules/datasets/test_augmix.py deleted file mode 100644 index 2c509822..00000000 --- a/tests/unit/mpa/modules/datasets/test_augmix.py +++ /dev/null @@ -1,70 +0,0 @@ -import unittest -import pytest -import torchvision -from PIL import Image - -from mpa.modules.datasets.pipelines.transforms.augmix import ( - AugMixAugment, OpsFabric, _AUGMIX_TRANSFORMS, _AUGMIX_TRANSFORMS_GREY -) - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestAugmix(unittest.TestCase): - def setUp(self): - self.dataset = getattr(torchvision.datasets, "SVHN")( - "./data/torchvision/svhn", split="train", download=True - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_augmix(self): - """ - Verifies that AugMix works & all augment_pool is working - """ - augmix = AugMixAugment(config_str="augmix-m5-w3") - img = self.dataset[0][0] - dummy_data = {"img": img} - result = augmix(dummy_data) - self.assertTrue(result["augmix"]) - self.assertEqual(len(augmix.ops), 12) - self.assertEqual(augmix.width, 3) - - augmix = AugMixAugment(config_str="augmix-m5-w5") - self.assertEqual(augmix.width, 5) - - # Set grey parameter - augmix = AugMixAugment(config_str="augmix-m5-w5", grey=True) - self.assertEqual(len(augmix.ops), 5) - - # all op test - hparams = dict( - translate_const=250, - img_mean=tuple([int(c * 256) for c in [0.485, 0.456, 0.406]]), - magnitude_std=float("inf"), - ) - op_lst = [OpsFabric(name, 3, hparams, 1.0) for name in _AUGMIX_TRANSFORMS] - for op in op_lst: - img_aug = op(img) - self.assertTrue(isinstance(img_aug, Image.Image)) - op_lst = [OpsFabric(name, 3, hparams, 1.0) for name in _AUGMIX_TRANSFORMS_GREY] - for op in op_lst: - img_aug = op(img) - self.assertTrue(isinstance(img_aug, Image.Image)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_augmix_wrong_parameter(self): - with self.assertRaises(AssertionError): - AugMixAugment(config_str="m5-w3") - with self.assertRaises(AssertionError): - AugMixAugment(config_str="augmix-z5") - with self.assertRaises(ValueError): - AugMixAugment(config_str="augmix-m0.1") diff --git a/tests/unit/mpa/modules/datasets/test_cls_csv_dataset.py b/tests/unit/mpa/modules/datasets/test_cls_csv_dataset.py deleted file mode 100644 index 2ca3e3fb..00000000 --- a/tests/unit/mpa/modules/datasets/test_cls_csv_dataset.py +++ /dev/null @@ -1,76 +0,0 @@ -import unittest -import os -import pytest -import numpy as np - -from mpa.modules.datasets.cls_csv_dataset import CSVDatasetCls -from mmcls.datasets import build_dataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestMultiClassDataset(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - dataset_type = 'CSVDatasetCls' - img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) - pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='RandomFlip', flip_prob=0.5, direction='vertical'), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - data_prefix = os.path.join(self.assets_path, 'csvs/imgs') - self.data_file = os.path.join(self.assets_path, 'csvs/dss18.data.csv') - self.anno_file = os.path.join(self.assets_path, 'csvs/dss18.anno.single_cls.csv') - self.classes = ["Other", "Senior", "Kids", "Unknown"] - self.data_cfg = dict( - type=dataset_type, - data_prefix=data_prefix, - ann_file=self.anno_file, - data_file=self.data_file, - pipeline=pipeline, - classes=self.classes - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_dataset(self): - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, CSVDatasetCls)) - - self.data_cfg['data_file'] = 'path/not/exist.csv' - with pytest.raises(Exception): - dataset = build_dataset(self.data_cfg) - # self.assertEqual(e.type, ValueError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset(self): - dataset = build_dataset(self.data_cfg) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_evaluate(self): - dataset = build_dataset(self.data_cfg) - dummy_res = [np.array([[1., 0., 0.]]) for i in range(10)] - metrics = ['accuracy', 'precision', 'recall', 'f1_score'] - for metric in metrics: - eval = dataset.evaluate(dummy_res, metric) - self.assertTrue(isinstance(eval, dict)) diff --git a/tests/unit/mpa/modules/datasets/test_cls_csv_incr_dataset.py b/tests/unit/mpa/modules/datasets/test_cls_csv_incr_dataset.py deleted file mode 100644 index ebe1b6de..00000000 --- a/tests/unit/mpa/modules/datasets/test_cls_csv_incr_dataset.py +++ /dev/null @@ -1,143 +0,0 @@ -import unittest -import os -import pytest -import numpy as np - -from mpa.modules.datasets.cls_csv_incr_dataset import LwfTaskIncDataset, ClassIncDataset -from mmcls.datasets import build_dataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClsLwfDataset(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - dataset_type = 'LwfTaskIncDataset' - img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) - self.pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='RandomFlip', flip_prob=0.5, direction='vertical'), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - self.data_prefix = os.path.join(self.assets_path, 'csvs/imgs') - self.data_file = os.path.join(self.assets_path, 'csvs/dss18.data.csv') - self.anno_file = os.path.join(self.assets_path, 'csvs/dss18.anno.multi_task.csv') - self.tasks = { - 'Age': ["Other", "Senior", "Kids", "Unknown"] - } - self.data_cfg = dict( - type=dataset_type, - data_prefix=self.data_prefix, - ann_file=self.anno_file, - data_file=self.data_file, - pipeline=self.pipeline, - tasks=self.tasks - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_task_incr_dataset(self): - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, LwfTaskIncDataset)) - - self.data_cfg['data_file'] = 'path/not/exist.csv' - with pytest.raises(Exception): - dataset = build_dataset(self.data_cfg) - # self.assertEqual(e.type, ValueError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_task_incr_dataset(self): - dataset = build_dataset(self.data_cfg) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - self.assertFalse(data_infos[0].get('soft_labels', False)) - - old_tasks = {'dummy_task': ['1', '2', '3']} - old_prob = {'dummy_task': np.random.rand(10, 3)} - model_tasks = old_tasks - model_tasks.update(self.tasks) - for i, data_info in enumerate(data_infos): - data_info['soft_label'] = {task: value[i] for task, value in old_prob.items()} - np.save('dummy_task_inc.npy', data_infos) - dataset_lwf = build_dataset(self.data_cfg, - default_args={'pre_stage_res': 'dummy_task_inc.npy', 'model_tasks': model_tasks}) - data_infos = dataset_lwf.data_infos - self.assertTrue(data_infos[0].get('soft_label', False)) - self.assertTrue(isinstance(data_infos[0]['soft_label'], dict)) - os.remove('dummy_task_inc.npy') - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_cls_incr_dataset(self): - dataset_type = 'ClassIncDataset' - data_file = os.path.join(self.assets_path, 'csvs/dss18.data.csv') - anno_file = os.path.join(self.assets_path, 'csvs/dss18.anno.single_cls.csv') - classes = ["Other", "Senior", "Kids", "Unknown"] - self.data_cfg = dict( - type=dataset_type, - data_prefix=self.data_prefix, - ann_file=anno_file, - data_file=data_file, - pipeline=self.pipeline, - classes=classes - ) - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, ClassIncDataset)) - - self.data_cfg['data_file'] = 'path/not/exist.csv' - with pytest.raises(Exception): - dataset = build_dataset(self.data_cfg) - # self.assertEqual(e.type, ValueError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_incr_dataset(self): - dataset_type = 'ClassIncDataset' - data_file = os.path.join(self.assets_path, 'csvs/dss18.data.csv') - anno_file = os.path.join(self.assets_path, 'csvs/dss18.anno.single_cls.csv') - classes = ["Other", "Senior", "Kids", "Unknown"] - self.data_cfg = dict( - type=dataset_type, - data_prefix=self.data_prefix, - ann_file=anno_file, - data_file=data_file, - pipeline=self.pipeline, - classes=classes - ) - dataset = build_dataset(self.data_cfg) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - self.assertFalse(data_infos[0].get('soft_labels', False)) - self.assertFalse(data_infos[0].get('center', False)) - - old_prob = np.random.rand(10, 4) - center = np.random.rand(10, 10) - for i, data_info in enumerate(data_infos): - data_info['soft_label'] = old_prob[i] - data_info['center'] = center[i] - np.save('dummy_cls_inc.npy', data_infos) - dataset_incr = build_dataset(self.data_cfg, - default_args={'pre_stage_res': 'dummy_cls_inc.npy', 'dst_classes': classes}) - data_infos_incr = dataset_incr.data_infos - self.assertEqual(len(data_infos_incr[0]['soft_label']), 4) - self.assertEqual(len(data_infos_incr[0]['center']), 10) - os.remove('dummy_cls_inc.npy') diff --git a/tests/unit/mpa/modules/datasets/test_cls_dir_dataset.py b/tests/unit/mpa/modules/datasets/test_cls_dir_dataset.py deleted file mode 100644 index 6f4351b9..00000000 --- a/tests/unit/mpa/modules/datasets/test_cls_dir_dataset.py +++ /dev/null @@ -1,186 +0,0 @@ -import unittest -import os -import pytest -import numpy as np - -from mpa.modules.datasets.cls_dir_dataset import ClsDirDataset -from mmcls.datasets import build_dataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClsDirDataset(unittest.TestCase): - def setUp(self): - """ - Classification Dataset from Directory settings - """ - self.assets_path = 'tests/assets' - - self.dataset_type = 'ClsDirDataset' - self.img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) - self.pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='RandomFlip', flip_prob=0.5, direction='vertical'), - dict(type='Normalize', **self.img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - self.data_prefix = os.path.join(self.assets_path, 'dirs/classification') - self.train_prefix = os.path.join(self.data_prefix, 'train') - - self.data_cfg = dict( - type=self.dataset_type, - data_dir=self.train_prefix, - pipeline=self.pipeline, - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_cls_dir_dataset(self): - """ - Verifies that ClsDirDataset build works - """ - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, ClsDirDataset)) - - self.data_cfg['data_dir'] = 'path/not/' - with pytest.raises(Exception): - dataset = build_dataset(self.data_cfg) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_dir_dataset(self): - """ - Verifies that ClsDirDataset config vary - """ - dataset = build_dataset(self.data_cfg) - classes = dataset.CLASSES - self.assertTrue(isinstance(classes, list)) - self.assertEqual(len(classes), 3) - self.assertEqual(len(dataset), 12) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - self.assertTrue(dataset[0].get('img_metas', False)) - - self.assertEqual(dataset.num_classes, 3) - self.assertEqual(dataset.samples_per_gpu, 1) - self.assertEqual(dataset.workers_per_gpu, 1) - - self.assertTrue(dataset.use_labels) - self.assertFalse(dataset.class_acc) - - # Use unlabeled data settings - self.data_cfg['use_labels'] = False - self.data_cfg['data_dir'] = os.path.join(self.data_prefix, 'unlabeled') - dataset = build_dataset(self.data_cfg) - self.assertEqual(dataset.num_classes, 1) - self.assertEqual(dataset.CLASSES[0], 'unlabeled') - - # Use partial classes (2 of 3) - classes = ['0', '1'] - data_cfg = dict( - type=self.dataset_type, - data_dir=self.train_prefix, - pipeline=self.pipeline, - classes=classes - ) - dataset = build_dataset(data_cfg) - self.assertEqual(dataset.num_classes, len(classes)) - self.assertEqual(dataset.CLASSES, classes) - - # Incremental-Learning Settings - new_classes = ['2'] - data_cfg = dict( - type=self.dataset_type, - data_dir=self.train_prefix, - pipeline=self.pipeline, - new_classes=new_classes, - classes=classes + new_classes - ) - dataset = build_dataset(data_cfg) - self.assertEqual(dataset.num_classes, len(classes) + len(new_classes)) - self.assertTrue(isinstance(dataset.img_indices, dict)) - self.assertTrue(isinstance(dataset.img_indices['old'], list)) - self.assertEqual(len(dataset.img_indices['old']), 8) - self.assertTrue(isinstance(dataset.img_indices['new'], list)) - self.assertEqual(len(dataset.img_indices['new']), 4) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_dir_dataset_evaluation(self): - """ - Verifies that ClsDirDataset evaluation function works - """ - classes = ['0', '1', '2'] - new_classes = ['2'] - data_cfg = dict( - type=self.dataset_type, - data_dir=self.train_prefix, - pipeline=self.pipeline, - new_classes=new_classes, - classes=classes - ) - - dataset = build_dataset(data_cfg) - np.random.seed(1234) - temp_prob = np.random.rand(12, 4) - eval_results = dataset.evaluate(temp_prob) - self.assertTrue(isinstance(eval_results, dict)) - self.assertEqual(len(eval_results), 1) - - eval_results = dataset.evaluate(temp_prob, metric='class_accuracy') - self.assertTrue(isinstance(eval_results, dict)) - self.assertEqual(len(eval_results), 4) - eval_results = dataset.evaluate(temp_prob, metric=['accuracy', 'class_accuracy']) - self.assertTrue(isinstance(eval_results, dict)) - self.assertEqual(len(eval_results), 5) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_dir_dataset_dict_pipeline(self): - """ - Verifies that ClsDirDataset works with dictionary pipeline - """ - strong_pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='RandomFlip', flip_prob=0.5, direction='vertical'), - dict(type="RandomRotate", p=0.35, angle=(-10, 10)), - dict(type="ToNumpy"), - dict(type='Normalize', **self.img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - data_cfg = dict( - type=self.dataset_type, - data_dir=self.train_prefix, - pipeline=dict(weak=self.pipeline, strong=strong_pipeline), - ) - - dataset = build_dataset(data_cfg) - self.assertEqual(dataset.num_pipes, 2) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_dir_dataset_with_value_error(self): - """ - Verifies that ClsDirDataset raise Exception - use_label=True, but if the folder structure is not suitable (unlabeled) - """ - self.data_cfg['data_dir'] = os.path.join(self.data_prefix, 'unlabeled') - with self.assertRaises(ValueError): - build_dataset(self.data_cfg) diff --git a/tests/unit/mpa/modules/datasets/test_cls_incr_sampler.py b/tests/unit/mpa/modules/datasets/test_cls_incr_sampler.py deleted file mode 100644 index f6abfae9..00000000 --- a/tests/unit/mpa/modules/datasets/test_cls_incr_sampler.py +++ /dev/null @@ -1,87 +0,0 @@ -import unittest -import pytest -import numpy as np - -from mmcls.datasets import build_dataset -from mpa.modules.datasets.samplers.cls_incr_sampler import ClsIncrSampler - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClsIncrSampler(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - dataset_type = 'ClsTVDataset' - self.data_cfg = dict( - type=dataset_type, - base='CIFAR10', - num_images=32, - classes=[0, 1, 2, 3], - new_classes=[3] - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_incr_sampler(self): - # Default Settings - dataset = build_dataset(self.data_cfg) - batch_size = 8 - sampler = ClsIncrSampler(dataset, batch_size) - self.assertEqual(len(sampler), dataset.num_images) - self.assertEqual(len(sampler.new_indices) + len(sampler.old_indices), dataset.num_images) - self.assertEqual(len(sampler.new_indices), 8) - self.assertEqual(len(sampler.old_indices), 24) - old_new_ratio = np.sqrt(len(sampler.old_indices) / len(sampler.new_indices)) - self.assertEqual(sampler.old_new_ratio, int(old_new_ratio)) - - # Repeat = 3 - dataset = build_dataset(self.data_cfg) - dataset.times = 3 - sampler = ClsIncrSampler(dataset, batch_size) - self.assertEqual(len(sampler), dataset.num_images * dataset.times) - - # Efficient Mode - dataset = build_dataset(self.data_cfg) - batch_size = 8 - sampler = ClsIncrSampler(dataset, batch_size, efficient_mode=True) - self.assertEqual(len(sampler.new_indices) + len(sampler.old_indices), dataset.num_images) - self.assertEqual(len(sampler.new_indices), 8) - self.assertEqual(len(sampler.old_indices), 24) - old_new_ratio = np.sqrt(len(sampler.old_indices) / len(sampler.new_indices)) - data_length = int(len(sampler.new_indices) * (1 + old_new_ratio)) - self.assertEqual(len(sampler), data_length) - self.assertEqual(sampler.old_new_ratio, 1) - - # no new_classes - data_cfg = dict( - type='ClsTVDataset', - base='CIFAR10', - num_images=32, - classes=[0, 1, 2, 3], - ) - dataset = build_dataset(data_cfg) - with self.assertRaises(ValueError): - sampler = ClsIncrSampler(dataset, batch_size) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_iter_cls_incr_sampler(self): - data_cfg = dict( - type='ClsTVDataset', - base='CIFAR10', - num_images=40, - classes=[0, 1, 2, 3, 4], - new_classes=[4] - ) - dataset = build_dataset(data_cfg) - batch_size = 8 - sampler = ClsIncrSampler(dataset, batch_size) - iter_sampler = iter(sampler) - self.assertEqual(len(list(iter_sampler)), dataset.num_images) diff --git a/tests/unit/mpa/modules/datasets/test_cls_tv_dataset.py b/tests/unit/mpa/modules/datasets/test_cls_tv_dataset.py deleted file mode 100644 index 4012c3d6..00000000 --- a/tests/unit/mpa/modules/datasets/test_cls_tv_dataset.py +++ /dev/null @@ -1,207 +0,0 @@ -import os -import unittest -from unittest.mock import patch, Mock, MagicMock -import pytest -import numpy as np - -from torch import Tensor -from torchvision.datasets import CIFAR10 -from mmcls.datasets import build_dataset -from mpa.modules.experimental.datasets.cls_tv_dataset import ClsTVDataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClsTVDataset(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - dataset_type = 'ClsTVDataset' - img_norm_cfg = dict( - mean=[129.3, 124.1, 112.4], std=[68.2, 65.4, 70.4], to_rgb=True) - self.train_pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - self.data_cfg = dict( - type=dataset_type, - base='CIFAR10', - train=True, - pipeline=self.train_pipeline, - samples_per_gpu=16, - workers_per_gpu=4, - download=True - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_dataset(self): - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, ClsTVDataset)) - - self.data_cfg['base'] = 'CIFAR1000' - with pytest.raises(Exception) as e: - dataset = build_dataset(self.data_cfg) - self.assertEqual(e.type, AttributeError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset(self): - dataset = build_dataset(self.data_cfg) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_evaluate(self): - dataset = build_dataset(self.data_cfg) - ds_len = len(dataset) - dummy_res = [np.array([[1., 0., 0.]]) for i in range(ds_len)] - metrics = ['accuracy', 'precision', 'recall', 'f1_score'] - for metric in metrics: - eval = dataset.evaluate(dummy_res, metric) - self.assertTrue(isinstance(eval, dict)) - for k, v in eval.items(): - self.assertTrue(k.startswith(metric)) - - # class_accuracy - metric = 'class_accuracy' - eval = dataset.evaluate(dummy_res, metric) - self.assertTrue(isinstance(eval, dict)) - for k, v in eval.items(): - self.assertTrue(k.endswith('accuracy')) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_base_dataset(self): - bases = ['CIFAR10', 'CIFAR100', 'STL10', 'SVHN'] - num_images = 10 - for base in bases: - ds = ClsTVDataset( - base, - num_images=num_images, - balanced_class=False, - ) - item = ds[0] - self.assertEqual(num_images, len(ds)) - self.assertTrue('img' in item) - self.assertIsInstance(item['img'], Tensor) - self.assertTrue('gt_label' in item) - self.assertIsInstance(item['gt_label'], Tensor) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset_init(self): - base = Mock() - base.targets = [] - base.labels = [] - delattr(base, 'targets') - delattr(base, 'labels') - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base) - self.assertEqual(e.type, NotImplementedError) - - num_indices = 10 - baseset_len = 50000 - base = CIFAR10('data/torchvision/cifar10', download=True) - ds = ClsTVDataset(base) - ds2 = ClsTVDataset('CIFAR10') - self.assertEqual(len(ds), len(ds2)) - - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, include_idx=range(num_indices)) - self.assertEqual(e.type, TypeError) - - ds = ClsTVDataset(base, include_idx=list(range(num_indices))) - self.assertEqual(len(ds), num_indices) - - # test for include_idx param - ds = ClsTVDataset(base, include_idx=os.path.join(self.assets_path, 'indices/cifar10-7k.p')) - self.assertEqual(len(ds), 7000) - - logger_warning = MagicMock() - with patch('mpa.utils.logger.warning', logger_warning): - ds = ClsTVDataset(base, include_idx='path/not/exist.p') - logger_warning.assert_called() - del logger_warning - - # test for exclude_idx param - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, exclude_idx=range(num_indices)) - self.assertEqual(e.type, TypeError) - - ds = ClsTVDataset(base, exclude_idx=list(range(num_indices))) - self.assertEqual(len(ds), baseset_len - num_indices) - - ds = ClsTVDataset(base, exclude_idx=os.path.join(self.assets_path, 'indices/cifar10-7k.p')) - self.assertEqual(len(ds), baseset_len - 7000) - - logger_warning = MagicMock() - with patch('mpa.utils.logger.warning', logger_warning): - ds = ClsTVDataset(base, exclude_idx='path/not/exist.p') - logger_warning.assert_called() - - # test num_images param - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, num_images=baseset_len+1) - self.assertEqual(e.type, RuntimeError) - - with pytest.raises(Exception) as e: - ds = ClsTVDataset(base, num_images=-100) - self.assertEqual(e.type, RuntimeError) - - split_len = 100 - ds = ClsTVDataset(base, num_images=split_len) - self.assertEqual(len(ds), split_len) - - ds = ClsTVDataset(base, num_images=split_len, use_labels=False) - self.assertEqual(len(ds), split_len) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset_classes(self): - ds = ClsTVDataset( - 'CIFAR10', - ) - self.assertEqual(len(ds.CLASSES), 10) - - ds = ClsTVDataset( - 'CIFAR10', - classes=[0, 1, 2] - ) - self.assertEqual(len(ds.CLASSES), 3) - - ds = ClsTVDataset( - 'CIFAR10', - classes=[0, 1, 2] - ) - self.assertEqual(len(ds.CLASSES), 3) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cls_incr_data(self): - base = 'CIFAR10' - ds = ClsTVDataset( - base, - num_images=40, - classes=[0, 1, 2, 3], - new_classes=[3] - ) - self.assertEqual(len(ds.img_indices['old']), 30) - self.assertEqual(len(ds.img_indices['new']), 10) diff --git a/tests/unit/mpa/modules/datasets/test_composed_dataloader.py b/tests/unit/mpa/modules/datasets/test_composed_dataloader.py deleted file mode 100644 index c27fe401..00000000 --- a/tests/unit/mpa/modules/datasets/test_composed_dataloader.py +++ /dev/null @@ -1,119 +0,0 @@ -import unittest -import os -import torch -import pytest - -from mpa.modules.datasets.composed_dataloader import ComposedDL, CDLIterator -from mmcls.datasets import build_dataset, build_dataloader - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestComposedDL(unittest.TestCase): - def setUp(self): - """ - ComposedDL settings with ClsDirDataset Settings - """ - self.assets_path = 'tests/assets' - - self.dataset_type = 'ClsDirDataset' - self.img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) - self.pipeline = [ - dict(type='RandomFlip', flip_prob=0.5, direction='vertical'), - dict(type='Normalize', **self.img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - self.data_prefix = os.path.join(self.assets_path, 'dirs/classification') - self.labeled_prefix = os.path.join(self.data_prefix, 'train') - self.unlabeled_prefix = os.path.join(self.data_prefix, 'unlabeled') - - def tearDown(self): - pass - - def get_sub_loaders(self, labeled_batch_size, unlabeled_batch_size): - label_data_cfg = dict( - type=self.dataset_type, - data_dir=self.labeled_prefix, - pipeline=self.pipeline, - samples_per_gpu=labeled_batch_size, - ) - - unlabel_data_cfg = dict( - type=self.dataset_type, - data_dir=self.unlabeled_prefix, - pipeline=dict(weak=self.pipeline, strong=self.pipeline), - use_labels=False, - samples_per_gpu=unlabeled_batch_size - ) - ds = [build_dataset(label_data_cfg), build_dataset(unlabel_data_cfg)] - sub_loaders = [ - build_dataloader( - sub_ds, - sub_ds.samples_per_gpu if hasattr(sub_ds, 'samples_per_gpu') else 1, - 1, - num_gpus=1, - dist=False, - round_up=True, - seed=1234, - ) for sub_ds in ds - ] - return sub_loaders - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_composed_dl(self): - """ - Verifies that ComposedDL works - """ - torch.manual_seed(1234) - labeled_bs = 3 - unlabeled_bs = 4 - composed_dl = ComposedDL(self.get_sub_loaders(labeled_bs, unlabeled_bs)) - self.assertEqual(composed_dl.max_iter, 4) - self.assertEqual(len(composed_dl), 4) - - composed_iter = iter(composed_dl) - self.assertTrue(isinstance(composed_iter, CDLIterator)) - - for i in range(len(composed_dl)): - batch = next(composed_iter) - self.assertTrue(isinstance(batch, dict)) - self.assertEqual(len(batch['img']), labeled_bs) - self.assertEqual(len(batch['gt_label']), labeled_bs) - - self.assertIn('extra_0', batch) - self.assertTrue(isinstance(batch['extra_0'], dict)) - self.assertIn('weak', batch['extra_0']) - self.assertEqual(len(batch['extra_0']['weak']['img']), unlabeled_bs) - self.assertIn('strong', batch['extra_0']) - self.assertEqual(len(batch['extra_0']['strong']['img']), unlabeled_bs) - - # over max-iteration - with self.assertRaises(StopIteration): - batch = next(composed_iter) - - labeled_bs = 3 - unlabeled_bs = 5 # unlabeled data: 4 images - composed_dl = ComposedDL(self.get_sub_loaders(labeled_bs, unlabeled_bs)) - composed_iter = iter(composed_dl) - batch = next(composed_iter) - self.assertEqual(len(batch['img']), labeled_bs) - self.assertEqual(len(batch['gt_label']), labeled_bs) - self.assertEqual(len(batch['extra_0']['weak']['img']), 4) - self.assertEqual(len(batch['extra_0']['strong']['img']), 4) - - labeled_bs = 16 # labeled data: 12 images - unlabeled_bs = 4 - composed_dl = ComposedDL(self.get_sub_loaders(labeled_bs, unlabeled_bs)) - composed_iter = iter(composed_dl) - batch = next(composed_iter) - self.assertEqual(len(batch['img']), 12) - self.assertEqual(len(batch['gt_label']), 12) - self.assertEqual(len(batch['extra_0']['weak']['img']), unlabeled_bs) - self.assertEqual(len(batch['extra_0']['strong']['img']), unlabeled_bs) diff --git a/tests/unit/mpa/modules/datasets/test_det_csv_dataset.py b/tests/unit/mpa/modules/datasets/test_det_csv_dataset.py deleted file mode 100644 index ab0d4c0a..00000000 --- a/tests/unit/mpa/modules/datasets/test_det_csv_dataset.py +++ /dev/null @@ -1,48 +0,0 @@ -import pytest -from mpa.modules.datasets.det_csv_dataset import CSVDatasetDet - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_det_csv_dataset(tmpdir): - data_csv = tmpdir.join('data.csv') - anno_csv = tmpdir.join('anno.csv') - data_csv.write(""" -ImageID,ImagePath,Width,Height -0,Shoppertrack_3983_Reidentification_Shoppertrack_0_Cam1cut1.mp4_00001723.jpg,1280,720 -1,Shoppertrack_3984_Reidentification_Shoppertrack_0_Cam2cut1.mp4_00002286.jpg,1280,720 -2,Shoppertrack_3984_Reidentification_Shoppertrack_0_Cam2cut1.mp4_00003772.jpg,1280,720 -3,Shoppertrack_3983_Reidentification_Shoppertrack_0_Cam1cut1.mp4_00003659.jpg,1280,720 - """) - - anno_csv.write(""" -AnnoID,ImageID,Xmin,Ymin,Xmax,Ymax,ClassName,IsOccluded -0,0,317.989990234375,55.9900016784668,389.0799865722656,142.0,Person,True -1,0,299.8999938964844,112.30000305175781,394.0199890136719,365.70001220703125,Person,False -2,0,791.8499755859375,357.75,977.5999755859375,715.9500122070312,Person,False -3,0,631.0,127.9000015258789,779.5999755859375,416.6000061035156,Person,False -4,0,456.7200012207031,66.05000305175781,528.5999755859375,202.8000030517578,Person,True -5,0,410.29998779296875,115.30000305175781,517.25,286.79998779296875,Person,False -8,3,294.29998779296875,77.5999984741211,366.29998779296875,149.39999389648438,Person,True -9,3,728.7999877929688,117.80000305175781,815.9000244140625,363.3999938964844,Person,False -10,3,260.70001220703125,158.6300048828125,390.0299987792969,474.3999938964844,Person,False -11,3,0.10000000149011612,506.70001220703125,31.700000762939453,571.0999755859375,Person,True -12,3,183.02999877929688,142.0800018310547,281.2799987792969,409.04998779296875,Person,False -13,3,452.6000061035156,62.810001373291016,527.7000122070312,201.39999389648438,Person,True -14,3,420.8299865722656,112.41999816894531,522.5999755859375,286.29998779296875,Person,False - """) - - dataset = CSVDatasetDet( - data_file=data_csv, - ann_file=anno_csv, - pipeline=[] - ) - - assert len(dataset.data_infos) == 2 - assert len(dataset.data_infos[0]['ann']['bboxes']) == 4 # 6 - 2 (occluded) - assert len(dataset.data_infos[1]['ann']['bboxes']) == 4 # 7 - 3 (occluded) diff --git a/tests/unit/mpa/modules/datasets/test_det_incr_dataset.py b/tests/unit/mpa/modules/datasets/test_det_incr_dataset.py deleted file mode 100644 index ea2336e1..00000000 --- a/tests/unit/mpa/modules/datasets/test_det_incr_dataset.py +++ /dev/null @@ -1,30 +0,0 @@ -import pytest -from mmdet.datasets import build_dataset -from mpa.modules.datasets.det_incr_dataset import DetIncrCocoDataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_sampling_incr_coco_dataset(): - - data_cfg = dict( - type='DetIncrCocoDataset', - img_ids_dict=dict( - img_ids=[], - img_ids_old=[], - img_ids_new=[], - old_classes=['person'], - new_classes=['car'] - ), - org_type='CocoDataset', - classes=['car'], - ann_file='tests/assets/data_cfg/instances_train2017.1@0.01.json', - pipeline=[], - ) - dataset = build_dataset(data_cfg) - assert isinstance(dataset, DetIncrCocoDataset) diff --git a/tests/unit/mpa/modules/datasets/test_multi_cls_dataset.py b/tests/unit/mpa/modules/datasets/test_multi_cls_dataset.py deleted file mode 100644 index e99bb58a..00000000 --- a/tests/unit/mpa/modules/datasets/test_multi_cls_dataset.py +++ /dev/null @@ -1,80 +0,0 @@ -import unittest -import os -import pytest -import numpy as np - -from mpa.modules.datasets.multi_cls_dataset import MultiClsDataset -from mmcls.datasets import build_dataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestMultiClassDataset(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - dataset_type = 'MultiClsDataset' - img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) - pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='RandomFlip', flip_prob=0.5, direction='vertical'), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - data_prefix = os.path.join(self.assets_path, 'csvs/imgs') - self.data_file = os.path.join(self.assets_path, 'csvs/dss18.data.csv') - self.anno_file = os.path.join(self.assets_path, 'csvs/dss18.anno.multi_task.csv') - self.tasks = { - 'Gender': ["Male", "Female", "Unknown"], - 'Backpack': ['Yes', 'No'] - } - self.data_cfg = dict( - type=dataset_type, - data_prefix=data_prefix, - ann_file=self.anno_file, - data_file=self.data_file, - pipeline=pipeline, - tasks=self.tasks - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_dataset(self): - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, MultiClsDataset)) - - self.data_cfg['data_file'] = 'path/not/exist.csv' - with pytest.raises(Exception): - dataset = build_dataset(self.data_cfg) - # self.assertEqual(e.type, ValueError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset(self): - dataset = build_dataset(self.data_cfg) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_evaluate(self): - dataset = build_dataset(self.data_cfg) - dummy_res = [{'Gender': np.array([[1., 0., 0.]]), - 'Backpack': np.array([[1., 0.]])} for i in range(10)] - metrics = ['accuracy', 'precision', 'recall', 'f1_score', 'class_accuracy'] - for metric in metrics: - eval = dataset.evaluate(dummy_res, metric) - self.assertTrue(isinstance(eval, dict)) diff --git a/tests/unit/mpa/modules/datasets/test_ote_transforms.py b/tests/unit/mpa/modules/datasets/test_ote_transforms.py deleted file mode 100644 index 6bc78637..00000000 --- a/tests/unit/mpa/modules/datasets/test_ote_transforms.py +++ /dev/null @@ -1,71 +0,0 @@ -import unittest -import pytest -import torchvision -import torch -from PIL import Image - -from mpa.modules.datasets.pipelines.transforms.ote_transforms import ( - RandomRotate, PILToTensor, TensorNormalize -) - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestOTETransforms(unittest.TestCase): - def setUp(self): - self.dataset = getattr(torchvision.datasets, 'SVHN')('./data/torchvision/svhn', split='train', download=True) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_random_rotate(self): - random_rotate = RandomRotate(p=0.35, angle=(-10, 10)) - img = self.dataset[0][0] - dummy_data = { - 'img': img - } - result = random_rotate(dummy_data) - while 'RandomRotate' not in result: - result = random_rotate(dummy_data) - self.assertTrue(result['RandomRotate']) - self.assertIsInstance(result['img'], Image.Image) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_pil_to_tensor(self): - pil_to_tensor = PILToTensor() - img = self.dataset[0][0] - dummy_data = { - 'img': img - } - self.assertIsInstance(img, Image.Image) - result = pil_to_tensor(dummy_data) - self.assertIsInstance(result['img'], torch.Tensor) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_tensor_normalize(self): - __img_norm_cfg = dict(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) - tensor_normalize = TensorNormalize(**__img_norm_cfg) - img = torch.ones((3, 3, 3)) - dummy_data = { - 'img': img - } - result = tensor_normalize(dummy_data) - self.assertIsInstance(result['img'], torch.Tensor) - self.assertTrue(result['TensorNormalize']) - mean = torch.as_tensor(__img_norm_cfg['mean'], dtype=img.dtype, device=img.device) - std = torch.as_tensor(__img_norm_cfg['std'], dtype=img.dtype, device=img.device) - if mean.ndim == 1: - mean = mean.view(-1, 1, 1) - if std.ndim == 1: - std = std.view(-1, 1, 1) - expected = img.sub_(mean).div_(std) - self.assertTrue(torch.equal(result['img'], expected)) diff --git a/tests/unit/mpa/modules/datasets/test_pseudo_balanced_dataset.py b/tests/unit/mpa/modules/datasets/test_pseudo_balanced_dataset.py deleted file mode 100644 index 925caa70..00000000 --- a/tests/unit/mpa/modules/datasets/test_pseudo_balanced_dataset.py +++ /dev/null @@ -1,37 +0,0 @@ -import pytest -import os -import math -from unittest.mock import patch, MagicMock, Mock -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mmcv.utils import Config -from mpa.modules.datasets.pseudo_balanced_dataset import PseudoBalancedDataset - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_pseudo_balanced_dataset(): - cfg = Config.fromfile('tests/assets/data_cfg/coco_smallest.yaml') - cfg.data.train.org_type = cfg.data.train.type - ds = PseudoBalancedDataset( - pseudo_length=0, - **cfg.data.train, - pipeline=[] - ) - assert len(ds) == 32 - ds = PseudoBalancedDataset( - pseudo_length=-1, - **cfg.data.train, - pipeline=[] - ) - assert len(ds) == int(10*math.sqrt(float(32))) - ds = PseudoBalancedDataset( - pseudo_length=10, - **cfg.data.train, - pipeline=[] - ) - assert len(ds) == 10 - diff --git a/tests/unit/mpa/modules/datasets/test_pseudo_incr_dataset.py b/tests/unit/mpa/modules/datasets/test_pseudo_incr_dataset.py deleted file mode 100644 index e3882967..00000000 --- a/tests/unit/mpa/modules/datasets/test_pseudo_incr_dataset.py +++ /dev/null @@ -1,92 +0,0 @@ -import pytest -import os -import numpy as np - -from mmcv.parallel import DataContainer as DC - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mpa.modules.experimental.datasets.pseudo_incr_dataset import ( - PseudoIncrCocoDataset, CocoDataset, FormatPseudoLabels, LoadPseudoLabels, PseudoMinIoURandomCrop -) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_pseudo_incr_dataset(): - - org_dataset = CocoDataset( - ann_file='tests/assets/data_cfg/instances_train2017.1@0.01.json', - pipeline=[], - ) - - new_anns = [] - for idx, org_ann in enumerate(org_dataset.data_infos): - if idx % 2 == 0: - new_anns.append([[]]) - else: - new_anns.append([[np.array([ - 0.0, 1.0, 2.0, 4.0, 1.0, 1.0, 0.0 - ])]]) - - pseudo_labels = dict( - detections=new_anns, - classes=['NEW_CLASS'] - ) - - np.save('tmp.npy', pseudo_labels, allow_pickle=True) - - dataset = PseudoIncrCocoDataset( - ann_file='tests/assets/data_cfg/instances_train2017.1@0.01.json', - pipeline=[], - pre_stage_res='tmp.npy' - ) - os.remove('tmp.npy') - - assert len(dataset) == len(org_dataset) - assert len(dataset.CLASSES) == len(org_dataset.CLASSES)+1 - - -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_format_pseudo_labels(): - op = FormatPseudoLabels() - data = dict(pseudo_labels=np.zeros(1)) - data = op(data) - assert isinstance(data['pseudo_labels'], DC) - - -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_load_pseudo_labels(): - op = LoadPseudoLabels() - data = dict(ann_info=dict(pseudo_labels=np.zeros(1))) - data = op(data) - assert isinstance(data['pseudo_labels'], np.ndarray) - - -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_pseudo_min_iou_random_crop(): - op = PseudoMinIoURandomCrop() - dummy_bboxes = [] - for i in range(5): - r = np.random.randint(224) - dummy_bboxes.append(np.array([0., 0., 32., 32.])+r) - dummy_gt_labels = np.random.randint(2, size=5) - dummy_pseudo_labels = np.random.rand(5, 2) - data = dict(img=np.random.rand(256, 256, 3), - bbox_fields=['gt_bboxes_ignore', 'gt_bboxes'], - gt_bboxes=np.array(dummy_bboxes), - gt_bboxes_ignore=np.zeros((0, 4), dtype=np.float32), - gt_labels=dummy_gt_labels, - pseudo_labels=dummy_pseudo_labels - ) - res = op(data) - assert len(res['pseudo_labels']) == len(res['gt_labels']) diff --git a/tests/unit/mpa/modules/datasets/test_random_augment.py b/tests/unit/mpa/modules/datasets/test_random_augment.py deleted file mode 100644 index 6bae7081..00000000 --- a/tests/unit/mpa/modules/datasets/test_random_augment.py +++ /dev/null @@ -1,53 +0,0 @@ -import unittest -import pytest -import torchvision -import random -import numpy as np - -from mpa.modules.datasets.pipelines.transforms.random_augment import RandAugment - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestRandAugment(unittest.TestCase): - def setUp(self): - """ - setting svhn dataset for augmentation test - """ - self.dataset = getattr(torchvision.datasets, "SVHN")( - "./data/torchvision/svhn", split="train", download=True - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_random_augment(self): - """ - Verifies that RandAugment works & all augment_pool is working - """ - random.seed(1234) - np.random.seed(1234) - rand_aug = RandAugment(n=2, m=10) - img = self.dataset[0][0] - dummy_data = {"img": img} - result = rand_aug(dummy_data) - - self.assertTrue(isinstance(result, dict)) - self.assertTrue(result["CutoutAbs"]) - - rand_aug_pool = rand_aug.augment_pool - self.assertEqual(len(rand_aug_pool), 14) - pool_returned = [ - None, 0.77, 0.68, 0.86, None, None, 4, - 21, 0.32, 0.03, -0.18, 76, 6, -3 - ] - for i, aug in enumerate(rand_aug_pool): - op, max_v, bias = aug - v = np.random.randint(1, 10) - _, aug_v = op(img, v=v, max_v=max_v, bias=bias) - self.assertEqual(aug_v, pool_returned[i]) diff --git a/tests/unit/mpa/modules/datasets/test_selfsl_dataset.py b/tests/unit/mpa/modules/datasets/test_selfsl_dataset.py deleted file mode 100644 index 2cd61e9d..00000000 --- a/tests/unit/mpa/modules/datasets/test_selfsl_dataset.py +++ /dev/null @@ -1,158 +0,0 @@ -# from inspect import CORO_CREATED -import unittest -import os -import pytest -# import numpy as np -from torch import Tensor - -from mmcls.datasets import build_dataset as build_cls_dataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mpa.modules.datasets.selfsl_dataset import SelfSLDataset -from mpa.selfsl.builder import build_dataset - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSlDataset(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - self.datasource_cfgs = dict( - FashionMNIST=dict( - type='FashionMNIST', - data_prefix='data/torchvision/fmnist', - pipeline=[]), - TVDatasetSplit=dict( - type='TVDatasetSplit', - data_prefix='data/torchvision/cifar10', - base='CIFAR10', - pipeline=[], - train=True, - download=True), - CSVDatasetCls=dict( - type='CSVDatasetCls', - data_prefix=os.path.join(self.assets_path, 'csvs/imgs'), - ann_file=os.path.join(self.assets_path, 'csvs/dss18.anno.single_cls.csv'), - data_file=os.path.join(self.assets_path, 'csvs/dss18.data.csv'), - pipeline=[], - classes=["Other", "Senior", "Kids", "Unknown"]), - ) - - dataset_type = 'SelfSLDataset' - img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) - pipeline = [ - dict(type='RandomResizedCrop', size=(224, 224)), - dict(type='RandomHorizontalFlip'), - dict( - type='RandomAppliedTrans', - transforms=[ - dict( - type='ColorJitter', - brightness=0.4, - contrast=0.4, - saturation=0.2, - hue=0.1) - ], - p=0.8), - dict(type='RandomGrayscale', p=0.2), - dict( - type='RandomAppliedTrans', - transforms=[ - dict( - type='GaussianBlur', - sigma_min=0.1, - sigma_max=2.0) - ], - p=1.), - dict( - type='RandomAppliedTrans', - transforms=[dict(type='Solarization')], - p=0.), - dict(type='ToNumpy'), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='Collect', keys=['img']) - ] - - self.data_cfg = dict( - type=dataset_type, - down_task='classification', - datasource=self.datasource_cfgs['FashionMNIST'], - pipeline=dict( - view0=pipeline, - view1=pipeline - ), - ) - - self.pipeline_with_coord = [ - dict(type='RandomResizedCrop', size=(224, 224), with_coord=True), - dict(type='RandomHorizontalFlip', with_coord=True), - dict(type='ToNumpy'), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='Collect', keys=['img', 'coord']) - ] - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_dataset(self): - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, SelfSLDataset)) - - self.data_cfg['data_file'] = 'path/not/exist.csv' - with pytest.raises(Exception): - dataset = build_dataset(self.data_cfg) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset(self): - dataset = build_dataset(self.data_cfg) - cls_dataset = build_cls_dataset(self.data_cfg['datasource']) - self.assertEqual(len(dataset), len(cls_dataset)) - data = dataset[0] - self.assertNotIn('coord1', data) - self.assertNotIn('coord2', data) - self.assertIsInstance(data['img1'], Tensor) - self.assertIsInstance(data['img2'], Tensor) - self.assertEqual(data['img1'].shape, (3, 224, 224)) - self.assertEqual(data['img2'].shape, (3, 224, 224)) - - self.data_cfg['pipeline']['view0'] = self.pipeline_with_coord - self.data_cfg['pipeline']['view1'] = self.pipeline_with_coord - dataset = build_dataset(self.data_cfg) - cls_dataset = build_cls_dataset(self.data_cfg['datasource']) - self.assertEqual(len(dataset), len(cls_dataset)) - data = dataset[0] - self.assertIn('img1', data) - self.assertIn('img2', data) - self.assertIsInstance(data['coord1'], Tensor) - self.assertIsInstance(data['coord2'], Tensor) - self.assertEqual(data['coord1'].shape, (4,)) - self.assertEqual(data['coord2'].shape, (4,)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_datasource(self): - self.data_cfg['datasource'] = self.datasource_cfgs['CSVDatasetCls'] - self.data_cfg['datasource']['pipeline'] = [dict(type='ToPIL')] - self.data_cfg['pipeline']['view0'][0]['size'] = 32 # Resize - dataset = build_dataset(self.data_cfg) - self.assertTrue(len(dataset), 10) - data = dataset[0] - self.assertEqual(data['img1'].shape, (3, 32, 32)) - self.assertEqual(data['img2'].shape, (3, 32, 32)) - - self.data_cfg['datasource'] = self.datasource_cfgs['TVDatasetSplit'] - self.data_cfg['datasource']['pipeline'] = [dict(type='ImageToTensor', keys=['img'])] - dataset = build_dataset(self.data_cfg) - with pytest.raises(TypeError): - data = dataset[0] diff --git a/tests/unit/mpa/modules/datasets/test_task_adapt_dataset.py b/tests/unit/mpa/modules/datasets/test_task_adapt_dataset.py deleted file mode 100644 index 199a0ee1..00000000 --- a/tests/unit/mpa/modules/datasets/test_task_adapt_dataset.py +++ /dev/null @@ -1,51 +0,0 @@ -import pytest -import numpy as np - -from mpa.modules.datasets.task_adapt_dataset import AdaptClassLabels -from mpa.modules.datasets.task_adapt_dataset import TaskAdaptEvalDataset - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_task_adapt_eval_dataset(monkeypatch): - - dataset = TaskAdaptEvalDataset( - model_classes=('car',), - org_type='CocoDataset', - classes=('person', 'car',), - ann_file='tests/assets/data_cfg/instances_train2017.1@0.01.json', - pipeline=[], - ) - - def fake_eval(results, **kwargs): - return results - monkeypatch.setattr(dataset.dataset, 'evaluate', fake_eval) - - org_det = [[ - [np.array([1.0, 2.0, 3.0, 4.0, 1.0])] # car - ]] - gt_adapt_det = [[ - [np.empty([0, 5])], # person - [np.array([1.0, 2.0, 3.0, 4.0, 1.0])] # car - ]] - adapt_det = dataset.evaluate(org_det) - print(adapt_det) - - assert(len(adapt_det[0]) == 2) - assert((adapt_det[0][1][0] == gt_adapt_det[0][1][0]).all()) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_adapt_class_labels(): - op = AdaptClassLabels(['car', 'person'], ['person', 'bus', 'car']) - data = dict(gt_labels=[0, 1, 0, 1, 0]) - data = op(data) - assert((data['gt_labels'] == [2, 0, 2, 0, 2]).all()) diff --git a/tests/unit/mpa/modules/datasets/test_task_adapt_dataset_seg.py b/tests/unit/mpa/modules/datasets/test_task_adapt_dataset_seg.py deleted file mode 100644 index 40a739ea..00000000 --- a/tests/unit/mpa/modules/datasets/test_task_adapt_dataset_seg.py +++ /dev/null @@ -1,42 +0,0 @@ -import pytest - -from mpa.modules.datasets.task_adapt_dataset_seg import TaskAdaptDatasetSeg - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_build_task_adapt_dataset_seg(): - dataset = TaskAdaptDatasetSeg( - model_classes=['background', 'car', 'building'], - with_background=True, - org_type='CityscapesDataset', - classes=['building'], - img_dir='tests/assets/dirs/segmentation/train', - pipeline=[] - ) - - assert len(dataset) == len(dataset.dataset) - assert dataset.model_classes == dataset.dataset.CLASSES - - dataset_repeat = TaskAdaptDatasetSeg( - model_classes=['background', 'car', 'building'], - with_background=True, - org_type='RepeatDataset', - times=1, - dataset=dict( - type='CityscapesDataset', - classes=['building'], - img_dir='tests/assets/dirs/segmentation/train', - pipeline=[] - ) - ) - - assert len(dataset_repeat) == len(dataset_repeat.dataset) - assert len(dataset_repeat.dataset) == len(dataset_repeat.dataset.dataset) - assert dataset_repeat.model_classes == dataset_repeat.dataset.CLASSES - assert dataset_repeat.dataset.CLASSES == dataset_repeat.dataset.dataset.CLASSES diff --git a/tests/unit/mpa/modules/datasets/test_torchvision2mmdet.py b/tests/unit/mpa/modules/datasets/test_torchvision2mmdet.py deleted file mode 100644 index e01cd607..00000000 --- a/tests/unit/mpa/modules/datasets/test_torchvision2mmdet.py +++ /dev/null @@ -1,150 +0,0 @@ -import pytest -import os -import numpy as np -import torch -import copy -import cv2 as cv -from torchvision import transforms as T -from PIL import Image, ImageFilter -from unittest.mock import patch, MagicMock, Mock - -import mpa.modules.datasets.pipelines.torchvision2mmdet as torchvision2mmdet -from mpa.modules.datasets.pipelines.torchvision2mmdet import ( - ColorJitter, RandomGrayscale, RandomErasing, RandomGaussianBlur, RandomApply, - NDArrayToTensor, NDArrayToPILImage, PILImageToNDArray, BranchImage, -) - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_color_jitter(): - img = torch.rand(1, 3, 5, 5) - inputs = {'img': copy.deepcopy(img)} - tv_op = T.ColorJitter() - md_op = ColorJitter() - tv_output = tv_op(img) - md_output = md_op(inputs) - np.testing.assert_array_equal(tv_output, md_output['img']) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_random_gray_scale(): - img = torch.rand(1, 3, 5, 5) - inputs = {'img': copy.deepcopy(img)} - tv_op = T.RandomGrayscale(p=1.0) - md_op = RandomGrayscale(p=1.0) - tv_output = tv_op(img) - md_output = md_op(inputs) - np.testing.assert_array_equal(tv_output, md_output['img']) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_random_erasing(): - img = torch.rand(1, 3, 5, 5) - inputs = {'img': copy.deepcopy(img)} - md_op = RandomErasing(p=1.0) - md_output = md_op(inputs) - assert not np.array_equal(img, md_output['img']) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_random_gaussian_blur(): - img = np.random.rand(3, 5, 5) - img = Image.fromarray(img, mode='RGB') - inputs = {'img': copy.deepcopy(img)} - output = img.filter(ImageFilter.GaussianBlur(radius=0.1)) - md_op = RandomGaussianBlur(0.1, 0.1) - md_output = md_op(inputs) - np.testing.assert_array_equal( - np.asarray(output), - np.asarray(md_output['img']) - ) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_random_random_gaussian_blur(): - img = np.random.rand(3, 5, 5) - inputs = {'img': copy.deepcopy(img)} - img = Image.fromarray(img, mode='RGB') - inputs = {'img': copy.deepcopy(img)} - output = img.filter(ImageFilter.GaussianBlur(radius=0.1)) - md_op = RandomApply( - [dict( - type='RandomGaussianBlur', - sigma_min=0.1, - sigma_max=0.1 - )], - p=1.0 - ) - md_output = md_op(inputs) - np.testing.assert_array_equal( - np.asarray(output), - np.asarray(md_output['img']) - ) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_random_apply(): - with patch(f'{__name__}.torchvision2mmdet.T.RandomApply.__init__') as init, \ - patch(f'{__name__}.torchvision2mmdet.build_from_cfg') as build_from_cfg: - t = RandomApply([dict(), dict()], 0.5) - init.assert_called() - build_from_cfg.assert_called() - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_ndarray_to_tensor(): - data = dict(img=np.random.rand(3, 5, 5)) - op = NDArrayToTensor(['img']) - data = op(data) - assert isinstance(data['img'], torch.Tensor) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_ndarray_to_pil_image(): - data = dict(img=np.random.rand(3, 5, 5)) - op = NDArrayToPILImage(['img']) - data = op(data) - assert isinstance(data['img'], Image.Image) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_pil_image_to_ndarry(): - data = dict(img=np.random.rand(3, 5, 5)) - op = NDArrayToPILImage(['img']) - data = op(data) - op = PILImageToNDArray(['img']) - data = op(data) - assert isinstance(data['img'], np.ndarray) - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_branch_image(): - data = dict(img=np.random.rand(3, 5, 5), img_fields=['img']) - op = BranchImage(dict(img='img0')) - data = op(data) - assert 'img' in data and 'img0' in data - np.testing.assert_array_equal(data['img'], data['img0']) diff --git a/tests/unit/mpa/modules/datasets/test_tvds_split.py b/tests/unit/mpa/modules/datasets/test_tvds_split.py deleted file mode 100644 index 538856fb..00000000 --- a/tests/unit/mpa/modules/datasets/test_tvds_split.py +++ /dev/null @@ -1,161 +0,0 @@ -import os -import unittest -from unittest.mock import patch, Mock -import pytest -import numpy as np - -from torch import Tensor -from torchvision.datasets import CIFAR10 -from mmcls.datasets import build_dataset -from mpa.modules.datasets.tvds_split import TVDatasetSplit - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestTVDatasetSplit(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - dataset_type = 'TVDatasetSplit' - img_norm_cfg = dict( - mean=[129.3, 124.1, 112.4], std=[68.2, 65.4, 70.4], to_rgb=True) - self.train_pipeline = [ - dict(type='Resize', size=(224, 224)), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='ToTensor', keys=['gt_label']), - dict(type='Collect', keys=['img', 'gt_label']) - ] - self.data_cfg = dict( - type=dataset_type, - base='CIFAR10', - train=True, - pipeline=self.train_pipeline, - samples_per_gpu=16, - workers_per_gpu=4, - download=True - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_dataset(self): - dataset = build_dataset(self.data_cfg) - self.assertTrue(isinstance(dataset, TVDatasetSplit)) - - self.data_cfg['base'] = 'CIFAR1000' - with pytest.raises(Exception) as e: - dataset = build_dataset(self.data_cfg) - self.assertEqual(e.type, AttributeError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset(self): - dataset = build_dataset(self.data_cfg) - data_infos = dataset.data_infos - self.assertTrue(isinstance(data_infos, list)) - self.assertTrue(isinstance(data_infos[0], dict)) - self.assertTrue(isinstance(data_infos[0]['gt_label'], np.ndarray)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_evaluate(self): - dataset = build_dataset(self.data_cfg) - ds_len = len(dataset) - dummy_res = [np.array([[1., 0., 0.]]) for i in range(ds_len)] - metrics = ['accuracy', 'precision', 'recall', 'f1_score'] - for metric in metrics: - eval = dataset.evaluate(dummy_res, metric) - self.assertTrue(isinstance(eval, dict)) - for k, v in eval.items(): - self.assertTrue(k.startswith(metric)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_base_dataset(self): - bases = ['CIFAR10', 'CIFAR100', 'STL10', 'SVHN'] - num_images = 10 - for base in bases: - ds = TVDatasetSplit( - base, - num_images=num_images - ) - item = ds[0] - self.assertEqual(num_images, len(ds)) - self.assertTrue('img' in item) - self.assertIsInstance(item['img'], Tensor) - self.assertTrue('gt_label' in item) - self.assertIsInstance(item['gt_label'], Tensor) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_dataset_init(self): - base = Mock() - base.targets = [] - base.labels = [] - delattr(base, 'targets') - delattr(base, 'labels') - with pytest.raises(Exception) as e: - ds = TVDatasetSplit(base) - self.assertEqual(e.type, NotImplementedError) - - num_indices = 10 - baseset_len = 50000 - base = CIFAR10('data/torchvision/cifar10', download=True) - with pytest.raises(Exception) as e: - ds = TVDatasetSplit(base, include_idx=range(num_indices)) - self.assertEqual(e.type, TypeError) - - ds = TVDatasetSplit(base, include_idx=list(range(num_indices))) - self.assertEqual(len(ds), num_indices) - - # test for include_idx param - ds = TVDatasetSplit(base, include_idx=os.path.join(self.assets_path, 'indices/cifar10-7k.p')) - self.assertEqual(len(ds), 7000) - - mock_warning = Mock() - mock_logger = Mock(warning=mock_warning) - with patch('mpa.modules.datasets.tvds_split.logger', mock_logger): - ds = TVDatasetSplit(base, include_idx='path/not/exist.p') - mock_warning.assert_called() - - # test for exclude_idx param - with pytest.raises(Exception) as e: - ds = TVDatasetSplit(base, exclude_idx=range(num_indices)) - self.assertEqual(e.type, TypeError) - - ds = TVDatasetSplit(base, exclude_idx=list(range(num_indices))) - self.assertEqual(len(ds), baseset_len - num_indices) - - ds = TVDatasetSplit(base, exclude_idx=os.path.join(self.assets_path, 'indices/cifar10-7k.p')) - self.assertEqual(len(ds), baseset_len - 7000) - - mock_warning = Mock() - mock_logger = Mock(warning=mock_warning) - with patch('mpa.modules.datasets.tvds_split.logger', mock_logger): - ds = TVDatasetSplit(base, exclude_idx='path/not/exist.p') - mock_warning.assert_called() - - # test num_images param - with pytest.raises(Exception) as e: - ds = TVDatasetSplit(base, num_images=baseset_len+1) - self.assertEqual(e.type, RuntimeError) - - with pytest.raises(Exception) as e: - ds = TVDatasetSplit(base, num_images=-100) - self.assertEqual(e.type, RuntimeError) - - split_len = 100 - ds = TVDatasetSplit(base, num_images=split_len) - self.assertEqual(len(ds), split_len) - - ds = TVDatasetSplit(base, num_images=split_len, use_labels=False) - self.assertEqual(len(ds), split_len) diff --git a/tests/unit/mpa/modules/hooks/__init__.py b/tests/unit/mpa/modules/hooks/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/hooks/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/hooks/test_model_ema_v2_hook.py b/tests/unit/mpa/modules/hooks/test_model_ema_v2_hook.py deleted file mode 100644 index 4e14ad1d..00000000 --- a/tests/unit/mpa/modules/hooks/test_model_ema_v2_hook.py +++ /dev/null @@ -1,109 +0,0 @@ -import unittest -import logging -import torch -from mmcls.models.builder import build_classifier -from mmcv.runner import BaseRunner, build_optimizer -from mpa.modules.hooks.model_ema_v2_hook import ModelEmaV2Hook, ModelEmaV2 -import pytest - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -class Model(torch.nn.Module): - def __init__(self): - super().__init__() - - -class Runner(BaseRunner): - def __init__( - self, model, optimizer, max_iters=None, max_epochs=None, iters_per_epoch=3 - ): - super(Runner, self).__init__( - model, - max_iters=max_iters, - max_epochs=max_epochs, - logger=logging.getLogger(), - ) - self.iters_per_epoch = iters_per_epoch - self.model = model - self.optimizer = optimizer - - def train(self): - pass - - def val(self): - pass - - def run(self, *args, **kwargs): - self.call_hook("before_run") - - def run_epoch(self): - self.call_hook("before_train_epoch") - for i in range(self.iters_per_epoch): - self._inner_iter = i - self.run_iter() - self._epoch += 1 - self.call_hook("after_train_epoch") - - def run_iter(self): - self.call_hook("before_train_iter") - self._iter += 1 - self.call_hook("after_train_iter") - - def save_checkpoint(self, *args, **kwargs): - pass - - -@pytest.mark.components(MPAComponent.MPA) -class TestModelEMAV2Hook(unittest.TestCase): - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_model_ema_v2_hook(self): - """ - Verifies that ModelEmaV2Hook builds - """ - import mmcv - from mmcv.runner.hooks import HOOKS - - custom_hook_config = dict(type="ModelEmaV2Hook") - hook = mmcv.build_from_cfg(custom_hook_config, HOOKS) - self.assertIsInstance(hook, ModelEmaV2Hook) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_model_ema_v2(self): - """ - Verifies that ModelEmaV2Hook configs work - """ - model_cfg = dict( - type="ImageClassifier", - backbone=dict( - type="MobileNetV2", - widen_factor=1.0, - ), - neck=dict( - type="GlobalAveragePooling", - ), - head=dict( - type="LinearClsHead", - in_channels=1280, - num_classes=3, - ), - ) - optimizer_config = dict(type="SGD", lr=0.03, momentum=0.9) - model = build_classifier(model_cfg) - optimizer = build_optimizer(model, optimizer_config) - runner = Runner(model, optimizer, max_epochs=3) - - custom_hook_config = dict(type="ModelEmaV2Hook", start_epoch=1) - runner.register_hook_from_cfg(custom_hook_config) - self.assertIsInstance(runner.hooks[0], ModelEmaV2Hook) - - runner.run() - self.assertIsInstance(runner.ema_model, ModelEmaV2) - - for _ in range(2): - runner.run_epoch() diff --git a/tests/unit/mpa/modules/hooks/test_no_bias_decay_hook.py b/tests/unit/mpa/modules/hooks/test_no_bias_decay_hook.py deleted file mode 100644 index 3a31a203..00000000 --- a/tests/unit/mpa/modules/hooks/test_no_bias_decay_hook.py +++ /dev/null @@ -1,93 +0,0 @@ -import unittest -import logging -import torch -from mmcls.models.builder import build_classifier -from mmcv.runner import BaseRunner, build_optimizer -from mpa.modules.hooks.no_bias_decay_hook import NoBiasDecayHook -import pytest - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -class Model(torch.nn.Module): - def __init__(self): - super().__init__() - - -class Runner(BaseRunner): - def __init__( - self, model, optimizer, max_iters=None, max_epochs=None, iters_per_epoch=3 - ): - super(Runner, self).__init__( - model, - max_iters=max_iters, - max_epochs=max_epochs, - logger=logging.getLogger(), - ) - self.iters_per_epoch = iters_per_epoch - self.model = model - self.optimizer = optimizer - - def train(self): - pass - - def val(self): - pass - - def run(self, *args, **kwargs): - self.call_hook("before_run") - - def save_checkpoint(self, *args, **kwargs): - pass - - -@pytest.mark.components(MPAComponent.MPA) -class TestNoBiasDecayHook(unittest.TestCase): - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_no_bias_decay_hook(self): - """ - Verifies that NoBiasDecayHook builds - """ - import mmcv - from mmcv.runner.hooks import HOOKS - - custom_hook_config = dict(type="NoBiasDecayHook") - hook = mmcv.build_from_cfg(custom_hook_config, HOOKS) - self.assertIsInstance(hook, NoBiasDecayHook) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_no_bias_decay(self): - """ - Verifies that NoBiasDecayHook config & works - """ - model_cfg = dict( - type="ImageClassifier", - backbone=dict( - type="MobileNetV2", - widen_factor=1.0, - ), - neck=dict( - type="GlobalAveragePooling", - ), - head=dict( - type="LinearClsHead", - in_channels=1280, - num_classes=3, - ), - ) - optimizer_config = dict(type="SGD", lr=0.03, momentum=0.9) - model = build_classifier(model_cfg) - optimizer = build_optimizer(model, optimizer_config) - runner = Runner(model, optimizer, max_epochs=5) - - custom_hook_config = dict(type="NoBiasDecayHook") - runner.register_hook_from_cfg(custom_hook_config) - self.assertIsInstance(runner.hooks[0], NoBiasDecayHook) - - runner.run() - self.assertEqual(len(runner.optimizer.param_groups), 3) diff --git a/tests/unit/mpa/modules/hooks/test_selfsl_hook.py b/tests/unit/mpa/modules/hooks/test_selfsl_hook.py deleted file mode 100644 index 2911b5ce..00000000 --- a/tests/unit/mpa/modules/hooks/test_selfsl_hook.py +++ /dev/null @@ -1,131 +0,0 @@ -import unittest -import logging -import torch -from mmcv.runner import BaseRunner -from mpa.modules.hooks.selfsl_hook import SelfSLHook -import pytest - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -class Model(torch.nn.Module): - def __init__(self, momentum): - super().__init__() - self.num_updated = 0 - self.base_momentum = momentum - self.momentum = momentum - - def train_step(self): - pass - - def momentum_update(self): - self.num_updated += 1 - - -class Runner(BaseRunner): - def __init__(self, model, max_iters=None, max_epochs=None, iters_per_epoch=3): - super(Runner, self).__init__(model, max_iters=max_iters, max_epochs=max_epochs, logger=logging.getLogger()) - self.iters_per_epoch = iters_per_epoch - - def train(self): - pass - - def val(self): - pass - - def run(self, *args, **kwargs): - pass - - def save_checkpoint(self, *args, **kwargs): - pass - - def run_epoch(self): - self.call_hook('before_train_epoch') - for i in range(self.iters_per_epoch): - self._inner_iter = i - self.run_iter() - self._epoch += 1 - self.call_hook('after_train_epoch') - - def run_iter(self): - self.call_hook('before_train_iter') - self._iter += 1 - self.call_hook('after_train_iter') - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSLHook(unittest.TestCase): - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_hook(self): - import mmcv - from mmcv.runner.hooks import HOOKS - custom_hook_config = dict(type='SelfSLHook') - hook = mmcv.build_from_cfg(custom_hook_config, HOOKS) - self.assertIsInstance(hook, SelfSLHook) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_hook_by_iter(self): - base_momentum = 0.9 - model = Model(base_momentum) - runner = Runner(model, max_iters=4) - - custom_hook_config = dict(type='SelfSLHook') - runner.register_hook_from_cfg(custom_hook_config) - self.assertIsInstance(runner.hooks[0], SelfSLHook) - - runner.run_iter() - self.assertEqual(model.momentum, base_momentum) - - for _ in range(int(runner.max_iters/2)): - runner.run_iter() - - # 1 - ( 1- base_momentum) * (cos(pi * 1/2) + 1) / 2 - self.assertEqual(model.momentum, (1 + base_momentum)/2) - - for _ in range(int(runner.max_iters/2)): - runner.run_iter() - self.assertEqual(model.momentum, 1.0) - self.assertEqual(model.num_updated, runner.max_iters + 1) - - # both momentum and weight should be updated - old_momentum = model.momentum - runner.run_iter() - self.assertNotEqual(model.momentum, old_momentum) - self.assertEqual(model.num_updated, runner.max_iters + 2) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_hook_by_epoch(self): - base_momentum = 0.9 - model = Model(base_momentum) - runner = Runner(model, max_epochs=4) - - custom_hook_config = dict(type='SelfSLHook', by_epoch=True) - runner.register_hook_from_cfg(custom_hook_config) - self.assertIsInstance(runner.hooks[0], SelfSLHook) - - runner.run_epoch() - self.assertEqual(model.momentum, base_momentum) - - for _ in range(int(runner.max_epochs/2)): - runner.run_epoch() - - self.assertEqual(model.momentum, (1 + base_momentum)/2) - - for _ in range(int(runner.max_epochs/2)): - runner.run_epoch() - self.assertEqual(model.momentum, 1.0) - self.assertEqual(model.num_updated, (runner.max_epochs + 1) * runner.iters_per_epoch) - - # momentum should NOT be updated while weight is updated - old_momentum = model.momentum - runner.run_iter() - self.assertEqual(model.momentum, old_momentum) - self.assertEqual(model.num_updated, (runner.max_epochs + 1) * runner.iters_per_epoch + 1) diff --git a/tests/unit/mpa/modules/hooks/test_semisl_cls_hook.py b/tests/unit/mpa/modules/hooks/test_semisl_cls_hook.py deleted file mode 100644 index 2dc4083a..00000000 --- a/tests/unit/mpa/modules/hooks/test_semisl_cls_hook.py +++ /dev/null @@ -1,126 +0,0 @@ -import unittest -import logging -import torch -import math -import pytest - -from mmcls.models.builder import build_classifier -from mmcv.runner import BaseRunner, build_optimizer -from mmcv.parallel import is_module_wrapper - -from mpa.modules.hooks.semisl_cls_hook import SemiSLClsHook - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -class Model(torch.nn.Module): - def __init__(self): - super().__init__() - - -class Runner(BaseRunner): - def __init__( - self, model, optimizer, max_iters=None, max_epochs=None, iters_per_epoch=3 - ): - super(Runner, self).__init__( - model, - max_iters=max_iters, - max_epochs=max_epochs, - logger=logging.getLogger(), - ) - self.iters_per_epoch = iters_per_epoch - self.model = model - self.optimizer = optimizer - - def train(self): - pass - - def val(self): - pass - - def run(self, *args, **kwargs): - pass - - def run_epoch(self): - self.call_hook("before_train_epoch") - for i in range(self.iters_per_epoch): - self._inner_iter = i - self.run_iter() - self._epoch += 1 - self.call_hook("after_epoch") - - def run_iter(self): - self.call_hook("before_train_iter") - self._iter += 1 - self.call_hook("after_train_iter") - - def save_checkpoint(self, *args, **kwargs): - pass - - -@pytest.mark.components(MPAComponent.MPA) -class TestSemiSLClsHook(unittest.TestCase): - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_semi_sl_cls_hook(self): - """ - Verifies that SemiSLClsHook builds - """ - import mmcv - from mmcv.runner.hooks import HOOKS - - custom_hook_config = dict(type="SemiSLClsHook") - hook = mmcv.build_from_cfg(custom_hook_config, HOOKS) - self.assertIsInstance(hook, SemiSLClsHook) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_semi_sl_cls_hook(self): - """ - Verifies that SemiSLClsHook's warm-up loss working & update log_buffer - """ - model_cfg = dict( - type="SemiSLClassifier", - backbone=dict( - type="MobileNetV2", - widen_factor=1.0, - ), - neck=dict( - type="GlobalAveragePooling", - ), - head=dict( - type="SemiSLClsHead", - in_channels=1280, - num_classes=3, - ), - ) - optimizer_config = dict(type="SGD", lr=0.03, momentum=0.9) - model = build_classifier(model_cfg) - optimizer = build_optimizer(model, optimizer_config) - runner = Runner(model, optimizer, max_iters=10) - - custom_hook_config = dict(type="SemiSLClsHook") - runner.register_hook_from_cfg(custom_hook_config) - self.assertIsInstance(runner.hooks[0], SemiSLClsHook) - - if is_module_wrapper(runner.model): - head = runner.model.module.head - else: - head = runner.model.head - - mu = ( - lambda x: 0.50 - - math.cos(min(math.pi, (2 * math.pi * x) / runner.max_iters)) / 2 - ) - - for i in range(runner.max_iters): - runner.run_iter() - self.assertEqual(head.unlabeled_coef, mu(i)) - - runner.run_epoch() - self.assertTrue(isinstance(runner.log_buffer.output, dict)) - self.assertEqual(runner.log_buffer.output['unlabeled_loss'], 1.0) - self.assertIn('pseudo_label', runner.log_buffer.output) diff --git a/tests/unit/mpa/modules/hooks/test_task_adapt_hook.py b/tests/unit/mpa/modules/hooks/test_task_adapt_hook.py deleted file mode 100644 index 0acc11eb..00000000 --- a/tests/unit/mpa/modules/hooks/test_task_adapt_hook.py +++ /dev/null @@ -1,134 +0,0 @@ -import pytest -import torch -from mpa.modules.hooks import task_adapt_hook -from mpa.modules.hooks.task_adapt_hook import TaskAdaptHook - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def __test_task_adapt_hook(monkeypatch): - class Model(torch.nn.Module): - def __init__(self): - super().__init__() - teacher = torch.nn.Module() - self.teachers = [teacher] - - class Runner(object): - def __init__(self): - self.model = Model() - - runner = Runner() - - def fake_load(f, **kwargs): - return dict(state_dict=dict(a=1)) - - monkeypatch.setattr(torch, 'load', fake_load) - - cs_load_args = dict() - - def fake_cs_load(**kwargs): - cs_load_args.update(**kwargs) - - monkeypatch.setattr( - task_adapt_hook, - 'class_sensitive_copy_state_dict', - fake_cs_load - ) - - hook = TaskAdaptHook( - 'path/to/ckpt.pth', - ('person',), - ('person', 'car'), - ) - hook.before_run(runner) - assert cs_load_args['src_dict'] == dict(a=1) - assert cs_load_args['src_classes'] == ('person',) - assert cs_load_args['dst_classes'] == ('person', 'car',) - - loaded_state_dict = dict() - - def fake_load_state_dict(module, state_dict, **kwargs): - loaded_state_dict.update(state_dict) - - monkeypatch.setattr( - task_adapt_hook, - 'load_state_dict', - fake_load_state_dict - ) - - hook = TaskAdaptHook( - 'path/to/ckpt.pth', - ('person',), - ('person', 'car'), - ) - hook.before_run(runner) - assert loaded_state_dict == dict(a=1) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_task_adapt_hook(): - class Dataset(object): - def __init__(self, num_images): - self.num_images = num_images - self.img_indices = dict() - self.indice_setting() - - def indice_setting(self): - indices = list(range(self.num_images)) - self.img_indices['old'] = indices[:int(self.num_images*0.8)] - self.img_indices['new'] = indices[int(self.num_images*0.8):] - - def __len__(self): - return self.num_images - - class DataLoader(object): - def __init__( - self, dataset, batch_size, num_workers, - collate_fn=None, worker_init_fn=None - ): - self.dataset = dataset - self.batch_size = batch_size - self.num_workers = num_workers - self.collate_fn = collate_fn - self.worker_init_fn = worker_init_fn - - class Runner(object): - def __init__(self, data_loader): - self.data_loader = data_loader - - dataset = Dataset(num_images=10) # old 8 new 2 - data_loader = DataLoader(dataset, 2, 1) - - runner = Runner(data_loader) - - hook = TaskAdaptHook( - ('person',), - ('person', 'car'), - sampler_flag=True - ) - hook.before_epoch(runner) - assert len(runner.data_loader.sampler.new_indices) == 2 - assert len(runner.data_loader.sampler.old_indices) == 8 - assert len(runner.data_loader.sampler) == 10 - assert runner.data_loader.sampler.old_new_ratio == 2 - - # Efficient Mode - hook = TaskAdaptHook( - ('person',), - ('person', 'car'), - sampler_flag=True, - efficient_mode=True - ) - hook.before_epoch(runner) - assert len(runner.data_loader.sampler.new_indices) == 2 - assert len(runner.data_loader.sampler.old_indices) == 8 - assert len(runner.data_loader.sampler) == 6 - assert runner.data_loader.sampler.old_new_ratio == 1 diff --git a/tests/unit/mpa/modules/models/__init__.py b/tests/unit/mpa/modules/models/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/models/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/models/classifiers/__init__.py b/tests/unit/mpa/modules/models/classifiers/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/models/classifiers/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/models/classifiers/test_cls_inc_classifier.py b/tests/unit/mpa/modules/models/classifiers/test_cls_inc_classifier.py deleted file mode 100644 index 8698559f..00000000 --- a/tests/unit/mpa/modules/models/classifiers/test_cls_inc_classifier.py +++ /dev/null @@ -1,77 +0,0 @@ -import unittest -import pytest - -import torch - -from mpa.modules.models.classifiers.cls_incremental_classifier import ClsIncrementalClassifier -from mmcls.models.builder import build_classifier - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClsIncClassifier(unittest.TestCase): - def setUp(self): - self.in_channels = 1280 - self.num_classes = 10 - self.num_old_classes = 3 - self.model_cfg = dict( - type='ClsIncrementalClassifier', - backbone=dict( - type='MobileNetV2', - widen_factor=1.0, - ), - neck=dict( - type='GlobalAveragePooling', - ), - head=dict( - type='ClsIncrHead', - in_channels=self.in_channels, - num_classes=self.num_classes, - num_old_classes=self.num_old_classes, - distillation_loss=dict(type='LwfLoss', T=2.0, loss_weight=1.0), - ranking_loss=dict(type="TripletLoss", margin=0.3, dist_metric="cosine") - ) - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build(self): - classifier = build_classifier(self.model_cfg) - self.assertTrue(isinstance(classifier, ClsIncrementalClassifier)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_forward(self): - classifier = build_classifier(self.model_cfg) - dummy_image = torch.rand(16, 3, 224, 224) - dummy_gt = torch.randint(self.num_classes, (16,)) - dummy_soft_labels = torch.rand(16, self.num_old_classes) - dummy_center = torch.rand(16, self.in_channels) - - loss = classifier.forward_train(dummy_image, dummy_gt, soft_label=dummy_soft_labels, center=dummy_center) - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 5) - self.assertEqual(len(loss['cls_loss'].shape), 0) - self.assertEqual(len(loss['dist_loss'].shape), 0) - self.assertEqual(len(loss['center_loss'].shape), 0) - self.assertEqual(len(loss['ranking_loss'].shape), 0) - self.assertTrue(isinstance(loss['accuracy'], dict)) - self.assertEqual(len(loss['accuracy']), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_extract_prob(self): - classifier = build_classifier(self.model_cfg) - dummy_image = torch.rand(16, 3, 224, 224) - probs, feats = classifier.extract_prob(dummy_image) - self.assertEqual(len(probs), 16) - self.assertEqual(len(probs[0]), self.num_old_classes) - self.assertEqual(len(feats[0]), self.in_channels) diff --git a/tests/unit/mpa/modules/models/classifiers/test_semisl_classifier.py b/tests/unit/mpa/modules/models/classifiers/test_semisl_classifier.py deleted file mode 100644 index c7251d9c..00000000 --- a/tests/unit/mpa/modules/models/classifiers/test_semisl_classifier.py +++ /dev/null @@ -1,185 +0,0 @@ -import unittest -import pytest - -import torch - -from mmcls.models.builder import build_classifier -from mpa.modules.models.classifiers.semisl_classifier import SemiSLClassifier - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestSemiSLClassifier(unittest.TestCase): - def setUp(self): - """ - Semi-SL Classifier settings with MV2 - """ - self.in_channels = 576 - self.num_classes = 3 - self.model_cfg = dict( - type="SemiSLClassifier", - backbone=dict( - type="OTEMobileNetV3", - mode="small", - width_mult=1.0 - ), - neck=dict( - type="GlobalAveragePooling", - ), - head=dict( - type="SemiSLClsHead", - in_channels=self.in_channels, - num_classes=self.num_classes, - ), - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_semi_sl_classifier_build(self): - """ - Verifies that classifier build works - """ - classifier = build_classifier(self.model_cfg) - self.assertTrue(isinstance(classifier, SemiSLClassifier)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_semi_sl_classifier_forward(self): - """ - Verifies that the forward_train function works - """ - classifier = build_classifier(self.model_cfg) - # Labeled images - dummy_labeled_image = torch.rand(3, 3, 32, 32) - # Labeled GT - dummy_gt = torch.tensor([0, 1, 2]) - # Unlabeled images - dummy_data = { - "weak": { - "img": torch.rand(9, 3, 32, 32), - "gt_label": torch.tensor([0, 1, 2, 0, 1, 2, 0, 1, 2]), - }, - "strong": {"img": torch.rand(9, 3, 32, 32)}, - } - - loss = classifier.forward_train( - imgs=dummy_labeled_image, gt_label=dummy_gt, extra_0=dummy_data - ) - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 2) - self.assertTrue(isinstance(loss["accuracy"], dict)) - self.assertEqual(len(loss["accuracy"]), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_semi_sl_classifier_pretrained_init_weight(self): - """ - Verifies that initialization weight of backbone, neck, head - with pretrained weights - """ - cfg = self.model_cfg - cfg["pretrained"] = True - classifier = build_classifier(cfg) - # Labeled images - dummy_labeled_image = torch.rand(3, 3, 32, 32) - # Labeled GT - dummy_gt = torch.tensor([0, 1, 2]) - # Unlabeled images - dummy_data = { - "weak": { - "img": torch.rand(9, 3, 32, 32), - "gt_label": torch.tensor([0, 1, 2, 0, 1, 2, 0, 1, 2]), - }, - "strong": {"img": torch.rand(9, 3, 32, 32)}, - } - - loss = classifier.forward_train( - imgs=dummy_labeled_image, gt_label=dummy_gt, extra_0=dummy_data - ) - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 2) - self.assertTrue(isinstance(loss["accuracy"], dict)) - self.assertEqual(len(loss["accuracy"]), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_semi_sl_classifier_extract_feat(self): - """ - Verifies that classifier's extract features from the backbone + neck - """ - classifier = build_classifier(self.model_cfg) - dummy_image = torch.rand(3, 3, 32, 32) - feats = classifier.extract_feat(dummy_image) - self.assertTrue(isinstance(feats, torch.Tensor)) - self.assertEqual(len(feats), 3) - - model_cfg = dict( - type="SemiSLClassifier", - backbone=dict( - type="MobileNetV2", - widen_factor=1.0, - ), - head=dict( - type="SemiSLClsHead", - in_channels=self.in_channels, - num_classes=self.num_classes, - ), - ) - classifier = build_classifier(model_cfg) - dummy_image = torch.rand(3, 3, 32, 32) - feats = classifier.extract_feat(dummy_image) - self.assertTrue(isinstance(feats, torch.Tensor)) - self.assertEqual(len(feats), 3) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_semi_sl_classifier_simple_test(self): - """ - Verifies that classifier use simple_test function with small data - """ - classifier = build_classifier(self.model_cfg) - dummy_image = torch.rand(3, 3, 32, 32) - features = classifier.simple_test(dummy_image) - self.assertEqual(len(features), 3) - self.assertEqual(len(features[0]), self.num_classes) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_semi_sl_classifier_value_error(self): - """ - Verifies that occur ValueError in an incorrect data configuration - (without gt_label or unlabeled data) - """ - classifier = build_classifier(self.model_cfg) - # Labeled images - dummy_labeled_image = torch.rand(3, 3, 32, 32) - # Labeled GT - dummy_gt = torch.tensor([0, 1, 2]) - # Unlabeled images - dummy_data = { - "weak": { - "img": torch.rand(9, 3, 32, 32), - "gt_label": torch.tensor([0, 1, 2, 0, 1, 2, 0, 1, 2]), - }, - "strong": {"img": torch.rand(9, 3, 32, 32)}, - } - - with self.assertRaises(ValueError): - classifier.forward_train( - imgs=dummy_labeled_image, extra_0=dummy_data - ) - with self.assertRaises(ValueError): - classifier.forward_train( - imgs=dummy_labeled_image, gt_label=dummy_gt - ) diff --git a/tests/unit/mpa/modules/models/classifiers/test_task_inc_classifier.py b/tests/unit/mpa/modules/models/classifiers/test_task_inc_classifier.py deleted file mode 100644 index adf0fd64..00000000 --- a/tests/unit/mpa/modules/models/classifiers/test_task_inc_classifier.py +++ /dev/null @@ -1,95 +0,0 @@ -import unittest -import pytest - -import torch - -from mpa.modules.models.classifiers.task_incremental_classifier import TaskIncrementalLwF -from mmcls.models.builder import build_classifier - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestTaskIncClassifier(unittest.TestCase): - def setUp(self): - self.model_cfg = dict( - type='TaskIncrementalLwF', - backbone=dict( - type='MobileNetV2', - widen_factor=1.0, - ), - neck=dict( - type='GlobalAveragePooling', - ), - head=dict( - type='TaskIncLwfHead', - in_channels=1280, - tasks=dict( - Age=["Other", "Senior", "Kids", "Unknown"] - ), - old_tasks=dict( - Gender=["Male", "Female", "Unknown"], - Backpack=['Yes', 'No'] - ) - ) - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build(self): - classifier = build_classifier(self.model_cfg) - self.assertTrue(isinstance(classifier, TaskIncrementalLwF)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_forward(self): - classifier = build_classifier(self.model_cfg) - dummy_image = torch.rand(3, 3, 224, 224) - dummy_gt = torch.tensor([[0], [1], [2]]) - dummy_soft_labels = dict( - Gender=torch.rand(3, 3), - Backpack=torch.rand(3, 2) - ) - loss = classifier.forward_train(dummy_image, dummy_gt, soft_label=dummy_soft_labels) - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 3) - self.assertEqual(len(loss['new_loss'].shape), 0) - self.assertEqual(len(loss['old_loss'].shape), 0) - self.assertTrue(isinstance(loss['accuracy'], dict)) - self.assertEqual(len(loss['accuracy']), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_extract_prob(self): - model_cfg = dict( - type='TaskIncrementalLwF', - backbone=dict( - type='MobileNetV2', - widen_factor=1.0, - ), - neck=dict( - type='GlobalAveragePooling', - ), - head=dict( - type='TaskIncLwfHead', - in_channels=1280, - tasks=dict( - Gender=["Male", "Female", "Unknown"], - Backpack=['Yes', 'No'] - ) - ) - ) - classifier = build_classifier(model_cfg) - dummy_image = torch.rand(3, 3, 224, 224) - probs, _ = classifier.extract_prob(dummy_image) - self.assertTrue(isinstance(probs, dict)) - self.assertEqual(len(probs), 2) - self.assertEqual(len(probs['Gender'][0]), 3) - self.assertEqual(len(probs['Backpack'][0]), 2) diff --git a/tests/unit/mpa/modules/models/detectors/__init__.py b/tests/unit/mpa/modules/models/detectors/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/models/detectors/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/models/detectors/test_custom_atss.py b/tests/unit/mpa/modules/models/detectors/test_custom_atss.py deleted file mode 100644 index 0bdd268c..00000000 --- a/tests/unit/mpa/modules/models/detectors/test_custom_atss.py +++ /dev/null @@ -1,123 +0,0 @@ -import pytest -import torch -from mpa.modules.models.detectors.custom_atss_detector import CustomATSS - -from mmdet.models.builder import build_detector - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_atss_build(): - model_cfg = dict( - type='CustomATSS', - backbone=dict( - type='mobilenetv2_w1', - out_indices=(2, 3, 4, 5), - frozen_stages=-1, - norm_eval=False, - pretrained=True - ), - neck=dict( - type='FPN', - in_channels=[24, 32, 96, 320], - out_channels=64, - start_level=1, - add_extra_convs=True, - extra_convs_on_inputs=False, - num_outs=5, - relu_before_extra_convs=True - ), - bbox_head=dict( - type='ATSSHead', - num_classes=2, - in_channels=64, - stacked_convs=4, - feat_channels=64, - anchor_generator=dict( - type='AnchorGenerator', - ratios=[1.0], - octave_base_scale=8, - scales_per_octave=1, - strides=[8, 16, 32, 64, 128] - ), - bbox_coder=dict( - type='DeltaXYWHBBoxCoder', - target_means=[0.0, 0.0, 0.0, 0.0], - target_stds=[0.1, 0.1, 0.2, 0.2] - ), - loss_cls=dict( - type='FocalLoss', - use_sigmoid=True, - gamma=2.0, - alpha=0.25, - loss_weight=1.0 - ), - loss_bbox=dict(type='GIoULoss', loss_weight=2.0), - loss_centerness=dict( - type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0 - ) - ), - task_adapt=dict( - src_classes = ['person', 'car'], - dst_classes = ['tree', 'car', 'person'], - ), - ) - - model = build_detector(model_cfg) - assert isinstance(model, CustomATSS) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_atss_load_state_dict_pre_hook(): - chkpt_classes = ['person', 'car'] - model_classes = ['tree', 'car', 'person'] - chkpt_dict = { - 'bbox_head.atss_cls.weight': torch.tensor([ - [1, 1, 1, 1], - [2, 2, 2, 2], - ]), - 'bbox_head.atss_cls.bias': torch.tensor([ - [1], - [2], - ]), - } - model_dict = { - 'bbox_head.atss_cls.weight': torch.tensor([ - [3, 3, 3, 3], - [4, 4, 4, 4], - [5, 5, 5, 5], - ]), - 'bbox_head.atss_cls.bias': torch.tensor([ - [3], - [4], - [5], - ]), - } - gt_dict = { - 'bbox_head.atss_cls.weight': torch.tensor([ - [3, 3, 3, 3], - [2, 2, 2, 2], - [1, 1, 1, 1], - ]), - 'bbox_head.atss_cls.bias': torch.tensor([ - [3], - [2], - [1], - ]), - } - class Model: - def state_dict(self): - return model_dict - CustomATSS.load_state_dict_pre_hook( - Model(), model_classes, chkpt_classes, chkpt_dict, '' - ) - for k, gt in gt_dict.items(): - assert (chkpt_dict[k] != gt).sum() == 0 diff --git a/tests/unit/mpa/modules/models/detectors/test_custom_frcnn.py b/tests/unit/mpa/modules/models/detectors/test_custom_frcnn.py deleted file mode 100644 index 679ed943..00000000 --- a/tests/unit/mpa/modules/models/detectors/test_custom_frcnn.py +++ /dev/null @@ -1,219 +0,0 @@ -import pytest -import torch -from mpa.modules.models.detectors.custom_two_stage_detector import CustomTwoStageDetector - -from mmdet.models.builder import build_detector -from mmcv.utils import ConfigDict - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_two_stage_detector_build(): - model_cfg = ConfigDict( - type='CustomTwoStageDetector', - backbone=dict( - type='ResNet', - depth=50, - num_stages=4, - out_indices=(0, 1, 2, 3), - frozen_stages=1, - norm_cfg=dict(type='BN', requires_grad=True), - norm_eval=True, - style='pytorch'), - neck=dict( - type='FPN', - in_channels=[256, 512, 1024, 2048], - out_channels=256, - num_outs=5 - ), - rpn_head=dict( - type='RPNHead', - in_channels=256, - feat_channels=256, - anchor_generator=dict( - type='AnchorGenerator', - scales=[8], - ratios=[0.5, 1.0, 2.0], - strides=[4, 8, 16, 32, 64] - ), - bbox_coder=dict( - type='DeltaXYWHBBoxCoder', - target_means=[.0, .0, .0, .0], - target_stds=[1.0, 1.0, 1.0, 1.0] - ), - loss_cls=dict( - type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0), - loss_bbox=dict(type='L1Loss', loss_weight=1.0) - ), - roi_head=dict( - type='StandardRoIHead', - bbox_roi_extractor=dict( - type='SingleRoIExtractor', - roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0.), - out_channels=256, - featmap_strides=[4, 8, 16, 32]), - bbox_head=dict( - type='Shared2FCBBoxHead', - in_channels=256, - fc_out_channels=1024, - roi_feat_size=7, - num_classes=80, - bbox_coder=dict( - type='DeltaXYWHBBoxCoder', - target_means=[0., 0., 0., 0.], - target_stds=[0.1, 0.1, 0.2, 0.2]), - reg_class_agnostic=False, - loss_cls=dict( - type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), - loss_bbox=dict(type='L1Loss', loss_weight=1.0) - ) - ), - # model training and testing settings - train_cfg=dict( - rpn=dict( - assigner=dict( - type='MaxIoUAssigner', - pos_iou_thr=0.7, - neg_iou_thr=0.3, - min_pos_iou=0.3, - match_low_quality=True, - ignore_iof_thr=-1), - sampler=dict( - type='RandomSampler', - num=256, - pos_fraction=0.5, - neg_pos_ub=-1, - add_gt_as_proposals=False), - allowed_border=-1, - pos_weight=-1, - debug=False), - rpn_proposal=dict( - nms_across_levels=False, - nms_pre=2000, - nms_post=1000, - max_num=1000, - nms_thr=0.7, - min_bbox_size=0), - rcnn=dict( - assigner=dict( - type='MaxIoUAssigner', - pos_iou_thr=0.5, - neg_iou_thr=0.5, - min_pos_iou=0.5, - match_low_quality=False, - ignore_iof_thr=-1), - sampler=dict( - type='RandomSampler', - num=512, - pos_fraction=0.25, - neg_pos_ub=-1, - add_gt_as_proposals=True), - pos_weight=-1, - debug=False)), - test_cfg=dict( - rpn=dict( - nms_across_levels=False, - nms_pre=1000, - nms_post=1000, - max_num=1000, - nms_thr=0.7, - min_bbox_size=0), - rcnn=dict( - score_thr=0.05, - nms=dict(type='nms', iou_threshold=0.5), - max_per_img=100) - # soft-nms is also supported for rcnn testing - # e.g., nms=dict(type='soft_nms', iou_threshold=0.5, min_score=0.05) - ), - task_adapt=dict( - src_classes = ['person', 'car'], - dst_classes = ['tree', 'car', 'person'], - ), - ) - - model = build_detector(model_cfg) - assert isinstance(model, CustomTwoStageDetector) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_two_stage_detector_load_state_dict_pre_hook(): - chkpt_classes = ['person', 'car'] - model_classes = ['tree', 'car', 'person'] - chkpt_dict = { - 'roi_head.bbox_head.fc_cls.weight': torch.tensor([ - [1, 1, 1, 1], - [2, 2, 2, 2], - ]), - 'roi_head.bbox_head.fc_cls.bias': torch.tensor([ - [1], - [2], - ]), - 'roi_head.bbox_head.fc_reg.weight': torch.tensor([ - [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], - [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], - ]), - 'roi_head.bbox_head.fc_reg.bias': torch.tensor([ - [1], [1], [1], [1], - [2], [2], [2], [2], - ]), - } - model_dict = { - 'roi_head.bbox_head.fc_cls.weight': torch.tensor([ - [3, 3, 3, 3], - [4, 4, 4, 4], - [5, 5, 5, 5], - ]), - 'roi_head.bbox_head.fc_cls.bias': torch.tensor([ - [3], - [4], - [5], - ]), - 'roi_head.bbox_head.fc_reg.weight': torch.tensor([ - [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], - [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4], - [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], - ]), - 'roi_head.bbox_head.fc_reg.bias': torch.tensor([ - [3], [3], [3], [3], - [4], [4], [4], [4], - [5], [5], [5], [5], - ]), - } - gt_dict = { - 'roi_head.bbox_head.fc_cls.weight': torch.tensor([ - [3, 3, 3, 3], - [2, 2, 2, 2], - [1, 1, 1, 1], - ]), - 'roi_head.bbox_head.fc_cls.bias': torch.tensor([ - [3], - [2], - [1], - ]), - 'roi_head.bbox_head.fc_reg.weight': torch.tensor([ - [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], - [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], - [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], - ]), - 'roi_head.bbox_head.fc_reg.bias': torch.tensor([ - [3], [3], [3], [3], - [2], [2], [2], [2], - [1], [1], [1], [1], - ]), - } - class Model: - def state_dict(self): - return model_dict - CustomTwoStageDetector.load_state_dict_pre_hook( - Model(), model_classes, chkpt_classes, chkpt_dict, '' - ) - for k, gt in gt_dict.items(): - assert (chkpt_dict[k] != gt).sum() == 0 diff --git a/tests/unit/mpa/modules/models/detectors/test_custom_single_stage_detector.py b/tests/unit/mpa/modules/models/detectors/test_custom_single_stage_detector.py deleted file mode 100644 index e1606fbc..00000000 --- a/tests/unit/mpa/modules/models/detectors/test_custom_single_stage_detector.py +++ /dev/null @@ -1,161 +0,0 @@ -import pytest -import torch -from mpa.modules.models.detectors.custom_single_stage_detector import CustomSingleStageDetector - -from mmdet.models.builder import build_detector - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_single_stage_detector_build(): - image_width, image_height = (512, 512) - model_cfg = dict( - type='CustomSingleStageDetector', - backbone=dict( - type='mobilenetv2_w1', - out_indices=(4, 5), - frozen_stages=-1, - norm_eval=False, - pretrained=True - ), - neck=None, - bbox_head=dict( - type='SSDHead', - num_classes=1, - in_channels=(int(96), int(320)), - anchor_generator=dict( - type='SSDAnchorGeneratorClustered', - strides=(16, 32), - widths=[ - [image_width * x for x in - [0.015411783166343854, 0.033018232306549156, 0.04467156688464953, - 0.0610697815328886]], - [image_width * x for x in - [0.0789599954420517, 0.10113984043326349, 0.12805187473050397, 0.16198319380154758, - 0.21636496806213493]], - - ], - heights=[ - [image_height * x for x in - [0.05032631418898226, 0.10070800135152037, 0.15806180366055939, - 0.22343401646383804]], - [image_height * x for x in - [0.300881401352503, 0.393181898580379, 0.4998807213337051, 0.6386035764261081, - 0.8363451552091518]], - - ], - ), - bbox_coder=dict( - type='DeltaXYWHBBoxCoder', - target_means=(.0, .0, .0, .0), - target_stds=(0.1, 0.1, 0.2, 0.2), ), - )) - - model = build_detector(model_cfg) - assert isinstance(model, CustomSingleStageDetector) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_single_stage_detector_load_state_dict_pre_hook(): - chkpt_classes = ['person', 'car'] - model_classes = ['tree', 'car', 'person'] - chkpt_dict = { - 'bbox_head.cls_convs.0.weight': torch.tensor([ - [1, 1, 1, 1], - [2, 2, 2, 2], - [0, 0, 0, 0], # BG - [1, 1, 1, 1], - [2, 2, 2, 2], - [0, 0, 0, 0], # BG - [1, 1, 1, 1], - [2, 2, 2, 2], - [0, 0, 0, 0], # BG - ]), - 'bbox_head.cls_convs.0.bias': torch.tensor([ - [1], - [2], - [0], # BG - [1], - [2], - [0], # BG - [1], - [2], - [0], # BG - ]), - } - model_dict = { - 'bbox_head.cls_convs.0.weight': torch.tensor([ - [3, 3, 3, 3], - [4, 4, 4, 4], - [5, 5, 5, 5], - [0, 0, 0, 0], # BG - [3, 3, 3, 3], - [4, 4, 4, 4], - [5, 5, 5, 5], - [0, 0, 0, 0], # BG - [3, 3, 3, 3], - [4, 4, 4, 4], - [5, 5, 5, 5], - [0, 0, 0, 0], # BG - ]), - 'bbox_head.cls_convs.0.bias': torch.tensor([ - [3], - [4], - [5], - [0], # BG - [3], - [4], - [5], - [0], # BG - [3], - [4], - [5], - [0], # BG - ]), - } - gt_dict = { - 'bbox_head.cls_convs.0.weight': torch.tensor([ - [3, 3, 3, 3], - [2, 2, 2, 2], - [1, 1, 1, 1], - [0, 0, 0, 0], # BG - [3, 3, 3, 3], - [2, 2, 2, 2], - [1, 1, 1, 1], - [0, 0, 0, 0], # BG - [3, 3, 3, 3], - [2, 2, 2, 2], - [1, 1, 1, 1], - [0, 0, 0, 0], # BG - ]), - 'bbox_head.cls_convs.0.bias': torch.tensor([ - [3], - [2], - [1], - [0], # BG - [3], - [2], - [1], - [0], # BG - [3], - [2], - [1], - [0], # BG - ]), - } - class Model: - def state_dict(self): - return model_dict - CustomSingleStageDetector.load_state_dict_pre_hook( - Model(), model_classes, chkpt_classes, chkpt_dict, '' - ) - for k, gt in gt_dict.items(): - assert (chkpt_dict[k] != gt).sum() == 0 diff --git a/tests/unit/mpa/modules/models/detectors/test_custom_vfnet.py b/tests/unit/mpa/modules/models/detectors/test_custom_vfnet.py deleted file mode 100644 index 2687fdca..00000000 --- a/tests/unit/mpa/modules/models/detectors/test_custom_vfnet.py +++ /dev/null @@ -1,126 +0,0 @@ -import pytest -import torch -from mpa.modules.models.detectors.custom_vfnet_detector import CustomVFNet - -from mmdet.models.builder import build_detector -from mmcv.utils import ConfigDict - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_vfnet_build(): - model_cfg = ConfigDict( - type='CustomVFNet', - backbone=dict( - type='ResNet', - depth=50, - num_stages=4, - out_indices=(0, 1, 2, 3), - frozen_stages=1, - norm_cfg=dict(type='SyncBN', requires_grad=True), - norm_eval=True, - style='pytorch'), - neck=dict( - type='FPN', - in_channels=[256, 512, 1024, 2048], - out_channels=256, - start_level=1, - add_extra_convs='on_output', - num_outs=5, - relu_before_extra_convs=True), - bbox_head=dict( - type='VFNetHead', - num_classes=2, - in_channels=256, - stacked_convs=3, - feat_channels=256, - strides=[8, 16, 32, 64, 128], - center_sampling=False, - dcn_on_last_conv=False, - use_atss=True, - use_vfl=True, - loss_cls=dict( - type='VarifocalLoss', - use_sigmoid=True, - alpha=0.75, - gamma=2.0, - iou_weighted=True, - loss_weight=1.0), - loss_bbox=dict(type='GIoULoss', loss_weight=1.5), - loss_bbox_refine=dict(type='GIoULoss', loss_weight=2.0)), - train_cfg=dict( - assigner=dict(type='ATSSAssigner', topk=9), - allowed_border=-1, - pos_weight=-1, - debug=False), - test_cfg=dict( - nms_pre=1000, - min_bbox_size=0, - score_thr=0.01, - nms=dict(type='nms', iou_threshold=0.5), - max_per_img=100 - ), - task_adapt=dict( - src_classes = ['person', 'car'], - dst_classes = ['tree', 'car', 'person'], - ), - ) - - model = build_detector(model_cfg) - assert isinstance(model, CustomVFNet) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_vfnet_load_state_dict_pre_hook(): - chkpt_classes = ['person', 'car'] - model_classes = ['tree', 'car', 'person'] - chkpt_dict = { - 'bbox_head.vfnet_cls.weight': torch.tensor([ - [1, 1, 1, 1], - [2, 2, 2, 2], - ]), - 'bbox_head.vfnet_cls.bias': torch.tensor([ - [1], - [2], - ]), - } - model_dict = { - 'bbox_head.vfnet_cls.weight': torch.tensor([ - [3, 3, 3, 3], - [4, 4, 4, 4], - [5, 5, 5, 5], - ]), - 'bbox_head.vfnet_cls.bias': torch.tensor([ - [3], - [4], - [5], - ]), - } - gt_dict = { - 'bbox_head.vfnet_cls.weight': torch.tensor([ - [3, 3, 3, 3], - [2, 2, 2, 2], - [1, 1, 1, 1], - ]), - 'bbox_head.vfnet_cls.bias': torch.tensor([ - [3], - [2], - [1], - ]), - } - class Model: - def state_dict(self): - return model_dict - CustomVFNet.load_state_dict_pre_hook( - Model(), model_classes, chkpt_classes, chkpt_dict, '' - ) - for k, gt in gt_dict.items(): - assert (chkpt_dict[k] != gt).sum() == 0 diff --git a/tests/unit/mpa/modules/models/heads/__init__.py b/tests/unit/mpa/modules/models/heads/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/models/heads/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/models/heads/test_cls_inc_classifier_head.py b/tests/unit/mpa/modules/models/heads/test_cls_inc_classifier_head.py deleted file mode 100644 index 3da11503..00000000 --- a/tests/unit/mpa/modules/models/heads/test_cls_inc_classifier_head.py +++ /dev/null @@ -1,88 +0,0 @@ -import unittest -import pytest -import torch - -from mpa.modules.models.heads.cls_incremental_head import ClsIncrHead -from mmcls.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClsIncClsHead(unittest.TestCase): - def setUp(self): - self.in_channels = 1280 - self.num_classes = 10 - self.num_old_classes = 7 - self.head_cfg = dict( - type='ClsIncrHead', - in_channels=self.in_channels, - num_classes=self.num_classes, - num_old_classes=self.num_old_classes, - distillation_loss=dict(type='LwfLoss', T=2.0, loss_weight=1.0), - ranking_loss=dict(type="TripletLoss", margin=0.3, dist_metric="cosine") - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build(self): - head = build_head(self.head_cfg) - self.assertTrue(isinstance(head, ClsIncrHead)) - with self.assertRaises(TypeError): - self.head_cfg['num_old_classes'] = [1] - head = build_head(self.head_cfg) - with self.assertRaises(ValueError): - self.head_cfg['num_old_classes'] = 0 - head = build_head(self.head_cfg) - with self.assertRaises(TypeError): - self.head_cfg['num_classes'] = [1] - head = build_head(self.head_cfg) - with self.assertRaises(ValueError): - self.head_cfg['num_classes'] = 0 - head = build_head(self.head_cfg) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_forward(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(16, self.in_channels) - dummy_gt = torch.randint(self.num_classes, (16,)) - dummy_soft_labels = torch.rand(16, self.num_old_classes) - dummy_center = torch.rand(16, self.in_channels) - - loss = head.forward_train(dummy_feature, dummy_gt, dummy_soft_labels, dummy_center) - - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 5) - self.assertEqual(len(loss['cls_loss'].shape), 0) - self.assertEqual(len(loss['dist_loss'].shape), 0) - self.assertEqual(len(loss['center_loss'].shape), 0) - self.assertEqual(len(loss['ranking_loss'].shape), 0) - self.assertTrue(isinstance(loss['accuracy'], dict)) - self.assertEqual(len(loss['accuracy']), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_simple_test(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - features = head.simple_test(dummy_feature) - self.assertEqual(len(features), 3) - self.assertEqual(len(features[0]), self.num_classes) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_prob_extract(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - features = head.extract_prob(dummy_feature) - self.assertEqual(len(features), 3) - self.assertEqual(len(features[0]), self.num_old_classes) diff --git a/tests/unit/mpa/modules/models/heads/test_custom_atss_head.py b/tests/unit/mpa/modules/models/heads/test_custom_atss_head.py deleted file mode 100644 index fa4ae023..00000000 --- a/tests/unit/mpa/modules/models/heads/test_custom_atss_head.py +++ /dev/null @@ -1,49 +0,0 @@ -import pytest - -from mmdet.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mpa.modules.models.heads.custom_atss_head import CustomATSSHead - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_atss_head_build(): - image_width, image_height = 512, 512 - bbox_head = dict( - type='CustomATSSHead', - num_classes=2, - in_channels=64, - stacked_convs=4, - feat_channels=64, - anchor_generator=dict( - type='AnchorGenerator', - ratios=[1.0], - octave_base_scale=8, - scales_per_octave=1, - strides=[8, 16, 32, 64, 128] - ), - bbox_coder=dict( - type='DeltaXYWHBBoxCoder', - target_means=[0.0, 0.0, 0.0, 0.0], - target_stds=[0.1, 0.1, 0.2, 0.2] - ), - loss_cls=dict( - type='FocalLoss', - use_sigmoid=True, - gamma=2.0, - alpha=0.25, - loss_weight=1.0 - ), - loss_bbox=dict(type='GIoULoss', loss_weight=2.0), - loss_centerness=dict( - type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0 - ) - ) - head = build_head(bbox_head) - assert isinstance(head, CustomATSSHead) - diff --git a/tests/unit/mpa/modules/models/heads/test_custom_ssd_head.py b/tests/unit/mpa/modules/models/heads/test_custom_ssd_head.py deleted file mode 100644 index cd8dff6b..00000000 --- a/tests/unit/mpa/modules/models/heads/test_custom_ssd_head.py +++ /dev/null @@ -1,55 +0,0 @@ -import pytest - -from mmdet.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mpa.modules.models.heads.custom_ssd_head import CustomSSDHead - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_ssd_head_build(): - image_width, image_height = 512, 512 - bbox_head = dict( - type='CustomSSDHead', - num_classes=2, - in_channels=(int(96), int(320)), - anchor_generator=dict( - type='SSDAnchorGeneratorClustered', - strides=(16, 32), - widths=[ - [image_width * x for x in - [0.015411783166343854, 0.033018232306549156, 0.04467156688464953, - 0.0610697815328886]], - [image_width * x for x in - [0.0789599954420517, 0.10113984043326349, 0.12805187473050397, 0.16198319380154758, - 0.21636496806213493]], - - ], - heights=[ - [image_height * x for x in - [0.05032631418898226, 0.10070800135152037, 0.15806180366055939, - 0.22343401646383804]], - [image_height * x for x in - [0.300881401352503, 0.393181898580379, 0.4998807213337051, 0.6386035764261081, - 0.8363451552091518]], - - ], - ), - bbox_coder=dict( - type='DeltaXYWHBBoxCoder', - target_means=(.0, .0, .0, .0), - target_stds=(0.1, 0.1, 0.2, 0.2), ), - loss_cls=dict( - type='FocalLoss', - loss_weight=1.0, - gamma=2.0, - reduction='none', - ) - ) - head = build_head(bbox_head) - assert isinstance(head, CustomSSDHead) diff --git a/tests/unit/mpa/modules/models/heads/test_custom_vfnet_head.py b/tests/unit/mpa/modules/models/heads/test_custom_vfnet_head.py deleted file mode 100644 index 4d153023..00000000 --- a/tests/unit/mpa/modules/models/heads/test_custom_vfnet_head.py +++ /dev/null @@ -1,41 +0,0 @@ -import pytest - -from mmdet.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mpa.modules.models.heads.custom_vfnet_head import CustomVFNetHead - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_custom_vfnet_head_build(): - image_width, image_height = 512, 512 - bbox_head = dict( - type='CustomVFNetHead', - num_classes=2, - in_channels=256, - stacked_convs=3, - feat_channels=256, - strides=[8, 16, 32, 64, 128], - center_sampling=False, - dcn_on_last_conv=False, - use_atss=True, - use_vfl=True, - loss_cls=dict( - type='VarifocalLoss', - use_sigmoid=True, - alpha=0.75, - gamma=2.0, - iou_weighted=True, - loss_weight=1.0), - loss_bbox=dict(type='GIoULoss', loss_weight=1.5), - loss_bbox_refine=dict(type='GIoULoss', loss_weight=2.0), - ) - head = build_head(bbox_head) - assert isinstance(head, CustomVFNetHead) - - diff --git a/tests/unit/mpa/modules/models/heads/test_lwf_bbox_head.py b/tests/unit/mpa/modules/models/heads/test_lwf_bbox_head.py deleted file mode 100644 index b552a3c6..00000000 --- a/tests/unit/mpa/modules/models/heads/test_lwf_bbox_head.py +++ /dev/null @@ -1,61 +0,0 @@ -import pytest - -from mmdet.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mpa.modules.experimental.models.heads.lwf_bbox_head import OffLwfSSDHead - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_off_lwf_bbox_head(): - image_width, image_height = 512, 512 - org_model_classes = ['person'] - model_classes = ['person', 'car'] - bbox_head = dict( - type='OffLwfSSDHead', - num_classes=2, - in_channels=(int(96), int(320)), - anchor_generator=dict( - type='SSDAnchorGeneratorClustered', - strides=(16, 32), - widths=[ - [image_width * x for x in - [0.015411783166343854, 0.033018232306549156, 0.04467156688464953, - 0.0610697815328886]], - [image_width * x for x in - [0.0789599954420517, 0.10113984043326349, 0.12805187473050397, 0.16198319380154758, - 0.21636496806213493]], - - ], - heights=[ - [image_height * x for x in - [0.05032631418898226, 0.10070800135152037, 0.15806180366055939, - 0.22343401646383804]], - [image_height * x for x in - [0.300881401352503, 0.393181898580379, 0.4998807213337051, 0.6386035764261081, - 0.8363451552091518]], - - ], - ), - bbox_coder=dict( - type='DeltaXYWHBBoxCoder', - target_means=(.0, .0, .0, .0), - target_stds=(0.1, 0.1, 0.2, 0.2), ), - loss_cls_lwf=dict( - type='LwFLoss', - src_classes=org_model_classes, - dst_classes=model_classes, - bg_aware=True, - temperature=2.0, - loss_weight=1.0 - ), - src_classes=org_model_classes, - dst_classes=model_classes - ) - head = build_head(bbox_head) - assert isinstance(head, OffLwfSSDHead) diff --git a/tests/unit/mpa/modules/models/heads/test_multi_classifier_head.py b/tests/unit/mpa/modules/models/heads/test_multi_classifier_head.py deleted file mode 100644 index dbc471bc..00000000 --- a/tests/unit/mpa/modules/models/heads/test_multi_classifier_head.py +++ /dev/null @@ -1,65 +0,0 @@ -import unittest -import pytest -import torch - -from mpa.modules.models.heads.multi_classifier_head import MultiClsHead -from mmcls.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestMultiClsHead(unittest.TestCase): - def setUp(self): - self.in_channels = 500 - self.head_cfg = dict( - type='MultiClsHead', - in_channels=self.in_channels, - tasks=dict( - Gender=["Male", "Female", "Unknown"], - Backpack=['Yes', 'No'] - ) - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build(self): - head = build_head(self.head_cfg) - self.assertTrue(isinstance(head, MultiClsHead)) - with self.assertRaises(TypeError): - self.head_cfg['tasks'] = 1 - head = build_head(self.head_cfg) - with self.assertRaises(ValueError): - self.head_cfg['tasks'] = dict() - head = build_head(self.head_cfg) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_forward(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - dummy_gt = torch.tensor([[0, 0], [1, 1], [2, 0]]) - loss = head.forward_train(dummy_feature, dummy_gt) - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 2) - self.assertEqual(len(loss['loss'].shape), 0) - self.assertTrue(isinstance(loss['accuracy'], dict)) - self.assertEqual(len(loss['accuracy']), 2) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_simple_test(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - features = head.simple_test(dummy_feature) - self.assertTrue(isinstance(features, dict)) - self.assertEqual(len(features), 2) - self.assertEqual(len(features['Gender'][0]), 3) - self.assertEqual(len(features['Backpack'][0]), 2) diff --git a/tests/unit/mpa/modules/models/heads/test_selfsl_head.py b/tests/unit/mpa/modules/models/heads/test_selfsl_head.py deleted file mode 100644 index 0f978516..00000000 --- a/tests/unit/mpa/modules/models/heads/test_selfsl_head.py +++ /dev/null @@ -1,68 +0,0 @@ -import unittest -import torch - -from mpa.selfsl.builder import build_head -from mpa.modules.models.heads.selfsl_head import LatentPredictHead -import pytest - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSLHead(unittest.TestCase): - def setUp(self): - self.mlp_head_cfg = dict( - type='LatentPredictHead', - loss='MSE', - predictor=dict( - type='MLP', - in_channels=128, - hid_channels=256, - out_channels=128, - with_avg_pool=False - ) - ) - self.ppm_head_cfg = dict( - type='LatentPredictHead', - loss='PPC', - predictor=dict( - type='PPM', - sharpness=2, - ) - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_head_MLP(self): - head = build_head(self.mlp_head_cfg) - self.assertIsInstance(head, LatentPredictHead) - online = torch.rand([3, 128]) - target = torch.rand([3, 128]) - loss = head(online, target) - self.assertIsInstance(loss, dict) - self.assertTrue(loss['loss'] >= 0 and loss['loss'] <= 4) - - self.mlp_head_cfg['size_average'] = False - head = build_head(self.mlp_head_cfg) - loss = head(online, target) - - self.assertIsInstance(loss, dict) - self.assertTrue(loss['loss'] >= 0 and loss['loss'] <= 4*online.size(0)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_head_PPM(self): - head = build_head(self.ppm_head_cfg) - self.assertIsInstance(head, LatentPredictHead) - online = torch.rand([3, 256, 7, 7]) - target = torch.rand([3, 256, 7, 7]) - coord_q = torch.rand([3, 4]) - coord_k = torch.rand([3, 4]) - loss = head(online, target, coord_q, coord_k) - self.assertIsInstance(loss, dict) diff --git a/tests/unit/mpa/modules/models/heads/test_semisl_cls_head.py b/tests/unit/mpa/modules/models/heads/test_semisl_cls_head.py deleted file mode 100644 index f351714a..00000000 --- a/tests/unit/mpa/modules/models/heads/test_semisl_cls_head.py +++ /dev/null @@ -1,130 +0,0 @@ -import unittest -import pytest -import torch - -from mpa.modules.models.heads.semisl_cls_head import SemiSLClsHead -from mmcls.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestSemiSLClsHead(unittest.TestCase): - def setUp(self): - """ - Semi-SL for Classification Head Settings - """ - self.in_channels = 1280 - self.num_classes = 10 - self.head_cfg = dict( - type="SemiSLClsHead", - in_channels=self.in_channels, - num_classes=self.num_classes, - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_semisl_cls_head(self): - """ - Verifies that SemiSLClsHead builds - """ - head = build_head(self.head_cfg) - self.assertTrue(isinstance(head, SemiSLClsHead)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_semisl_cls_head_type_error(self): - """ - Verifies that SemiSLClsHead parameters check with TypeError - """ - with self.assertRaises(TypeError): - self.head_cfg["num_classes"] = [1] - build_head(self.head_cfg) - with self.assertRaises(TypeError): - self.head_cfg["in_channels"] = [1] - build_head(self.head_cfg) - with self.assertRaises(TypeError): - self.head_cfg["loss"] = [1] - build_head(self.head_cfg) - with self.assertRaises(TypeError): - self.head_cfg["topk"] = [1] - build_head(self.head_cfg) - with self.assertRaises(TypeError): - self.head_cfg["unlabeled_coef"] = [1] - build_head(self.head_cfg) - with self.assertRaises(TypeError): - self.head_cfg["min_threshold"] = [1] - build_head(self.head_cfg) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_semisl_cls_head_value_error(self): - """ - Verifies that SemiSLClsHead parameters check with ValueError - """ - with self.assertRaises(ValueError): - self.head_cfg["num_classes"] = 0 - build_head(self.head_cfg) - with self.assertRaises(ValueError): - self.head_cfg["num_classes"] = -1 - build_head(self.head_cfg) - with self.assertRaises(ValueError): - self.head_cfg["in_channels"] = 0 - build_head(self.head_cfg) - with self.assertRaises(ValueError): - self.head_cfg["in_channels"] = -1 - build_head(self.head_cfg) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_forward(self): - """ - Verifies that SemiSLClsHead forward function works - """ - head = build_head(self.head_cfg) - labeled_batch_size = 16 - unlabeled_batch_size = 64 - - dummy_gt = torch.randint(self.num_classes, (labeled_batch_size,)) - dummy_data = { - "labeled": torch.rand(labeled_batch_size, self.in_channels), - "unlabeled_weak": torch.rand(unlabeled_batch_size, self.in_channels), - "unlabeled_strong": torch.rand(unlabeled_batch_size, self.in_channels), - } - - loss = head.forward_train(dummy_data, dummy_gt) - - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 2) - self.assertTrue(isinstance(loss["accuracy"], dict)) - self.assertEqual(len(loss["accuracy"]), 2) - - # No Unlabeled Data - dummy_feature = torch.rand(labeled_batch_size, self.in_channels) - loss = head.forward_train(dummy_feature, dummy_gt) - - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 2) - self.assertTrue(isinstance(loss["accuracy"], dict)) - self.assertEqual(len(loss["accuracy"]), 2) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_simple_test(self): - """ - Verifies that SemiSLClsHead simple_test function works - """ - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - features = head.simple_test(dummy_feature) - self.assertEqual(len(features), 3) - self.assertEqual(len(features[0]), self.num_classes) diff --git a/tests/unit/mpa/modules/models/heads/test_task_inc_classifier_head.py b/tests/unit/mpa/modules/models/heads/test_task_inc_classifier_head.py deleted file mode 100644 index 00c43bfc..00000000 --- a/tests/unit/mpa/modules/models/heads/test_task_inc_classifier_head.py +++ /dev/null @@ -1,86 +0,0 @@ -import unittest -import pytest -import torch - -from mpa.modules.models.heads.task_incremental_classifier_head import TaskIncLwfHead -from mmcls.models.builder import build_head - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestTaskIncClsHead(unittest.TestCase): - def setUp(self): - self.in_channels = 500 - self.head_cfg = dict( - type='TaskIncLwfHead', - in_channels=self.in_channels, - tasks=dict( - Age=["Other", "Senior", "Kids", "Unknown"] - ), - old_tasks=dict( - Gender=["Male", "Female", "Unknown"], - Backpack=['Yes', 'No'] - ) - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build(self): - head = build_head(self.head_cfg) - self.assertTrue(isinstance(head, TaskIncLwfHead)) - with self.assertRaises(TypeError): - self.head_cfg['old_tasks'] = 1 - head = build_head(self.head_cfg) - with self.assertRaises(ValueError): - self.head_cfg['old_tasks'] = dict() - head = build_head(self.head_cfg) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_forward(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - dummy_gt = torch.tensor([[0], [1], [2]]) - dummy_soft_labels = dict( - Gender=torch.rand(3, 3), - Backpack=torch.rand(3, 2) - ) - loss = head.forward_train(dummy_feature, dummy_gt, dummy_soft_labels) - self.assertTrue(isinstance(loss, dict)) - self.assertEqual(len(loss), 3) - self.assertEqual(len(loss['new_loss'].shape), 0) - self.assertEqual(len(loss['old_loss'].shape), 0) - self.assertTrue(isinstance(loss['accuracy'], dict)) - self.assertEqual(len(loss['accuracy']), 1) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_simple_test(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - features = head.simple_test(dummy_feature) - self.assertTrue(isinstance(features, dict)) - self.assertEqual(len(features), 3) - self.assertEqual(len(features['Age'][0]), 4) - self.assertEqual(len(features['Gender'][0]), 3) - self.assertEqual(len(features['Backpack'][0]), 2) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_prob_extract(self): - head = build_head(self.head_cfg) - dummy_feature = torch.rand(3, self.in_channels) - features = head.extract_prob(dummy_feature) - self.assertTrue(isinstance(features, dict)) - self.assertEqual(len(features), 3) - self.assertEqual(len(features['Gender'][0]), 3) - self.assertEqual(len(features['Backpack'][0]), 2) diff --git a/tests/unit/mpa/modules/models/losses/__init__.py b/tests/unit/mpa/modules/models/losses/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/models/losses/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/models/losses/test distllation_losses.py b/tests/unit/mpa/modules/models/losses/test distllation_losses.py deleted file mode 100644 index bd72a3dc..00000000 --- a/tests/unit/mpa/modules/models/losses/test distllation_losses.py +++ /dev/null @@ -1,34 +0,0 @@ -import unittest -import pytest - -import torch - -from mpa.modules.models.losses.distillation_losses import LwfLoss -from mmcls.models.builder import build_loss - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestDistillationLoss(unittest.TestCase): - def setUp(self): - self.loss_cfg = dict( - type='LwfLoss', - loss_weight=1.0 - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_loss(self): - compute_loss = build_loss(self.loss_cfg) - self.assertTrue(isinstance(compute_loss, LwfLoss)) - dummy_score = torch.rand(4, 3) - dummy_gt = torch.rand(4, 3) - loss = compute_loss(dummy_score, dummy_gt) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) diff --git a/tests/unit/mpa/modules/models/losses/test_class_balanced_losses.py b/tests/unit/mpa/modules/models/losses/test_class_balanced_losses.py deleted file mode 100644 index 845f837a..00000000 --- a/tests/unit/mpa/modules/models/losses/test_class_balanced_losses.py +++ /dev/null @@ -1,69 +0,0 @@ -import unittest -import pytest - -import torch - -from mpa.modules.models.losses.class_balanced_losses import SoftmaxFocalLoss, SoftmaxPolarityLoss -from mmcls.models.builder import build_loss - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestClassBalancedLosses(unittest.TestCase): - def setUp(self): - self.focal_loss_cfg = dict( - type='SoftmaxFocalLoss', - loss_weight=1.0 - ) - self.polarity_loss_cfg = dict( - type='SoftmaxPolarityLoss', - loss_weight=1.0 - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_loss(self): - compute_focal_loss = build_loss(self.focal_loss_cfg) - self.assertTrue(isinstance(compute_focal_loss, SoftmaxFocalLoss)) - dummy_score = torch.rand(4, 3) - dummy_gt = torch.tensor([0, 1, 2, 1]) - loss = compute_focal_loss(dummy_score, dummy_gt) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) - - compute_polarity_loss = build_loss(self.polarity_loss_cfg) - self.assertTrue(isinstance(compute_polarity_loss, SoftmaxPolarityLoss)) - loss = compute_focal_loss(dummy_score, dummy_gt) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) - - # ignore index - focal_loss_cfg = dict( - type='SoftmaxFocalLoss', - loss_weight=1.0, - ignore_index=2 - ) - compute_focal_loss = build_loss(focal_loss_cfg) - dummy_score = torch.rand(4, 3) - dummy_gt = torch.tensor([0, 1, 2, 1]) - loss = compute_focal_loss(dummy_score, dummy_gt) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) - - polarity_loss_cfg = dict( - type='SoftmaxPolarityLoss', - loss_weight=1.0, - ignore_index=2 - ) - compute_polarity_loss = build_loss(polarity_loss_cfg) - dummy_score = torch.rand(4, 3) - dummy_gt = torch.tensor([0, 1, 2, 1]) - loss = compute_polarity_loss(dummy_score, dummy_gt) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) diff --git a/tests/unit/mpa/modules/models/losses/test_cross_entropy_loss.py b/tests/unit/mpa/modules/models/losses/test_cross_entropy_loss.py deleted file mode 100644 index 2957d27d..00000000 --- a/tests/unit/mpa/modules/models/losses/test_cross_entropy_loss.py +++ /dev/null @@ -1,59 +0,0 @@ -import unittest -import pytest - -import torch - -from mpa.modules.models.losses.cross_entropy_loss import CrossEntropyLossWithIgnore, WeightedCrossEntropyLoss -from mmcls.models.builder import build_loss - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestCrossEntropyLosses(unittest.TestCase): - def setUp(self): - self.loss_cfg_compare = {"type": "CrossEntropyLoss", "loss_weight": 1.0} - self.compute_loss_compare = build_loss(self.loss_cfg_compare) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_ce_w_ignore_loss(self): - self.loss_cfg = {"type": "CrossEntropyLossWithIgnore", "loss_weight": 1.0, "ignore_index": -1} - compute_loss = build_loss(self.loss_cfg) - self.assertTrue(isinstance(compute_loss, CrossEntropyLossWithIgnore)) - dummy_score = torch.rand(4, 3) - dummy_gt = torch.tensor([0, 1, 2, -1]) - loss = compute_loss(dummy_score, dummy_gt) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) - - dummy_score = dummy_score[0:3] - dummy_gt = dummy_gt[0:3] - loss_compare = self.compute_loss_compare(dummy_score, dummy_gt) - self.assertAlmostEqual(loss.cpu().numpy() * 4 / 3, loss_compare.cpu().numpy(), 3) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_weighted_ce_loss(self): - self.loss_cfg = {"type": "WeightedCrossEntropyLoss", "loss_weight": 1.0, "class_weight": [0.0, 1, 1]} - compute_loss = build_loss(self.loss_cfg) - self.assertTrue(isinstance(compute_loss, WeightedCrossEntropyLoss)) - dummy_score = torch.rand(4, 3) - dummy_gt = torch.tensor([1, 1, 2, 0]) - if torch.cuda.is_available(): - dummy_score = dummy_score.cuda() - dummy_gt = dummy_gt.cuda() - loss = compute_loss(dummy_score, dummy_gt) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) - - dummy_score = dummy_score[0:3] - dummy_gt = dummy_gt[0:3] - loss_compare = self.compute_loss_compare(dummy_score, dummy_gt) - self.assertAlmostEqual(loss.cpu().numpy() * 4 / 3, loss_compare.cpu().numpy(), 3) diff --git a/tests/unit/mpa/modules/models/losses/test_recall_loss.py b/tests/unit/mpa/modules/models/losses/test_recall_loss.py deleted file mode 100644 index caa0fc4d..00000000 --- a/tests/unit/mpa/modules/models/losses/test_recall_loss.py +++ /dev/null @@ -1,33 +0,0 @@ -import pytest -import torch - -from mpa.modules.models.losses.recall_loss import RecallLoss - -from mmseg.models.builder import build_loss - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_recall_loss(): - loss_cfg = dict( - type='RecallLoss', - loss_jitter_prob=0.01, - loss_weight=1.0 - ) - - recall_loss = build_loss(loss_cfg) - - assert isinstance(recall_loss, RecallLoss) - assert recall_loss.name == 'recall_loss' - - cls_score = torch.randn((1, 4, 32, 32)) - label = torch.randint(low=0, high=4, size=(1, 32, 32)).long() - - loss, _ = recall_loss._calculate(cls_score, label, 1.) - - assert loss.shape == label.shape diff --git a/tests/unit/mpa/modules/models/losses/test_triplet_loss.py b/tests/unit/mpa/modules/models/losses/test_triplet_loss.py deleted file mode 100644 index f0b9680c..00000000 --- a/tests/unit/mpa/modules/models/losses/test_triplet_loss.py +++ /dev/null @@ -1,31 +0,0 @@ -import unittest -import pytest - -import torch - -from mpa.modules.models.losses.triplet_loss import TripletLoss -from mmcls.models.builder import build_loss - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestTripletLoss(unittest.TestCase): - def setUp(self): - self.loss_cfg = {"type": "TripletLoss", "margin": 0.3, "dist_metric": "cosine"} - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_loss(self): - compute_loss = build_loss(self.loss_cfg) - self.assertTrue(isinstance(compute_loss, TripletLoss)) - dummy_features = torch.rand(8, 128) - dummy_gts = torch.tensor([0, 1, 0, 1, 0, 1, 0, 1]) - loss = compute_loss(dummy_features, dummy_gts) - self.assertTrue(torch.is_tensor(loss)) - self.assertEqual(len(loss.shape), 0) diff --git a/tests/unit/mpa/modules/models/necks/__init__.py b/tests/unit/mpa/modules/models/necks/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/models/necks/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/models/necks/test_selfsl_neck.py b/tests/unit/mpa/modules/models/necks/test_selfsl_neck.py deleted file mode 100644 index 1a447c97..00000000 --- a/tests/unit/mpa/modules/models/necks/test_selfsl_neck.py +++ /dev/null @@ -1,64 +0,0 @@ -import unittest -import pytest -import torch -from mpa.selfsl.builder import build_neck -from mpa.modules.models.necks.selfsl_neck import MLP, PPM - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSLNeck(unittest.TestCase): - def setUp(self): - self.mlp_neck_cfg = dict( - type='MLP', - in_channels=2048, - hid_channels=256, - out_channels=128, - norm_cfg=dict(type='BN1d'), - use_conv=False, - with_avg_pool=True - ) - self.ppm_neck_cfg = dict( - type='PPM', - sharpness=2 - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_neck_MLP(self): - neck = build_neck(self.mlp_neck_cfg) - self.assertIsInstance(neck, MLP) - - input = torch.rand([3, 2048, 7, 7]) - out = neck(input) - self.assertIsInstance(out, torch.Tensor) - self.assertEqual(out.shape, (3, self.mlp_neck_cfg['out_channels'])) - - with pytest.raises(TypeError): - out = neck(input.numpy()) - - self.mlp_neck_cfg['with_avg_pool'] = False - neck = build_neck(self.mlp_neck_cfg) - with pytest.raises(RuntimeError): - out = neck(input) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_neck_PPM(self): - neck = build_neck(self.ppm_neck_cfg) - self.assertIsInstance(neck, PPM) - - input = torch.rand([3, 256, 7, 7]) - out = neck(input) - self.assertIsInstance(out, torch.Tensor) - self.assertEqual(out.shape, input.shape) - - with pytest.raises(TypeError): - out = neck(input.numpy()) diff --git a/tests/unit/mpa/modules/models/segmentors/__init__.py b/tests/unit/mpa/modules/models/segmentors/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/models/segmentors/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/models/segmentors/test_class_incr_segmentor.py b/tests/unit/mpa/modules/models/segmentors/test_class_incr_segmentor.py deleted file mode 100644 index 39f64d1c..00000000 --- a/tests/unit/mpa/modules/models/segmentors/test_class_incr_segmentor.py +++ /dev/null @@ -1,196 +0,0 @@ -import pytest -import torch -from mpa.modules.models.segmentors.class_incr_segmentor import ClassIncrSegmentor - -from mmseg.models.builder import build_segmentor - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_class_incr_segmentor_build(): - model_cfg = dict( - type='ClassIncrSegmentor', - pretrained=None, - is_task_adapt=True, - task_adapt=dict( - src_classes=['background', 'car'], - dst_classes=['background', 'car', 'building']), - num_stages=2, - backbone=dict( - type='LiteHRNet', - norm_cfg=dict(type='BN', requires_grad=True), - norm_eval=False, - extra=dict( - stem=dict( - stem_channels=32, - out_channels=32, - expand_ratio=1, - strides=(2, 2), - extra_stride=False, - input_norm=False, - ), - num_stages=3, - stages_spec=dict( - num_modules=(2, 4, 2), - num_branches=(2, 3, 4), - num_blocks=(2, 2, 2), - module_type=('LITE', 'LITE', 'LITE'), - with_fuse=(True, True, True), - reduce_ratios=(8, 8, 8), - num_channels=( - (40, 80), - (40, 80, 160), - (40, 80, 160, 320), - ) - ), - out_modules=dict( - conv=dict( - enable=False, - channels=320 - ), - position_att=dict( - enable=False, - key_channels=128, - value_channels=320, - psp_size=(1, 3, 6, 8), - ), - local_att=dict( - enable=False - ) - ), - out_aggregator=dict( - enable=True - ), - add_input=False - ) - ), - decode_head=[ - dict(type='FCNHead', - in_channels=40, - in_index=0, - channels=40, - input_transform=None, - kernel_size=1, - num_convs=0, - concat_input=False, - dropout_ratio=-1, - num_classes=19, - norm_cfg=dict(type='BN', requires_grad=True), - align_corners=False, - enable_out_norm=False, - loss_decode=[ - dict(type='RecallLoss', - loss_jitter_prob=0.01, - sampler=dict(type='OHEMPixelSampler', thresh=0.7, min_kept=100000), - loss_weight=1.0) - ]), - dict(type='OCRHead', - in_channels=40, - in_index=0, - channels=40, - ocr_channels=40, - sep_conv=True, - input_transform=None, - dropout_ratio=-1, - num_classes=19, - norm_cfg=dict(type='BN', requires_grad=True), - align_corners=False, - enable_out_norm=True, - loss_decode=[ - dict(type='AMSoftmaxLoss', - scale_cfg=dict( - type='PolyScalarScheduler', - start_scale=30, - end_scale=5, - by_epoch=True, - num_iters=250, - power=1.2 - ), - margin_type='cos', - margin=0.5, - gamma=0.0, - t=1.0, - target_loss='ce', - pr_product=False, - conf_penalty_weight=dict( - type='PolyScalarScheduler', - start_scale=0.2, - end_scale=0.15, - by_epoch=True, - num_iters=200, - power=1.2 - ), - loss_jitter_prob=0.01, - border_reweighting=False, - sampler=dict(type='MaxPoolingPixelSampler', ratio=0.25, p=1.7), - loss_weight=1.0) - ]) - ] - ) - - model = build_segmentor(model_cfg) - model_cfg.update({'is_task_adapt': False}) - model_no_TA = build_segmentor(model_cfg) - - assert isinstance(model, ClassIncrSegmentor) - assert isinstance(model_no_TA, ClassIncrSegmentor) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_class_incr_segmentor_load_state_dict_pre_hook(): - chkpt_classes = ['person', 'car'] - model_classes = ['tree', 'car', 'person'] - - chkpt_dict = { - 'decode_head.0.conv_seg.weight': torch.tensor([ - [1, 1, 1, 1], - [2, 2, 2, 2], - ]), - 'decode_head.0.conv_seg.bias': torch.tensor([ - [1], - [2], - ]), - } - model_dict = { - 'decode_head.0.conv_seg.weight': torch.tensor([ - [3, 3, 3, 3], - [4, 4, 4, 4], - [5, 5, 5, 5], - ]), - 'decode_head.0.conv_seg.bias': torch.tensor([ - [3], - [4], - [5], - ]), - } - gt_dict = { - 'decode_head.0.conv_seg.weight': torch.tensor([ - [3, 3, 3, 3], - [2, 2, 2, 2], - [1, 1, 1, 1], - ]), - 'decode_head.0.conv_seg.bias': torch.tensor([ - [3], - [2], - [1], - ]), - } - - class Model: - def state_dict(self): - return model_dict - - ClassIncrSegmentor.load_state_dict_pre_hook( - Model(), model_classes, chkpt_classes, chkpt_dict, '' - ) - - for k, gt in gt_dict.items(): - assert (chkpt_dict[k] != gt).sum() == 0 diff --git a/tests/unit/mpa/modules/models/test_selfsl_model.py b/tests/unit/mpa/modules/models/test_selfsl_model.py deleted file mode 100644 index edae7427..00000000 --- a/tests/unit/mpa/modules/models/test_selfsl_model.py +++ /dev/null @@ -1,64 +0,0 @@ -import unittest -import pytest -import torch -# from mmcls.models import BACKBONES -from mpa.selfsl.builder import build_trainer -from mpa.modules.models.selfsl_model import SelfSL - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSL(unittest.TestCase): - def setUp(self): - self.model_cfg = dict( - type='SelfSL', - down_task='classification', - pretrained='torchvision://resnet50', - backbone=dict( - type='ResNet', - depth=50, - ), - neck=dict( - type='MLP', - in_channels=2048, - hid_channels=256, - out_channels=128, - with_avg_pool=True - ), - head=dict( - type='LatentPredictHead', - loss='MSE', - size_average=True, - predictor=dict( - type='MLP', - in_channels=128, - hid_channels=256, - out_channels=128, - with_avg_pool=False - ) - ) - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build(self): - trainer = build_trainer(self.model_cfg) - self.assertTrue(isinstance(trainer, SelfSL)) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_forward(self): - trainer = build_trainer(self.model_cfg) - dummy_image = torch.rand(4, 3, 112, 112) - loss = trainer.train_step(dict(img1=dummy_image, img2=dummy_image), None) - self.assertIsInstance(loss, dict) - self.assertEqual(len(loss), 3) - self.assertIn('loss', loss) - self.assertEqual(len(loss['loss'].shape), 0) diff --git a/tests/unit/mpa/modules/utils/__init__.py b/tests/unit/mpa/modules/utils/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/modules/utils/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/modules/utils/test_mda.py b/tests/unit/mpa/modules/utils/test_mda.py deleted file mode 100644 index b97f58e0..00000000 --- a/tests/unit/mpa/modules/utils/test_mda.py +++ /dev/null @@ -1,209 +0,0 @@ -import os -# import unittest -import pytest -import shutil -from mmcv import Config -from mda import MDA - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - -from mpa.utils.mda_stage import MdaRunner -from mpa.utils import mda_stage -from mpa.utils.config_utils import MPAConfig - -OUTPUT_PATH = '_mpa_unittest' - - -def make_sample_recipe(task='classification', mda_metric='z-score'): - if task == "detection": - config_file = 'recipes_old/detection/domain_adapt/faster_rcnn/finetune/train.yaml' - else: - config_file = 'recipes_old/classification/domain_adapt/finetune/train.yaml' - - cfg = { - 'name': 'finetune', - 'task': task, - 'mode': 'train', - 'config': config_file, - 'mda_metric': mda_metric, - 'output': ['final_score'], - 'common_cfg': {'output_path': OUTPUT_PATH} - } - - return Config(cfg) - - -def mock_function(*args, **kwargs): - return 1 - - -@pytest.fixture -def classification_model_cfg(): - res = MPAConfig.fromfile('models/classification/mobilenet_v2.yaml') - return res - - -@pytest.fixture -def detection_model_cfg(): - res = MPAConfig.fromfile('models/detection/faster_rcnn_r50_fpn.py') - res.pretrained = None - return res - - -@pytest.fixture -def cifar_data_cfg(): - return MPAConfig.fromfile('tests/assets/data_cfg/cifar10split_224_bs16.py') - - -@pytest.fixture -def coco_data_cfg(): - return MPAConfig.fromfile('tests/assets/data_cfg/coco_smallest.py') - - -@pytest.fixture -def classification_recipe(): - return make_sample_recipe() - - -@pytest.fixture -def detection_recipe(): - return make_sample_recipe(task='detection') - - -@pytest.fixture -def MDA_cls(): - return MdaRunner(**make_sample_recipe(task="classification", mda_metric="z-score")) - - -@pytest.fixture -def MDA_det(): - return MdaRunner(**make_sample_recipe(task="detection", mda_metric="z-score")) - - -@pytest.fixture -def MDA_cls_cfg(MDA_cls, classification_model_cfg, cifar_data_cfg): - MDA_cls.task_stage._init_logger() - return MDA_cls.task_stage.configure(classification_model_cfg, None, cifar_data_cfg, training=False) - - -@pytest.fixture -def MDA_det_cfg(MDA_det, detection_model_cfg, coco_data_cfg): - MDA_det.task_stage._init_logger() - return MDA_det.task_stage.configure(detection_model_cfg, None, coco_data_cfg, training=False) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -@pytest.mark.parametrize("task", [1, 0.5, True, 'wrong_value']) -def test_MdaRunner_init_wrong_task_value(task): - with pytest.raises(ValueError): - MdaRunner(**make_sample_recipe(task=task)) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -@pytest.mark.parametrize("mda_metric", [1, 0.5, True, 'wrong_value']) -def test_MdaRunner_init_wrong_mda_metric_value(mda_metric): - with pytest.raises(ValueError): - MdaRunner(**make_sample_recipe(mda_metric=mda_metric)) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -@pytest.mark.parametrize("task", ["classification", "detection"]) -@pytest.mark.parametrize("mda_metric", ['z-score', 'cos-sim', 'kl', 'wst']) -def test_MdaRunner_init_right_mda_metric_value(task, mda_metric): - MdaRunner(**make_sample_recipe(task=task, mda_metric=mda_metric)) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_MdaRunner_classification_make_dataset(MDA_cls, MDA_cls_cfg): - ds = MDA_cls.make_dataset(MDA_cls_cfg) - assert 'mpa.modules.datasets' in str(type(ds)) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -@pytest.mark.parametrize("input_source", ["train", "val", "test"]) -def test_MdaRunner_detection_make_dataset(MDA_det, MDA_det_cfg, input_source): - MDA_det_cfg.input_source = input_source - ds = MDA_det.make_dataset(MDA_det_cfg) - assert 'mmdet.datasets' in str(type(ds)) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_MdaRunner_classification_make_model(MDA_cls, MDA_cls_cfg): - model = MDA_cls.make_model(MDA_cls_cfg) - assert 'mmcls.model' in str(type(model)) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_MdaRunner_detection_make_model(MDA_det, MDA_det_cfg): - datset = Config({'CLASSES': 10}) - MDA_det.dataset = datset - model = MDA_det.make_model(MDA_det_cfg) - assert 'mmdet.models' in str(type(model)) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_MdaRunner_classification_analyze_model_drift(monkeypatch, MDA_cls, MDA_cls_cfg): - monkeypatch.setattr(MDA, "measure", mock_function) - monkeypatch.setattr(mda_stage, "build_dataloader_cls", mock_function) - MDA_cls.analyze_model_drift(MDA_cls_cfg) - assert os.path.exists(f'{OUTPUT_PATH}/stage00_finetune/mpa_output.txt') - shutil.rmtree(OUTPUT_PATH) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_MdaRunner_detection_analyze_model_drift(monkeypatch, MDA_det, MDA_det_cfg): - monkeypatch.setattr(MDA, "measure", mock_function) - monkeypatch.setattr(mda_stage, "build_dataloader_det", mock_function) - MDA_det.analyze_model_drift(MDA_det_cfg) - assert os.path.exists(f'{OUTPUT_PATH}/stage00_finetune/mpa_output.txt') - shutil.rmtree(OUTPUT_PATH) - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_MdaRunner_MDA_run_wrong_mode(MDA_cls, classification_model_cfg, cifar_data_cfg): - MDA_cls.mode = 'wrong_value' - res = MDA_cls.run(model_cfg=classification_model_cfg, model_ckpt=None, data_cfg=cifar_data_cfg) - assert res == {} - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_MdaRunner_run(MDA_det, detection_model_cfg, coco_data_cfg): - MDA_det.analyze_model_drift = mock_function - res = MDA_det.run(model_cfg=detection_model_cfg, model_ckpt=None, data_cfg=coco_data_cfg) - assert res == 1 - assert os.path.exists(OUTPUT_PATH) - shutil.rmtree(OUTPUT_PATH) diff --git a/tests/unit/mpa/modules/utils/test_pseudo_nms.py b/tests/unit/mpa/modules/utils/test_pseudo_nms.py deleted file mode 100644 index d6da0d07..00000000 --- a/tests/unit/mpa/modules/utils/test_pseudo_nms.py +++ /dev/null @@ -1,53 +0,0 @@ -import pytest -import torch - -from mpa.modules.experimental.utils.pseudo_nms import pseudo_multiclass_nms - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_pseudo_multiclass_nms(monkeypatch): - - # num_classes = 1 - score_thr = 0.8 - max_num = 1 - multi_bboxes = torch.tensor([ - [1.0, 2.0, 3.0, 4.0], - ]) - multi_scores = torch.tensor([ - [0.1, 0.9] - ]) - # gt_bboxes = torch.zeros((0, 5)) - # gt_labels = torch.zeros((0,), dtype=torch.long) - bboxes, labels = pseudo_multiclass_nms( - multi_bboxes, multi_scores, score_thr, {} - ) - assert bboxes.numel() == 0 - assert labels.numel() == 0 - - multi_bboxes = torch.tensor([ - [1.0, 2.0, 3.0, 4.0], - ]) - multi_scores = torch.tensor([ - [0.9, 0.1] - ]) - # gt_bboxes = torch.tensor([ - # [1.0, 2.0, 3.0, 4.0, 0.9, 0.9, 0.1], - # # [x, y, w, h, max_conf, conf_0, ..., conf_num_classes] - # ]) - # gt_labels = torch.tensor([ - # 0 - # ]) - - def fake_nms(bboxes, scores, labels, nms_cfg): - return torch.tensor([[1.0, 2.0, 3.0, 4.0, 0.9]]), torch.tensor([True]) - from mpa.modules.experimental.utils import pseudo_nms - monkeypatch.setattr(pseudo_nms, 'batched_nms', fake_nms) - bboxes, labels = pseudo_multiclass_nms( - multi_bboxes, multi_scores, score_thr, {}, max_num - ) diff --git a/tests/unit/mpa/modules/utils/test_task_adapt.py b/tests/unit/mpa/modules/utils/test_task_adapt.py deleted file mode 100644 index 18676730..00000000 --- a/tests/unit/mpa/modules/utils/test_task_adapt.py +++ /dev/null @@ -1,158 +0,0 @@ -import pytest -import torch -from mpa.modules.utils.task_adapt import map_class_names, class_sensitive_copy_state_dict, extract_anchor_ratio,\ - map_cat_and_cls_as_order, prob_extractor - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements -from unittest.mock import patch, Mock - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_map_class_names(): - src_classes = ['person', 'car', 'tree'] - dst_classes = ['tree', 'person', 'sky', 'ball'] - gt_src2dst = [1, -1, 0] - src2dst = map_class_names(src_classes, dst_classes) - assert src2dst == gt_src2dst - - src_classes = ['person', 'car', 'tree'] - dst_classes = [] - gt_src2dst = [-1, -1, -1] - src2dst = map_class_names(src_classes, dst_classes) - assert src2dst == gt_src2dst - - src_classes = [] - dst_classes = ['tree', 'person', 'sky', 'ball'] - gt_src2dst = [] - src2dst = map_class_names(src_classes, dst_classes) - assert src2dst == gt_src2dst - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_class_sensitive_copy_state_dict(): - # with pytest.raises(NotImplementedError): # Changed to warning - class_sensitive_copy_state_dict({}, [], {}, [], 'SomeNewDetector') - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_class_sensitive_copy_state_dict_cls(): - import os - assets_path = 'tests/assets' - model_path = os.path.join(assets_path, 'model_cfg/task_inc/parameters.pth') - state_dict = torch.load(model_path, map_location=torch.device('cpu'))['state_dict'] - class_sensitive_copy_state_dict(state_dict, ['class1'], state_dict, ['class1', 'class2'], 'TaskIncrementalLwF') - wrong_params = os.path.join(assets_path, 'model_cfg/ckpt/cifar10_5cls_mnet_v2.pth') - wrong_state_dict = torch.load(wrong_params, map_location=torch.device('cpu'))['state_dict'] - mock_warning = Mock() - mock_logger = Mock(warning=mock_warning) - # mock_logger.warning = mock_warning - with patch('mpa.modules.utils.task_adapt.logger', mock_logger): - class_sensitive_copy_state_dict(wrong_state_dict, ['class1'], state_dict, ['class1', 'class2'], - 'TaskIncrementalLwF') - mock_warning.assert_called() - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_extract_anchor_ratio(): - from mmdet.datasets.builder import build_dataset - input_size = 512 - img_norm_cfg = dict(mean=[0, 0, 0], std=[255, 255, 255], to_rgb=True) - data_cfg = dict( - samples_per_gpu=30, - workers_per_gpu=3, - train=dict( - type='CocoDataset', - classes=['bird'], - ann_file='data/coco/annotations/semi_supervised/instances_train2017.1@1.0.json', - min_size=20, - img_prefix='data/coco/train2017', - pipeline=[ - dict(type='LoadImageFromFile', to_float32=True), - dict(type='LoadAnnotations', with_bbox=True), - dict( - type='PhotoMetricDistortion', - brightness_delta=32, - contrast_range=(0.5, 1.5), - saturation_range=(0.5, 1.5), - hue_delta=18), - dict( - type='MinIoURandomCrop', - min_ious=(0.1, 0.3, 0.5, 0.7, 0.9), - min_crop_size=0.1), - dict(type='Resize', img_scale=(input_size, input_size), keep_ratio=False), - dict(type='Normalize', **img_norm_cfg), - dict(type='RandomFlip', flip_ratio=0.5), - dict(type='DefaultFormatBundle'), - dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']), - ] - ), - ) - dataset = build_dataset(data_cfg['train']) - res = extract_anchor_ratio(dataset) - assert len(res) == 5 - res = extract_anchor_ratio(dataset, 7) - assert len(res) == 7 - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_map_cat_and_cls_as_order(): - classes = ['car', 'person'] - cats = {0: {'id': 0, 'name': 'person'}, 1: {'id': 1, 'name': 'car'}, 2: {'id': 2, 'name': 'truck'}} - cat2labels, cat_ids = map_cat_and_cls_as_order(classes, cats) - assert len(cat2labels) == 2 - assert len(cat_ids) == 2 - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -@pytest.mark.priority_high -@pytest.mark.unit -def test_prob_extractor(): - from mmcls.models import build_classifier - model_cfg = dict( - type='TaskIncrementalLwF', - pretrained=None, - backbone=dict( - type='MobileNetV2', - widen_factor=1.0, - ), - neck=dict( - type='GlobalAveragePooling' - ), - head=dict( - type='TaskIncLwfHead', - in_channels=1280, - tasks=dict( - Age=["Other", "Senior", "Kids", "Unknown"] - ), - distillation_loss=dict( - type='LwfLoss', - T=2 - ), - topk=(1,) - ) - ) - data_loader = [] - for i in range(4): - dummy_image = torch.rand(3, 3, 224, 224) - data_loader.append(dict(img=dummy_image)) - model = build_classifier(model_cfg) - old_prob, _ = prob_extractor(model, data_loader) - assert 'Age' in old_prob - assert old_prob['Age'].shape == (12, 4) diff --git a/tests/unit/mpa/selfsl/__init__.py b/tests/unit/mpa/selfsl/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/selfsl/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/selfsl/test_selfsl_builder.py b/tests/unit/mpa/selfsl/test_selfsl_builder.py deleted file mode 100644 index f4ed488a..00000000 --- a/tests/unit/mpa/selfsl/test_selfsl_builder.py +++ /dev/null @@ -1,88 +0,0 @@ -import unittest -import pytest -# from mmcls.models import BACKBONES -# from mmcls.datasets import DATASETS as CLS_DATASETS -import mpa.selfsl.builder as builder - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSLBuilder(unittest.TestCase): - def setUp(self): - dataset_type = 'SelfSLDataset' - down_task = 'classification' - img_norm_cfg = dict( - mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) - self.train_pipeline = [ - dict(type='RandomResizedCrop', size=112), - dict(type='ToNumpy'), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='Collect', keys=['img']) - ] - data_cfg = dict( - type=dataset_type, - down_task=down_task, - datasource=dict( - type='TVDatasetSplit', - data_prefix='data/torchvision/cifar10', - base='CIFAR10', - pipeline=[], - train=True, - download=True), - pipeline=dict( - view0=self.train_pipeline, - view1=self.train_pipeline - ) - ) - model_cfg = dict( - type='SelfSL', - donw_task=down_task, - pretrained='torchvision://resnet50', - backbone=dict( - type='ResNet', - depth=50 - ), - neck=dict( - type='MLP', - in_channels=2048, - hid_channels=256, - out_channels=128, - with_avg_pool=True - ), - head=dict( - type='LatentPredictHead', - loss='MSE', - size_average=True, - predictor=dict( - type='MLP', - in_channels=128, - hid_channels=256, - out_channels=128, - with_avg_pool=False - ) - ) - ) - - self.cfg = dict( - model=model_cfg, - data=dict( - train=data_cfg, - ) - ) - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build(self): - data_cfg = self.cfg['data']['train'] - concat_data_cfg = [data_cfg, data_cfg] - concat_dataset = builder.build_dataset(concat_data_cfg) - dataset = builder.build_dataset(data_cfg) - - self.assertEqual(len(dataset) * 2, len(concat_dataset)) diff --git a/tests/unit/mpa/selfsl/test_selfsl_trainer.py b/tests/unit/mpa/selfsl/test_selfsl_trainer.py deleted file mode 100644 index 7a6d90b8..00000000 --- a/tests/unit/mpa/selfsl/test_selfsl_trainer.py +++ /dev/null @@ -1,167 +0,0 @@ -""" -import unittest -import pytest -from unittest.mock import patch, Mock -from mmcv import Config -from mpa.selfsl.trainer import SelfSLTrainer - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSLStageTrainer(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_selfsl_stage_trainer(self): - selfsl_cfg = 'recipes/stages/classification/train_selfsl.yaml' - with patch('mpa.selfsl.trainer.SelfSLTrainer'): - stage = SelfSLTrainer(config=selfsl_cfg, name='selfsl_training', mode='train') - model_cfg = Config.fromfile('models/classification/resnet50.yaml') - data_cfg = Mock(data=Mock(unlabeled=None)) - out = stage.run(model_cfg=model_cfg, data_cfg=data_cfg, model_ckpt=None) - self.assertIsInstance(out, dict) - self.assertIn('pretrained', out) - self.assertIsInstance(stage, SelfSLTrainer) -""" - -import copy -import os -import os.path as osp -import shutil -import unittest -from unittest.mock import patch, Mock -import torch -import pytest - -from mmcv import ConfigDict - -from mpa.selfsl.trainer import SelfSLTrainer - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -# @pytest.mark.components(MPAComponent.MPA) -def check_dict(cfg, pairs: dict, parents: list, check: dict): - for k, v in cfg.items(): - parents.append(k) - full_k = '.'.join(parents) - if (k in pairs.keys() and full_k not in pairs.keys() and v != pairs[k]) \ - or (full_k in pairs.keys() and v != pairs[full_k]): - check[full_k] = v - elif isinstance(v, dict): - check_dict(v, pairs, parents, check) - elif isinstance(v, (list, tuple)): - for i in range(len(v)): - _v = v[i] - parents.append(str(i)) - if isinstance(_v, dict): - check_dict(_v, pairs, parents, check) - parents.pop() - parents.pop() - - -@pytest.mark.components(MPAComponent.MPA) -class TestSelfSLTrainer(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - self.output_path = 'outputs_selfsl_trainer' - self.model_cfg = dict( - model=dict( - backbone=dict( - type='ResNet', - depth=50, - norm_eval=True - ) - ) - ) - self.dataset_cfg = dict( - data=dict( - unlabeled=dict( - type='TVDatasetSplit', - base='CIFAR10', - pipeline=[], - train=True, - download=True, - num_images=100 - ) - ) - ) - os.makedirs(self.output_path, exist_ok=True) - - def tearDown(self): - if osp.exists(self.output_path): - shutil.rmtree(self.output_path) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_trainer(self): - cfg_dict = dict(type='test-selfsl') - with pytest.raises(KeyError): - trainer = SelfSLTrainer(config=cfg_dict, name='stage', mode='train') - self.assertIsInstance(trainer, SelfSLTrainer) - - cfg_file = 'recipes/stages/classification/selfsl.yaml' - trainer = SelfSLTrainer(config=cfg_file, name='stage', mode='train') - self.assertIsInstance(trainer, SelfSLTrainer) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_configure(self): - cfg_file = 'recipes/stages/classification/selfsl.yaml' - backbone_cfg = ConfigDict(copy.deepcopy(self.model_cfg['model']['backbone'])) - dataset_cfg = ConfigDict(copy.deepcopy(self.dataset_cfg)) - - trainer = SelfSLTrainer(config=cfg_file, name='stage', mode='train') - trainer.configure(backbone_cfg, dataset_cfg) - self.assertTrue(bool(trainer.cfg.model.pretrained)) - pairs = {'norm_eval': False} - check = {} - check_dict(trainer.cfg, pairs, [], check) - self.assertFalse(check, f'Expected {pairs}') - - trainer._configure_model(backbone_cfg, 'random') - self.assertFalse(bool(trainer.cfg.model.pretrained)) - - trainer._configure_model(backbone_cfg, 'model_ckpt.pth') - self.assertEqual(trainer.cfg.load_from, 'model_ckpt.pth') - - backbone_cfg['type'] = 'OTEEfficientNet' - converted_key = osp.join(self.output_path, 'model_ckpt.converted.pth') - feat = Mock(spec=torch.Tensor, shape=(2, 1024, 7, 7)) - backbone = Mock(return_value=feat) - with patch('mpa.selfsl.trainer.convert_keys', Mock(return_value=converted_key)), \ - patch('mpa.selfsl.trainer.build_backbone', Mock(return_value=backbone)): - trainer._configure_model(backbone_cfg, 'model_ckpt.pth') - self.assertEqual(trainer.cfg.load_from, osp.join(self.output_path, 'model_ckpt.converted.pth')) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_run(self): - cfg_file = 'recipes/stages/classification/selfsl.yaml' - model_cfg = ConfigDict(copy.deepcopy(self.model_cfg)) - data_cfg = ConfigDict(copy.deepcopy(self.dataset_cfg)) - - trainer = SelfSLTrainer(config=cfg_file, name='stage', mode='train') - - # set for short tests - trainer.cfg.data.pipeline_options.RandomResizedCrop.size = 32 - trainer.cfg.work_dir = self.output_path - trainer.cfg.checkpoint_config.interval = 1 - trainer.cfg.runner.max_iters = 1 - trainer.cfg.runner.max_epochs = None - - trainer.run(model_cfg=model_cfg, data_cfg=data_cfg, model_ckpt=None) - self.assertTrue(osp.exists(self.output_path)) - self.assertTrue(osp.exists(osp.join(self.output_path, 'backbone.pth'))) diff --git a/tests/unit/mpa/test_builder.py b/tests/unit/mpa/test_builder.py deleted file mode 100644 index 54a3e670..00000000 --- a/tests/unit/mpa/test_builder.py +++ /dev/null @@ -1,55 +0,0 @@ -import unittest -import pytest -from unittest.mock import patch, Mock - -from mmcv import Config -from mpa.builder import build -from mpa.workflow import Workflow -from mpa.stage import Stage - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestBuilder(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_build_workflow_config(self): - config_file = 'path/not/exits/file.yaml' - with pytest.raises(Exception) as e: - build(config_file) - self.assertEqual(e.type, ValueError) - - config = Config( - dict( - workflow_hooks=[ - dict( - type='SampleLoggingHook', - log_level='WARNING' - ) - ], - stages=[ - dict(), - dict() - ] - ) - ) - mock_stage = Mock(spec=Stage) - mock_stage.name = 'fake-stage' - - mock_build_stage = Mock(return_value=mock_stage) - with patch('mpa.builder.__build_stage', mock_build_stage): - wf = build(config) - self.assertTrue(isinstance(wf, Workflow)) - - config_file = 'recipes/cls.yaml' - wf = build(config_file) - self.assertTrue(isinstance(wf, Workflow)) diff --git a/tests/unit/mpa/test_stage.py b/tests/unit/mpa/test_stage.py deleted file mode 100644 index 30e89348..00000000 --- a/tests/unit/mpa/test_stage.py +++ /dev/null @@ -1,96 +0,0 @@ -import unittest -import os -import shutil -import pytest -import time -from unittest.mock import patch, MagicMock, Mock - -from mmcv.utils import Config - -from mpa.stage import Stage - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestStage(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_init(self): - # config - cfg = 'path/is/not/existed.yaml' - with pytest.raises(Exception) as e: - stage = Stage('stage', 'test-mode', cfg) - self.assertEqual(e.type, ValueError) - - cfg = MagicMock(spec=Config, total_epochs=10) - cfg.checkpoint_config = Mock(interval=1) - cfg.custom_hooks = [] - cfg.runner = Mock(max_epochs=1) - cfg.pop = Mock(return_value=1) - - def cfg_get(*args): - if args[0] == 'custom_hooks': - return [] - else: - return '' - cfg.get = Mock(side_effect=cfg_get) - stage = Stage('stage', 'test-mode', cfg) - self.assertIsInstance(stage, Stage, 'cannot create a Stage instance with Config object') - - cfg = dict( - checkpoint_config=dict(interval=1), - runner=dict(type='fast-runner', max_epochs=1) - ) - stage = Stage('stage', 'test-mode', cfg) - self.assertIsInstance(stage, Stage, 'cannot create a Stage instance with dict') - - cfg = 'recipes/stages/classification/train.yaml' - stage = Stage('stage', 'test-mode', cfg) - self.assertIsInstance(stage, Stage, 'cannot create a Stage instance with the config file') - - # common_cfg - common_cfg = [] - with pytest.raises(Exception) as e: - stage = Stage('stage', 'test-mode', cfg, common_cfg=common_cfg) - self.assertEqual(e.type, TypeError) - - common_cfg = dict(runner=dict(type='new-runner', max_epochs=1)) - stage = Stage('stage', 'test-mode', cfg, common_cfg=common_cfg) - self.assertIsInstance(stage, Stage, 'cannot create a Stage instance with the common_cfg') - self.assertEqual(common_cfg['runner'], stage.cfg['runner']) - - # kwargs - stage = Stage('stage', 'test-mode', cfg, something_new='new-value') - self.assertEqual('new-value', stage.cfg['something_new']) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_init_logger(self): - timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime()) - time_strftime = MagicMock(return_value=timestamp) - cfg = dict( - log_level='DEBUG' - ) - common_cfg = dict( - output_path='logs/unittests' - ) - stage = Stage('stage', 'test-mode', cfg, common_cfg) - - with patch('time.strftime', time_strftime): - stage._init_logger() - - log_file = os.path.join(common_cfg['output_path'], f'stage00_stage/{timestamp}.log') - self.assertTrue(os.path.exists(log_file)) - - # cleanup output dir - shutil.rmtree(common_cfg['output_path'], ignore_errors=False) diff --git a/tests/unit/mpa/test_workflow.py b/tests/unit/mpa/test_workflow.py deleted file mode 100644 index 3246aab2..00000000 --- a/tests/unit/mpa/test_workflow.py +++ /dev/null @@ -1,89 +0,0 @@ -import unittest -import pytest -from unittest.mock import Mock, MagicMock - -from mpa.workflow import Workflow -from mpa.modules.hooks.workflow_hooks import WorkflowHook -from mpa.stage import Stage - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestWorkflow(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_init(self): - with pytest.raises(Exception) as e: - Workflow('test', None) - self.assertEqual(e.type, ValueError) - - with pytest.raises(Exception) as e: - Workflow([], None) - self.assertEqual(e.type, ValueError) - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_call_hooks(self): - wf_hook0 = Mock(spec=WorkflowHook) - wf_hook0.before_workflow = MagicMock() - wf_hook1 = Mock(spec=WorkflowHook) - wf_hook1.after_workflow = MagicMock() - wf_hook2 = Mock(spec=WorkflowHook) - wf_hook2.before_stage = MagicMock() - wf_hook3 = Mock(spec=WorkflowHook) - wf_hook3.after_stage = MagicMock() - - stage0 = Mock(spec=Stage) - stage0.name = 'fake0' - stage0.run = MagicMock(return_value=dict(key='xyz')) - wf = Workflow([stage0], [wf_hook0, wf_hook1, wf_hook2, wf_hook3]) - wf.run() - - wf_hook0.before_workflow.assert_called() - wf_hook1.after_workflow.assert_called() - wf_hook2.before_stage.assert_called() - wf_hook3.after_stage.assert_called() - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_run(self): - stage0 = Mock(spec=Stage) - stage0.name = 'fake0' - stage0.run = MagicMock(return_value=dict(key='xyz')) - stage1 = Mock(spec=Stage) - stage1.name = 'fake1' - stage1.run = MagicMock(return_value=dict()) - stage1.input = dict( - stage0_output=dict( - stage_name='fake0', - output_key='key' - ) - ) - stage_invalid = Mock(spec=Stage) - stage_invalid.name = 'invalid' - stage_invalid.run = MagicMock(return_value='run-results1') - stage_invalid.input = dict( - # missing required attribute definition - stage0_output=dict( - stage_name='fake0' - ) - ) - - wf = Workflow([stage0, stage_invalid], None) - with pytest.raises(Exception) as e: - wf.run() - self.assertEqual(e.type, ValueError) - - wf = Workflow([stage0, stage1], None) - wf.run() diff --git a/tests/unit/mpa/utils/__init__.py b/tests/unit/mpa/utils/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/mpa/utils/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/mpa/utils/test_hpo_stage.py b/tests/unit/mpa/utils/test_hpo_stage.py deleted file mode 100644 index 8513058e..00000000 --- a/tests/unit/mpa/utils/test_hpo_stage.py +++ /dev/null @@ -1,70 +0,0 @@ -import unittest -import pytest - -from mmcv.utils.config import ConfigDict - -from mpa.utils.hpo_stage import HpoRunner -from mpa.utils.config_utils import MPAConfig - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -@pytest.mark.reqids(Requirements.REQ_1) -class TestHpoStage(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - - def tearDown(self): - pass - - @pytest.mark.priority_high - @pytest.mark.unit - def test_asha(self): - cfg = None - with pytest.raises(Exception) as e: - hpo_runner = HpoRunner(config=cfg, mode='train', name='hpo') - self.assertEqual(e.type, ValueError) - - hpo_cfg = {'hyperparams': [{'name': 'lr', 'range': [0.0001, 0.1], 'type': 'loguniform'}, - {'name': 'bs', 'range': [4, 32, 2], 'type': 'qloguniform'}], - 'max_iterations': 1, - 'metric': 'accuracy_top-1', - 'num_trials': 1, - 'search_alg': 'asha', - 'subset_size': 100, - 'trainer': {'config': 'recipes_old/classification/domain_adapt/finetune/train.yaml', - 'type': 'ClsTrainer'}, - } - common_cfg = {'log_level': 'DEBUG'} - hpo_runner = HpoRunner(hpo=ConfigDict(hpo_cfg), - common_cfg=ConfigDict(common_cfg), - mode='train', - name='hpo') - self.assertIsInstance(hpo_runner, HpoRunner, 'cannot create a HpoRunner instance with Config object') - self.assertEqual(hpo_runner.min_iterations, 1) - self.assertEqual(hpo_runner.max_iterations, 1) - self.assertEqual(hpo_runner.reduction_factor, 4) - - print('============================================') - print(hpo_runner.cfg) - print('============================================') - print("common_cfg", hpo_runner.cfg['common_cfg']) - print('============================================') - - cls_model_cfg = MPAConfig.fromfile('models/classification/mobilenet_v2.yaml') - cifar_data_cfg = MPAConfig.fromfile(f'{self.assets_path}/data_cfg/cifar10split_224_bs16.py') - - best_cfg = hpo_runner.run(mode='train', - model_cfg=cls_model_cfg, - model_ckpt=None, - data_cfg=cifar_data_cfg) - - self.assertIn('hyperparams', best_cfg) - self.assertIn('lr', best_cfg['hyperparams']) - self.assertIn('bs', best_cfg['hyperparams']) - self.assertGreaterEqual(best_cfg['hyperparams']['lr'], 0.0001) - self.assertLessEqual(best_cfg['hyperparams']['lr'], 0.1) - self.assertGreaterEqual(best_cfg['hyperparams']['bs'], 4) - self.assertLessEqual(best_cfg['hyperparams']['bs'], 32) diff --git a/tests/unit/tools/__init__.py b/tests/unit/tools/__init__.py deleted file mode 100644 index f570c087..00000000 --- a/tests/unit/tools/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# INTEL CONFIDENTIAL -# Copyright (c) 2021 Intel Corporation -# -# The source code contained or described herein and all documents related to -# the source code ("Material") are owned by Intel Corporation or its suppliers -# or licensors. Title to the Material remains with Intel Corporation or its -# suppliers and licensors. The Material contains trade secrets and proprietary -# and confidential information of Intel or its suppliers and licensors. The -# Material is protected by worldwide copyright and trade secret laws and treaty -# provisions. No part of the Material may be used, copied, reproduced, modified, -# published, uploaded, posted, transmitted, distributed, or disclosed in any way -# without Intel's prior express written permission. -# -# No license under any patent, copyright, trade secret or other intellectual -# property right is granted to or conferred upon you by disclosure or delivery -# of the Materials, either expressly, by implication, inducement, estoppel or -# otherwise. Any license under such intellectual property rights must be express -# and approved by Intel in writing. -# diff --git a/tests/unit/tools/test_cli.py b/tests/unit/tools/test_cli.py deleted file mode 100644 index 64247c21..00000000 --- a/tests/unit/tools/test_cli.py +++ /dev/null @@ -1,29 +0,0 @@ -import unittest -import pytest -import sys -import runpy - -from tests.constants.mpa_components import MPAComponent -from tests.constants.requirements import Requirements - - -@pytest.mark.components(MPAComponent.MPA) -class TestCli(unittest.TestCase): - def setUp(self): - self.assets_path = 'tests/assets' - self.recipes_path = 'recipes' - self.argv_tmp = sys.argv - self.output_path = 'outputs/tests/cli' - - def tearDown(self): - sys.argv = self.argv_tmp - - @pytest.mark.reqids(Requirements.REQ_1) - @pytest.mark.priority_high - @pytest.mark.unit - def test_cli_missing_required(self): - sys.argv = 'tools/cli.py'.split() - with pytest.raises(SystemExit) as e: - runpy.run_module('tools.cli', run_name='__main__') - self.assertEqual(e.type, SystemExit) - self.assertTrue(e.value.code, 2)