Skip to content

Commit 2bf166b

Browse files
authored
Update notebook links (#2037)
1 parent 2c98d10 commit 2bf166b

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

scripts/rknn-convert-tool/create_onnx.py

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,63 @@
1616
ultralytics_folder_name_yolov5 = "airockchip_yolo_pkg_yolov5"
1717
ultralytics_default_folder_name = "airockchip_yolo_pkg"
1818

19-
2019
bad_model_msg = """
2120
This is usually due to passing in the wrong model version.
2221
Please make sure you have the right model version and try again.
2322
"""
2423

2524

26-
# idk how else to make Google Colab display this nicely
27-
class IncorrectModelError(Exception):
28-
def __init__(self, message):
29-
self.message = message
30-
super().__init__(self.message)
31-
32-
3325
def print_bad_model_msg(cause):
3426
print(f"{cause}{bad_model_msg}")
3527

3628

37-
def check_git_installed():
29+
def run_and_exit_with_error(cmd, error_msg, enable_error_output=True):
3830
try:
39-
subprocess.run(["git", "--version"]).check_returncode()
40-
except:
41-
print("Git is not installed or not found in your PATH.")
42-
print("Please install Git from https://git-scm.com/downloads and try again.")
31+
if enable_error_output:
32+
subprocess.run(
33+
cmd,
34+
stderr=subprocess.STDOUT,
35+
stdout=subprocess.PIPE,
36+
universal_newlines=True,
37+
).check_returncode()
38+
else:
39+
subprocess.run(cmd).check_returncode()
40+
except subprocess.CalledProcessError as e:
41+
print(error_msg)
42+
43+
if enable_error_output:
44+
print(e.stdout)
45+
4346
sys.exit(1)
4447

4548

49+
def check_git_installed():
50+
run_and_exit_with_error(
51+
["git", "--version"],
52+
"""Git is not installed or not found in your PATH.
53+
Please install Git from https://git-scm.com/downloads and try again.""",
54+
)
55+
56+
4657
def check_or_clone_rockchip_repo(repo_url, repo_name=ultralytics_default_folder_name):
4758
if os.path.exists(repo_name):
4859
print(
4960
f'Existing Rockchip repo "{repo_name}" detected, skipping installation...'
5061
)
5162
else:
5263
print(f'Cloning Rockchip repo to "{repo_name}"')
53-
try:
54-
subprocess.run(["git", "clone", repo_url, repo_name]).check_returncode()
55-
except subprocess.CalledProcessError as e:
56-
print("Failed to clone Rockchip repo, see error output below")
57-
print(e.output)
58-
sys.exit(1)
64+
run_and_exit_with_error(
65+
["git", "clone", repo_url, repo_name],
66+
"Failed to clone Rockchip repo, please see error output",
67+
)
5968

6069

6170
def run_pip_install_or_else_exit(args):
6271
print("Running pip install...")
63-
64-
try:
65-
subprocess.run(["pip", "install"] + args).check_returncode()
66-
except subprocess.CalledProcessError as e:
67-
print("Pip install rockchip repo failed, see error output")
68-
print(e.output)
69-
sys.exit(1)
72+
run_and_exit_with_error(
73+
["pip", "install"] + args,
74+
"Pip install rockchip repo failed, please see error output",
75+
)
7076

7177

7278
def run_onnx_conversion_yolov5(model_path):
@@ -93,23 +99,22 @@ def run_onnx_conversion_yolov5(model_path):
9399
"--include",
94100
"onnx",
95101
],
96-
capture_output=True,
97-
text=True,
102+
stderr=subprocess.STDOUT,
103+
stdout=subprocess.PIPE,
104+
universal_newlines=True,
98105
).check_returncode()
99106
except subprocess.CalledProcessError as e:
100-
print("Failed to run YOLOv5 export, see output below")
101-
output_string = (e.stdout or "") + (e.stderr or "")
102-
print(output_string)
107+
print("Failed to run YOLOv5 export, please see error output")
103108

104-
if "ModuleNotFoundError" in output_string and "ultralytics" in output_string:
109+
if "ModuleNotFoundError" in e.stdout and "ultralytics" in e.stdout:
105110
print_bad_model_msg(
106111
"It seems the YOLOv5 repo could not find an ultralytics installation."
107112
)
108-
elif (
109-
"AttributeError" in output_string
110-
and "_register_detect_seperate" in output_string
111-
):
113+
elif "AttributeError" in e.stdout and "_register_detect_seperate" in e.stdout:
112114
print_bad_model_msg("It seems that you received a model attribute error.")
115+
else:
116+
print("Unknown Error when converting:")
117+
print(e.stdout)
113118

114119
sys.exit(1)
115120

@@ -132,7 +137,7 @@ def run_onnx_conversion_no_anchor(model_path):
132137
"Ultralytics has detected that this model is a YOLOv5 model."
133138
)
134139
else:
135-
print(e)
140+
raise e
136141

137142
sys.exit(1)
138143

scripts/rknn-convert-tool/rknn_conversion.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
"# DO NOT modify the filenames\n",
3838
"scripts = [\n",
3939
" {\n",
40-
" \"url\": \"https://raw.githubusercontent.com/boomermath/photonvision_rknn_fork/refs/heads/rknn_conversion_tool/scripts/rknn-convert-tool/create_onnx.py\",\n",
40+
" \"url\": \"https://raw.githubusercontent.com/PhotonVision/photonvision/ba1c0db7e19db090ca04a8375255b00db2e0babd/scripts/rknn-convert-tool/create_onnx.py\",\n",
4141
" \"filename\": \"create_onnx.py\" # CREATE_ONNX_SCRIPT\n",
4242
" },\n",
4343
" {\n",
44-
" \"url\": \"https://raw.githubusercontent.com/boomermath/photonvision_rknn_fork/refs/heads/rknn_conversion_tool/scripts/rknn-convert-tool/create_rknn.py\",\n",
44+
" \"url\": \"https://raw.githubusercontent.com/PhotonVision/photonvision/ba1c0db7e19db090ca04a8375255b00db2e0babd/scripts/rknn-convert-tool/create_rknn.py\",\n",
4545
" \"filename\": \"create_rknn.py\" # CREATE_RKNN_SCRIPT\n",
4646
" }\n",
4747
"]\n",
@@ -254,15 +254,15 @@
254254
"| `--img_dir` (`-d`) | `str` (required) | Path to your image directory. This can either be a folder of images **or** a dataset folder with a `data.yaml`. |\n",
255255
"| `--model_path` (`-m`) | `str` (required) | Path to your YOLO ONNX model, created in Step 1. |\n",
256256
"| `--num_imgs` (`-ni`) | `int` (default: `300`) | Number of images to use for quantization calibration. |\n",
257-
"| `--disable_quantize` (`-dq`) | `bool` (default: `False`) | Set to `True` to skip quantization entirely, not recommended for performance. |\n",
257+
"| `--disable_quantize` (`-dq`) | `bool` (default: `False`) | Set to `True` to skip quantization entirely. Not recommended for performance, and should not be used for deployment on PhotonVision, which requires quantization. |\n",
258258
"| `--rknn_output` (`-o`) | `str` (default: `out.rknn`) | File path where the final RKNN model should be saved. |\n",
259259
"| `--img_dataset_txt` (`-ds`) | `str` (default: `imgs.txt`) | File path to store the list of images used during quantization. |\n",
260260
"| `--verbose` (`-vb`) | `bool` (default: `False`) | Enable detailed logging from the RKNN API during conversion. |\n",
261261
"\n",
262262
"\n",
263263
"##### *Notes*\n",
264264
"\n",
265-
"1. This script is designed for use with [PhotonVision](https://photonvision.org), and by default sets the target platform for RKNN conversion to `RK3588`, a chipset commonly found in many variants of the Orange Pi 5 series (e.g., Orange Pi 5, 5 Pro, 5 Plus, 5 Max, etc.). You may modify the `TARGET_PLATFORM` value in the `create_onnx.py` script to match your specific hardware or deployment requirements if necessary.\n",
265+
"1. This script is designed for use with [PhotonVision](https://photonvision.org), and by default sets the target platform for RKNN conversion to `RK3588`, a chipset commonly found in many variants of the Orange Pi 5 series (e.g., Orange Pi 5, 5 Pro, 5 Plus, 5 Max, etc.). You may modify the `DEFAULT_PLATFORM` value in the `create_rknn.py` script to match your specific hardware or deployment requirements if necessary.\n",
266266
"\n",
267267
"2. If you followed the Roboflow dataset download instructions from the previous section, the dataset will have been extracted to your **current working directory**. In that case, you can simply set `--img_dir` to \"`.`\" to reference the current directory."
268268
]

0 commit comments

Comments
 (0)