|
4 | 4 | import argparse |
5 | 5 | import re |
6 | 6 | import platform |
| 7 | +from subprocess import CalledProcessError, DEVNULL |
| 8 | +import textwrap |
| 9 | + |
7 | 10 |
|
8 | 11 | convert_default = "empty" |
9 | 12 | parser = argparse.ArgumentParser() |
@@ -46,7 +49,7 @@ def hasWhitespace(string): |
46 | 49 | # try to import opencv, numpy in a subprocess, since it might fail with illegal instruction |
47 | 50 | # if it was previously installed w/ pip without setting OPENBLAS_CORE_TYPE=ARMV8 env variable |
48 | 51 | try: |
49 | | - subprocess.check_call([sys.executable, "-c", "import numpy, cv2;"]) |
| 52 | + subprocess.check_call([sys.executable, "-c", "import numpy, cv2;"], stderr=DEVNULL) |
50 | 53 | requireOpenCv = False |
51 | 54 | except subprocess.CalledProcessError as ex: |
52 | 55 | requireOpenCv = True |
@@ -94,10 +97,38 @@ def hasWhitespace(string): |
94 | 97 |
|
95 | 98 | # Update pip |
96 | 99 | pip_update_cmd = [*pip_install, "pip"] |
| 100 | + |
97 | 101 | if args.dry_run: |
98 | 102 | prettyPrint(pip_update_cmd) |
99 | 103 | else: |
100 | | - subprocess.check_call(pip_update_cmd) |
| 104 | + try: |
| 105 | + subprocess.check_call(pip_update_cmd) |
| 106 | + except CalledProcessError as e: |
| 107 | + print(f"\n\n\033[31m\033[1m[Warning]\033[0m An error occurred while trying to update pip: {e}\n") |
| 108 | + print("This likely stems from the fact that you're not using a Python virtual environment.") |
| 109 | + venv_creation_instructions = textwrap.dedent(f"""\ |
| 110 | + \033[94m\033[1m |
| 111 | + Here's how you can create and activate a virtual environment: |
| 112 | + |
| 113 | + 1. Create a virtual environment: |
| 114 | + - For Linux or MacOS, use: python3 -m venv {parent_dir}/.env |
| 115 | + - For Windows, use: python -m venv {parent_dir}/.env |
| 116 | + |
| 117 | + 2. Activate the virtual environment: |
| 118 | + - For Linux or MacOS, use: source {parent_dir}/.env/bin/activate |
| 119 | + - For Windows, use: {parent_dir}/.env/Scripts/activate |
| 120 | + |
| 121 | + Once activated, you'll be working within the virtual environment. You can then attempt to re-run this script. |
| 122 | + To exit the virtual environment when you're done, simply use the command: deactivate |
| 123 | + |
| 124 | + For more detailed instructions, please refer to the official Python documentation on virtual environments: https://docs.python.org/3/tutorial/venv.html |
| 125 | + \033[0m |
| 126 | + """) |
| 127 | + |
| 128 | + print(textwrap.indent(venv_creation_instructions, ' ')) |
| 129 | + exit(0) |
| 130 | + |
| 131 | + |
101 | 132 | # Install python dependencies |
102 | 133 | python_dependencies_cmd = [*pip_package_install, *DEPENDENCIES] |
103 | 134 | if args.dry_run: |
@@ -161,16 +192,51 @@ def hasWhitespace(string): |
161 | 192 | subprocess.check_call(downloader_cmd) |
162 | 193 |
|
163 | 194 | if args.convert != convert_default: |
164 | | - nn_models_shaves = { |
165 | | - "mobilenet-ssd": [5, 6, 8], |
166 | | - "person-detection-retail-0013": [7], |
167 | | - "yolo-v4-tiny-tf": [6], |
168 | | - "yolo-v3-tiny-tf": [6], |
| 195 | + |
| 196 | + nn_model_configs = { |
| 197 | + "mobilenet-ssd": { |
| 198 | + "shaves": [5, 6, 8], |
| 199 | + "compile_params": ["-ip U8"], |
| 200 | + "zoo_type": "intel", |
| 201 | + "default_ov_version": "2021.4" |
| 202 | + }, |
| 203 | + "person-detection-retail-0013": { |
| 204 | + "shaves": [7], |
| 205 | + "compile_params": ["-ip U8"], |
| 206 | + "zoo_type": "intel", |
| 207 | + "default_ov_version": "2021.4" |
| 208 | + }, |
| 209 | + "yolo-v4-tiny-tf": { |
| 210 | + "shaves": [6], |
| 211 | + "compile_params": ["-ip U8"], |
| 212 | + "zoo_type": "intel", |
| 213 | + "default_ov_version": "2021.4" |
| 214 | + }, |
| 215 | + "yolo-v3-tiny-tf": { |
| 216 | + "shaves": [6], |
| 217 | + "compile_params": ["-ip U8"], |
| 218 | + "zoo_type": "intel", |
| 219 | + "default_ov_version": "2021.4" |
| 220 | + }, |
| 221 | + "yolov6n_thermal_people_256x192": { |
| 222 | + "shaves": [6], |
| 223 | + "compile_params": ["-ip FP16"], |
| 224 | + "zoo_type": "depthai", |
| 225 | + "default_ov_version": "2022.1" |
| 226 | + }, |
169 | 227 | } |
| 228 | + |
170 | 229 | blobconverter_cmds = [ |
171 | | - [sys.executable, "-m", "blobconverter", "-zn", nn_name, "-sh", str(nn_shave), "-o", f"{examples_dir}/models", *(["-v", args.convert] if args.convert is not None else [])] |
172 | | - for nn_name in nn_models_shaves |
173 | | - for nn_shave in nn_models_shaves[nn_name] |
| 230 | + [sys.executable, |
| 231 | + "-m", "blobconverter", |
| 232 | + "-zn", nn_name, |
| 233 | + "-sh", str(nn_shave), |
| 234 | + "-o", f"{examples_dir}/models", |
| 235 | + "-zt", nn_model_configs[nn_name]["zoo_type"], |
| 236 | + *(["--compile-params", " ".join(nn_model_configs[nn_name]["compile_params"])] if nn_model_configs[nn_name]["compile_params"] else []), |
| 237 | + *(["-v", args.convert] if args.convert != convert_default else ["-v", nn_model_configs[nn_name]["default_ov_version"]])] |
| 238 | + for nn_name in nn_model_configs |
| 239 | + for nn_shave in nn_model_configs[nn_name]["shaves"] |
174 | 240 | ] |
175 | 241 | install_blobconverter_cmd = [*pip_package_install, "blobconverter"] |
176 | 242 | for cmd in [install_blobconverter_cmd] + blobconverter_cmds: |
|
0 commit comments