Luigi
commited on
Commit
•
e4e03fd
1
Parent(s):
bd45a81
Bugfix: correct batch dimension fixation then regenerate ONNX models
Browse filesBatch dimension has been fixed properly following the guide below
https://onnxruntime.ai/docs/tutorials/mobile/helpers/make-dynamic-shape-fixed.html
- convert_to_fp16_all.py +35 -0
- fix_batch_dimension.py +0 -35
- fix_batch_dimension_all.sh +3 -3
- rtmo-l.fp16.onnx +2 -2
- rtmo-l.fp16_batch1.onnx +2 -2
- rtmo-l.fp16_batch2.onnx +2 -2
- rtmo-l.fp16_batch4.onnx +2 -2
- rtmo-l_batch1.onnx +2 -2
- rtmo-l_batch2.onnx +2 -2
- rtmo-l_batch4.onnx +2 -2
- rtmo-m.fp16.onnx +2 -2
- rtmo-m.fp16_batch1.onnx +2 -2
- rtmo-m.fp16_batch2.onnx +2 -2
- rtmo-m.fp16_batch4.onnx +2 -2
- rtmo-m_batch1.onnx +2 -2
- rtmo-m_batch2.onnx +2 -2
- rtmo-m_batch4.onnx +2 -2
- rtmo-s.fp16.onnx +2 -2
- rtmo-s.fp16_batch1.onnx +2 -2
- rtmo-s.fp16_batch2.onnx +2 -2
- rtmo-s.fp16_batch4.onnx +2 -2
- rtmo-s_batch1.onnx +2 -2
- rtmo-s_batch2.onnx +2 -2
- rtmo-s_batch4.onnx +2 -2
- rtmo-t.fp16.onnx +2 -2
- rtmo-t.fp16_batch1.onnx +2 -2
- rtmo-t.fp16_batch2.onnx +2 -2
- rtmo-t.fp16_batch4.onnx +2 -2
- rtmo-t_batch1.onnx +2 -2
- rtmo-t_batch2.onnx +2 -2
- rtmo-t_batch4.onnx +2 -2
convert_to_fp16_all.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
|
4 |
+
def convert_onnx_to_fp16_corrected(input_dir):
|
5 |
+
# List all files in the input directory
|
6 |
+
files = os.listdir(input_dir)
|
7 |
+
|
8 |
+
# Filter out files with the .onnx extension
|
9 |
+
onnx_files = [file for file in files if file.endswith('.onnx')]
|
10 |
+
|
11 |
+
# Iterate over each ONNX file to convert it to FP16
|
12 |
+
for onnx_file in onnx_files:
|
13 |
+
# Split the file name to insert '.fp16' before the last underscore
|
14 |
+
parts = onnx_file.rsplit('_', 1)
|
15 |
+
if len(parts) == 2:
|
16 |
+
# If there is at least one underscore, insert '.fp16' before the last part
|
17 |
+
output_model_name = f"{parts[0]}.fp16_{parts[1]}"
|
18 |
+
else:
|
19 |
+
# If there's no underscore, just replace '.onnx' with '.fp16.onnx'
|
20 |
+
output_model_name = onnx_file.replace('.onnx', '.fp16.onnx')
|
21 |
+
|
22 |
+
# Construct the command to run the conversion script
|
23 |
+
command = [
|
24 |
+
'python3', 'convert_to_fp16.py',
|
25 |
+
'--input_model', os.path.join(input_dir, onnx_file),
|
26 |
+
'--output_model', os.path.join(input_dir, output_model_name)
|
27 |
+
]
|
28 |
+
|
29 |
+
# Execute the command
|
30 |
+
subprocess.run(command, check=True)
|
31 |
+
|
32 |
+
if __name__ == '__main__':
|
33 |
+
# Assuming the current directory is the input directory
|
34 |
+
input_dir = os.getcwd()
|
35 |
+
convert_onnx_to_fp16_corrected(input_dir)
|
fix_batch_dimension.py
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
import argparse
|
2 |
-
import onnx
|
3 |
-
from onnx import numpy_helper
|
4 |
-
import numpy as np
|
5 |
-
|
6 |
-
def fix_batch_dimension(input_model_path, output_model_path, batch_size=1):
|
7 |
-
# Load the input ONNX model
|
8 |
-
model = onnx.load(input_model_path)
|
9 |
-
|
10 |
-
# Iterate through the model's inputs
|
11 |
-
for input_tensor in model.graph.input:
|
12 |
-
# Get the tensor shape
|
13 |
-
tensor_shape = input_tensor.type.tensor_type.shape
|
14 |
-
|
15 |
-
# Modify the batch dimension
|
16 |
-
if len(tensor_shape.dim) > 0:
|
17 |
-
tensor_shape.dim[0].dim_value = batch_size
|
18 |
-
|
19 |
-
# Save the modified model to the output path
|
20 |
-
onnx.save(model, output_model_path)
|
21 |
-
print(f"Model saved with updated batch size of {batch_size} to {output_model_path}")
|
22 |
-
|
23 |
-
if __name__ == "__main__":
|
24 |
-
# Setup command line arguments
|
25 |
-
parser = argparse.ArgumentParser(description="Fix batch dimension of an ONNX model.")
|
26 |
-
parser.add_argument("input_model_path", type=str, help="Path to the input ONNX model.")
|
27 |
-
parser.add_argument("output_model_path", type=str, help="Path to save the output ONNX model with fixed batch dimension.")
|
28 |
-
parser.add_argument("--batch_size", type=int, default=1, help="Value of batch size to assign (default is 1).")
|
29 |
-
|
30 |
-
# Parse arguments
|
31 |
-
args = parser.parse_args()
|
32 |
-
|
33 |
-
# Call the function to fix the batch dimension
|
34 |
-
fix_batch_dimension(args.input_model_path, args.output_model_path, args.batch_size)
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fix_batch_dimension_all.sh
CHANGED
@@ -5,15 +5,15 @@ for model in ./*.onnx; do
|
|
5 |
# Exclude processing any files that already have a batch size in their name
|
6 |
if [[ ! $model =~ _batch[0-9]+\.onnx$ ]]; then
|
7 |
# Process for batch size 1
|
8 |
-
|
9 |
echo "Generated ${model%.onnx}_batch1.onnx"
|
10 |
|
11 |
# Process for batch size 2
|
12 |
-
|
13 |
echo "Generated ${model%.onnx}_batch2.onnx"
|
14 |
|
15 |
# Process for batch size 4
|
16 |
-
|
17 |
echo "Generated ${model%.onnx}_batch4.onnx"
|
18 |
fi
|
19 |
done
|
|
|
5 |
# Exclude processing any files that already have a batch size in their name
|
6 |
if [[ ! $model =~ _batch[0-9]+\.onnx$ ]]; then
|
7 |
# Process for batch size 1
|
8 |
+
python3 -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param batch --dim_value 1 "$model" "${model%.onnx}_batch1.onnx"
|
9 |
echo "Generated ${model%.onnx}_batch1.onnx"
|
10 |
|
11 |
# Process for batch size 2
|
12 |
+
python3 -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param batch --dim_value 2 "$model" "${model%.onnx}_batch2.onnx"
|
13 |
echo "Generated ${model%.onnx}_batch2.onnx"
|
14 |
|
15 |
# Process for batch size 4
|
16 |
+
python3 -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param batch --dim_value 4 "$model" "${model%.onnx}_batch4.onnx"
|
17 |
echo "Generated ${model%.onnx}_batch4.onnx"
|
18 |
fi
|
19 |
done
|
rtmo-l.fp16.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ea87472539adf395a81f15035d0e6a0db530b22ddcc1775fd3f6847fceba7d4f
|
3 |
+
size 88035167
|
rtmo-l.fp16_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:644b8c4874bddef42b97b2ff2f2edaecd612b6f35897ceaaf6cc48caeac6a083
|
3 |
+
size 88032432
|
rtmo-l.fp16_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6d86819d5d382afcfe4d482bae5f620fbca8e5f52f0c79a6677c91b597e8f47c
|
3 |
+
size 88032398
|
rtmo-l.fp16_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:048cd749dcf87b644ce88c78ec656f63f25b47d00bc057507f95a5f5f059b770
|
3 |
+
size 88032398
|
rtmo-l_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:94b757af7c448fa4985aed100e6d1122ad3559d61ed81cc87751a85288f8a647
|
3 |
+
size 175938796
|
rtmo-l_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5d5d8632f9189dc1e46686c4427c0bbff624e2c8bdcaafbb7c13c31d7128dad1
|
3 |
+
size 175938796
|
rtmo-l_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1ea8088c6f24454d60e4af491c6b91f0a3dd97b928c87430143fe2dd3488f405
|
3 |
+
size 175938796
|
rtmo-m.fp16.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:509a805d124f6cb943405eb41a0c28bfb9ac1919631de63818abae7b3e41dfa5
|
3 |
+
size 44712954
|
rtmo-m.fp16_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9a9f8ea58642c7e738d8f6a1c35e54c97686225e694b287525efd72e32bc3e79
|
3 |
+
size 44710494
|
rtmo-m.fp16_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ba340136e48163fe0cfd507db6a7ad5c8549c4bd07df5581156468bea6942282
|
3 |
+
size 44710460
|
rtmo-m.fp16_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4437562c4dd81f5db334d753a389f550c7e00c1b65b3bbc12a20a68080db98f2
|
3 |
+
size 44710460
|
rtmo-m_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3d7113a12ec7fb313083e61fc5a3a83e3b694cb69b793c28004b5e0a2490cae8
|
3 |
+
size 89304396
|
rtmo-m_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d782e675967e88463a29996d57ff1fb59598e6a6d81c65cf4a92ad8dcfc00b74
|
3 |
+
size 89304396
|
rtmo-m_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:512041bcabede48cc202e20559d8f7a8d39a63890c5ba798d5fadaaefb5d33e9
|
3 |
+
size 89304396
|
rtmo-s.fp16.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5c237799c55a2393c1562164edbb36fbb61f946c87956b69ab522f2ecdb85db4
|
3 |
+
size 19879429
|
rtmo-s.fp16_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:91e95cc9145f6fe7605f6cb298d5f7836ce5e53b8c754e4fdb9a7e0458eadb29
|
3 |
+
size 19877304
|
rtmo-s.fp16_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8eca1f9f073d1310b1febdd0e5e620c37c2f5fdeda539191d80fb6710be5a2ac
|
3 |
+
size 19877270
|
rtmo-s.fp16_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:32d98c24db0874def5032726202b4bb067ea0445e3dd030fed9a5e1a2689285a
|
3 |
+
size 19877270
|
rtmo-s_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:948208e964af1fca8479e9114ff3eb914ea140cf75c75d97bf67c59bf6cbca43
|
3 |
+
size 39649220
|
rtmo-s_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:686f4b1c6975a3cf53b90583947be00ccbedef978f0bb2a7b3cb6dbdb8eaacd9
|
3 |
+
size 39649220
|
rtmo-s_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:05d78076b5dda52a03385f208a571a31795235c6cbad32dba4f20d0afd77c898
|
3 |
+
size 39649220
|
rtmo-t.fp16.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:29d0a7ee6da1eaa14509ce62deadbc6b7b16519486602394f6a19cfdaa607bb3
|
3 |
+
size 13741368
|
rtmo-t.fp16_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:611919fcc2202c06df67c8a2c7c08b2f81da2fb83f144215cc6fbb0bb8a9f2a5
|
3 |
+
size 13739243
|
rtmo-t.fp16_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:747804876024f0b7c474c65477f060124c7870cdd23c9db196a2d7d15cad0520
|
3 |
+
size 13739209
|
rtmo-t.fp16_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b321277a64f4062a7e502cc261b77e2503b9efc8d9b031c592032209845a2e47
|
3 |
+
size 13739209
|
rtmo-t_batch1.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e13642306c47ee0a29f48b99dcea2cecda8166123f838ccd1e85e8b884898517
|
3 |
+
size 27373389
|
rtmo-t_batch2.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8f2458615ee49aec6f4c7bc7ce1129fe82e0cbc388141670ccb42e06212d870d
|
3 |
+
size 27373389
|
rtmo-t_batch4.onnx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dd0aa5cffc9fe6cf829de801a3544a12e137e05f3ce9a0d196720c4de276d10f
|
3 |
+
size 27373389
|