Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[DEV] Fix deprecated np.bool issue from numpy==1.24.0 #1455

Merged
merged 9 commits into from
Dec 23, 2022
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file.
### Fixed

- Neural Network Compression Framework (NNCF)

- Fix CUDA OOM for NNCF optimization model MaskRCNN-EfficientNetB2B (<https://github.com/openvinotoolkit/training_extensions/pull/1319>)

- Model Preparation Algorithm (MPA)
Expand Down
1 change: 1 addition & 0 deletions external/anomaly/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ openmodelzoo-modelapi @ git+https://github.com/openvinotoolkit/open_model_zoo/@r
openvino==2022.1.0
openvino-dev==2022.1.0
pytorch-lightning>=1.6.0,<1.7.0
numpy<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime
1 change: 1 addition & 0 deletions external/deep-object-reid/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ openvino-dev==2022.1.0
openmodelzoo-modelapi @ git+https://github.com/openvinotoolkit/open_model_zoo/@releases/2022/SCv1.1#egg=openmodelzoo-modelapi&subdirectory=demos/common/python
nncf@ git+https://github.com/openvinotoolkit/nncf@e85a695da95b202b4579ea11f880f1b14bfcda2e#egg=nncf
networkx<=2.8.0
numpy<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime
1 change: 1 addition & 0 deletions external/mmsegmentation/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ openmodelzoo-modelapi @ git+https://github.com/openvinotoolkit/open_model_zoo/@r
nncf@ git+https://github.com/openvinotoolkit/nncf@e85a695da95b202b4579ea11f880f1b14bfcda2e#egg=nncf
networkx<=2.8.0
protobuf<3.21.0
numpy<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime
133 changes: 60 additions & 73 deletions ote_cli/ote_cli/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import json
import os
import shutil
from subprocess import run # nosec
import subprocess # nosec

import pytest

Expand All @@ -36,12 +36,9 @@ def get_some_vars(template, root):
def create_venv(algo_backend_dir, work_dir):
venv_dir = f"{work_dir}/venv"
if not os.path.exists(venv_dir):
assert run([f"./{algo_backend_dir}/init_venv.sh", venv_dir]).returncode == 0
assert (
run(
[f"{work_dir}/venv/bin/python", "-m", "pip", "install", "-e", "ote_cli"]
).returncode
== 0
check_run([f"./{algo_backend_dir}/init_venv.sh", venv_dir])
check_run(
[f"{work_dir}/venv/bin/python", "-m", "pip", "install", "-e", "ote_cli"]
)


Expand Down Expand Up @@ -73,6 +70,11 @@ def collect_env_vars(work_dir):
return vars


def check_run(cmd, **kwargs):
result = subprocess.run(cmd, stderr=subprocess.PIPE, **kwargs)
assert result.returncode == 0, result.stderr.decode("utf=8")


def ote_train_testing(template, root, ote_dir, args):
work_dir, template_work_dir, _ = get_some_vars(template, root)
command_line = [
Expand All @@ -95,7 +97,7 @@ def ote_train_testing(template, root, ote_dir, args):
["--load-weights", f'{os.path.join(ote_dir, args["--load-weights"])}']
)
command_line.extend(args["train_params"])
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/trained_{template.model_template_id}/weights.pth"
)
Expand Down Expand Up @@ -127,7 +129,7 @@ def ote_hpo_testing(template, root, ote_dir, args):
"1",
]
command_line.extend(args["train_params"])
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(f"{template_work_dir}/hpo/hpopt_status.json")
with open(f"{template_work_dir}/hpo/hpopt_status.json", "r") as f:
assert json.load(f).get("best_config_id", None) is not None
Expand All @@ -150,7 +152,7 @@ def ote_export_testing(template, root):
"--save-model-to",
f"{template_work_dir}/exported_{template.model_template_id}",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/exported_{template.model_template_id}/openvino.xml"
)
Expand All @@ -177,7 +179,7 @@ def ote_eval_testing(template, root, ote_dir, args):
"--save-performance",
f"{template_work_dir}/trained_{template.model_template_id}/performance.json",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/trained_{template.model_template_id}/performance.json"
)
Expand All @@ -198,7 +200,7 @@ def ote_eval_openvino_testing(template, root, ote_dir, args, threshold):
"--save-performance",
f"{template_work_dir}/exported_{template.model_template_id}/performance.json",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/exported_{template.model_template_id}/performance.json"
)
Expand Down Expand Up @@ -233,7 +235,7 @@ def ote_demo_testing(template, root, ote_dir, args):
"--delay",
"-1",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))


def ote_demo_openvino_testing(template, root, ote_dir, args):
Expand All @@ -249,7 +251,7 @@ def ote_demo_openvino_testing(template, root, ote_dir, args):
"--delay",
"-1",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))


def ote_deploy_openvino_testing(template, root, ote_dir, args):
Expand All @@ -264,63 +266,48 @@ def ote_deploy_openvino_testing(template, root, ote_dir, args):
"--save-model-to",
deployment_dir,
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
assert run(["unzip", "-o", "openvino.zip"], cwd=deployment_dir).returncode == 0
assert (
run(
["python3", "-m", "venv", "venv"],
cwd=os.path.join(deployment_dir, "python"),
).returncode
== 0
check_run(command_line, env=collect_env_vars(work_dir))
check_run(["unzip", "-o", "openvino.zip"], cwd=deployment_dir)
check_run(
["python3", "-m", "venv", "venv"],
cwd=os.path.join(deployment_dir, "python"),
)
assert (
run(
["python3", "-m", "pip", "install", "wheel"],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
).returncode
== 0
check_run(
["python3", "-m", "pip", "install", "wheel"],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
)

assert (
run(
["python3", "-m", "pip", "install", "pip", "--upgrade"],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
).returncode
== 0
check_run(
["python3", "-m", "pip", "install", "pip", "--upgrade"],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
)
assert (
run(
[
"python3",
"-m",
"pip",
"install",
"-r",
os.path.join(deployment_dir, "python", "requirements.txt"),
],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
).returncode
== 0
check_run(
[
"python3",
"-m",
"pip",
"install",
"-r",
os.path.join(deployment_dir, "python", "requirements.txt"),
],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
)

assert (
run(
[
"python3",
"demo.py",
"-m",
"../model",
"-i",
os.path.join(ote_dir, args["--input"]),
"--no_show",
],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
).returncode
== 0
check_run(
[
"python3",
"demo.py",
"-m",
"../model",
"-i",
os.path.join(ote_dir, args["--input"]),
"--no_show",
],
cwd=os.path.join(deployment_dir, "python"),
env=collect_env_vars(os.path.join(deployment_dir, "python")),
)


Expand All @@ -339,7 +326,7 @@ def ote_eval_deployment_testing(template, root, ote_dir, args, threshold):
"--save-performance",
f"{template_work_dir}/deployed_{template.model_template_id}/performance.json",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/deployed_{template.model_template_id}/performance.json"
)
Expand Down Expand Up @@ -373,7 +360,7 @@ def ote_demo_deployment_testing(template, root, ote_dir, args):
"--delay",
"-1",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))


def pot_optimize_testing(template, root, ote_dir, args):
Expand All @@ -395,7 +382,7 @@ def pot_optimize_testing(template, root, ote_dir, args):
"--save-model-to",
f"{template_work_dir}/pot_{template.model_template_id}",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/pot_{template.model_template_id}/openvino.xml"
)
Expand All @@ -422,7 +409,7 @@ def pot_eval_testing(template, root, ote_dir, args):
"--save-performance",
f"{template_work_dir}/pot_{template.model_template_id}/performance.json",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/pot_{template.model_template_id}/performance.json"
)
Expand Down Expand Up @@ -450,7 +437,7 @@ def nncf_optimize_testing(template, root, ote_dir, args):
f"{template_work_dir}/nncf_{template.model_template_id}/train_performance.json",
]
command_line.extend(args["train_params"])
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/nncf_{template.model_template_id}/weights.pth"
)
Expand All @@ -470,7 +457,7 @@ def nncf_export_testing(template, root):
"--save-model-to",
f"{template_work_dir}/exported_nncf_{template.model_template_id}",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/exported_nncf_{template.model_template_id}/openvino.xml"
)
Expand Down Expand Up @@ -506,7 +493,7 @@ def nncf_eval_testing(template, root, ote_dir, args, threshold):
"--save-performance",
f"{template_work_dir}/nncf_{template.model_template_id}/performance.json",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/nncf_{template.model_template_id}/performance.json"
)
Expand Down Expand Up @@ -543,7 +530,7 @@ def nncf_eval_openvino_testing(template, root, ote_dir, args):
"--save-performance",
f"{template_work_dir}/exported_nncf_{template.model_template_id}/performance.json",
]
assert run(command_line, env=collect_env_vars(work_dir)).returncode == 0
check_run(command_line, env=collect_env_vars(work_dir))
assert os.path.exists(
f"{template_work_dir}/exported_nncf_{template.model_template_id}/performance.json"
)
Expand Down
2 changes: 1 addition & 1 deletion ote_cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pyyaml
opencv-python
numpy
numpy<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime
nbmake
pytest
pytest-ordering
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
openvino==2022.1.0
openmodelzoo-modelapi @ git+https://github.com/openvinotoolkit/open_model_zoo/@releases/2022/SCv1.1#egg=openmodelzoo-modelapi&subdirectory=demos/common/python
ote-sdk @ git+https://github.com/openvinotoolkit/training_extensions/@c29f1b385d5eabcf07bc9a6e9c340fd0dbf67c8d#egg=ote-sdk&subdirectory=ote_sdk
ote-sdk @ git+https://github.com/openvinotoolkit/training_extensions/@565fbf682cc8a182ce67a69688f0e7b48a991696#egg=ote-sdk&subdirectory=ote_sdk
numpy<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime
2 changes: 1 addition & 1 deletion ote_sdk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy>=1.16.4
numpy>=1.16.4,<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime
scikit-learn==0.24.*
Shapely>=1.7.1,<=1.8.0
networkx>=2.6,<2.8.1rc1
Expand Down
4 changes: 2 additions & 2 deletions tests/ote_cli/misc/test_code_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# and limitations under the License.

import os
from subprocess import run

from ote_sdk.test_suite.e2e_test_system import e2e_pytest_component
from ote_cli.utils.tests import check_run

class TestCodeChecks:
@e2e_pytest_component
def test_code_checks(self):
wd = os.path.join(os.path.dirname(__file__), "..", "..", "..")
assert run(["./tests/run_code_checks.sh"], cwd=wd, check=True).returncode == 0
check_run(["./tests/run_code_checks.sh"], cwd=wd)
9 changes: 5 additions & 4 deletions tests/run_model_templates_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import os
import sys
from subprocess import run

from ote_cli.utils.tests import collect_env_vars
from ote_cli.utils.tests import collect_env_vars, check_run

ALGO_ROOT_DIR = "external"
ALGO_DIRS = [
Expand Down Expand Up @@ -59,7 +58,8 @@ def test(run_algo_tests):
success = True
command = ["pytest", os.path.join("tests", "ote_cli", "misc"), "-v"]
try:
res = run(command, env=collect_env_vars(wd), check=True).returncode == 0
check_run(command, env=collect_env_vars(wd))
res = True
except:
res = False
passed["misc"] = res
Expand All @@ -68,7 +68,8 @@ def test(run_algo_tests):
if run_algo_tests[algo_dir]:
command = ["pytest", os.path.join(algo_dir, "tests", "ote_cli"), "-v", "-rxXs", "--durations=10"]
try:
res = run(command, env=collect_env_vars(wd), check=True).returncode == 0
check_run(command, env=collect_env_vars(wd))
res = True
except:
res = False
passed[algo_dir] = res
Expand Down