Fix FP16 models having poor accuracy
Browse filesKeep only dynamic-batch ONNX models, because
it's compatible with TRT EP as well as we've just verified.
- convert_to_fp16.py +1 -1
- demo.sh +1 -1
- demo_batch.sh +1 -1
- fix_input_batch_size.py +0 -31
- fix_input_batch_size_all.sh +0 -38
- rtmo-l.fp16.onnx +2 -2
- rtmo-l.fp16_batch1.onnx +0 -3
- rtmo-l.fp16_batch2.onnx +0 -3
- rtmo-l.fp16_batch4.onnx +0 -3
- rtmo-l_batch1.onnx +0 -3
- rtmo-l_batch2.onnx +0 -3
- rtmo-l_batch4.onnx +0 -3
- rtmo-m.fp16.onnx +2 -2
- rtmo-m.fp16_batch1.onnx +0 -3
- rtmo-m.fp16_batch2.onnx +0 -3
- rtmo-m.fp16_batch4.onnx +0 -3
- rtmo-m_batch1.onnx +0 -3
- rtmo-m_batch2.onnx +0 -3
- rtmo-m_batch4.onnx +0 -3
- rtmo-s.fp16.onnx +2 -2
- rtmo-s.fp16_batch1.onnx +0 -3
- rtmo-s.fp16_batch2.onnx +0 -3
- rtmo-s.fp16_batch4.onnx +0 -3
- rtmo-s_batch1.onnx +0 -3
- rtmo-s_batch2.onnx +0 -3
- rtmo-s_batch4.onnx +0 -3
- rtmo-t.fp16.onnx +2 -2
- rtmo-t.fp16_batch1.onnx +0 -3
- rtmo-t.fp16_batch2.onnx +0 -3
- rtmo-t.fp16_batch4.onnx +0 -3
- rtmo-t_batch1.onnx +0 -3
- rtmo-t_batch2.onnx +0 -3
- rtmo-t_batch4.onnx +0 -3
convert_to_fp16.py
CHANGED
@@ -17,7 +17,7 @@ def main():
|
|
17 |
|
18 |
# Convert model from Float32 to Float16
|
19 |
print("Converting model...")
|
20 |
-
new_onnx_model = convert_float_to_float16(onnx_model, keep_io_types=True)
|
21 |
|
22 |
# Save the converted model
|
23 |
print(f"Saving converted model to {args.output_model}")
|
|
|
17 |
|
18 |
# Convert model from Float32 to Float16
|
19 |
print("Converting model...")
|
20 |
+
new_onnx_model = convert_float_to_float16(onnx_model, min_positive_val=1e-7, max_finite_val=1e4, keep_io_types=True)
|
21 |
|
22 |
# Save the converted model
|
23 |
print(f"Saving converted model to {args.output_model}")
|
demo.sh
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
#!/bin/sh
|
2 |
-
python3 rtmo_demo.py ./video rtmo-s.
|
|
|
1 |
#!/bin/sh
|
2 |
+
python3 rtmo_demo.py ./video rtmo-s.fp16.onnx
|
demo_batch.sh
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
#!/bin/sh
|
2 |
-
python3 rtmo_demo_batch.py ./video rtmo-
|
|
|
1 |
#!/bin/sh
|
2 |
+
python3 rtmo_demo_batch.py ./video rtmo-t.fp16.onnx 4
|
fix_input_batch_size.py
DELETED
@@ -1,31 +0,0 @@
|
|
1 |
-
import onnx
|
2 |
-
import argparse
|
3 |
-
|
4 |
-
def modify_batch_size(input_model_path, output_model_path, batch_size):
|
5 |
-
# Load the ONNX model
|
6 |
-
model = onnx.load(input_model_path)
|
7 |
-
|
8 |
-
# Modify the batch size of the first input tensor
|
9 |
-
input_tensor = model.graph.input[0]
|
10 |
-
input_tensor.type.tensor_type.shape.dim[0].dim_value = batch_size
|
11 |
-
|
12 |
-
# Save the modified model
|
13 |
-
onnx.save(model, output_model_path)
|
14 |
-
print(f"Modified model saved to {output_model_path}")
|
15 |
-
|
16 |
-
if __name__ == "__main__":
|
17 |
-
# Parse command line arguments
|
18 |
-
parser = argparse.ArgumentParser(description="Modify the batch size of the first input tensor of an ONNX model.")
|
19 |
-
parser.add_argument("input_model_path", type=str, help="Path to the input ONNX model file.")
|
20 |
-
parser.add_argument("output_model_path", type=str, help="Path to save the modified ONNX model file.")
|
21 |
-
parser.add_argument("--batch_size", type=int, help="Desired batch size for the first input tensor.")
|
22 |
-
|
23 |
-
args = parser.parse_args()
|
24 |
-
|
25 |
-
# Ensure that the batch_size argument has been provided
|
26 |
-
if args.batch_size is None:
|
27 |
-
raise ValueError("Please specify the new batch size for the input tensor using --batch_size.")
|
28 |
-
|
29 |
-
# Call the function to modify the model's batch size
|
30 |
-
modify_batch_size(args.input_model_path, args.output_model_path, args.batch_size)
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fix_input_batch_size_all.sh
DELETED
@@ -1,38 +0,0 @@
|
|
1 |
-
#!/bin/bash
|
2 |
-
|
3 |
-
# Directory containing the original ONNX models
|
4 |
-
MODEL_DIR="."
|
5 |
-
|
6 |
-
# Directory to save the modified ONNX models
|
7 |
-
OUTPUT_DIR="."
|
8 |
-
|
9 |
-
# Ensure output directory exists
|
10 |
-
mkdir -p "$OUTPUT_DIR"
|
11 |
-
|
12 |
-
# Path to the Python script
|
13 |
-
PYTHON_SCRIPT="fix_input_batch_size.py"
|
14 |
-
|
15 |
-
# Loop through each ONNX model in the directory
|
16 |
-
for model in "$MODEL_DIR"/*.onnx; do
|
17 |
-
echo "Processing $model..."
|
18 |
-
filename=$(basename -- "$model")
|
19 |
-
base="${filename%.*}"
|
20 |
-
|
21 |
-
# Generate models with batch size 1
|
22 |
-
output_model_1="$OUTPUT_DIR/${base}_batch1.onnx"
|
23 |
-
python "$PYTHON_SCRIPT" "$model" "$output_model_1" --batch_size 1
|
24 |
-
echo "Generated model with batch size 1: $output_model_1"
|
25 |
-
|
26 |
-
# Generate models with batch size 2
|
27 |
-
output_model_2="$OUTPUT_DIR/${base}_batch2.onnx"
|
28 |
-
python "$PYTHON_SCRIPT" "$model" "$output_model_2" --batch_size 1
|
29 |
-
echo "Generated model with batch size 2: $output_model_2"
|
30 |
-
|
31 |
-
# Generate models with batch size 4
|
32 |
-
output_model_4="$OUTPUT_DIR/${base}_batch4.onnx"
|
33 |
-
python "$PYTHON_SCRIPT" "$model" "$output_model_4" --batch_size 4
|
34 |
-
echo "Generated model with batch size 4: $output_model_4"
|
35 |
-
done
|
36 |
-
|
37 |
-
echo "Batch size modification complete."
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:661897e1e8cb15a9747ef0a6d86238c205e494f4861fced708d975fa54ab9a5b
|
3 |
+
size 88036653
|
rtmo-l.fp16_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:c9c9fee334086aec0482b348cb74a61bc144c0a9bd23550ebdc05001f2ca86d9
|
3 |
-
size 88036970
|
|
|
|
|
|
|
|
rtmo-l.fp16_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:c9c9fee334086aec0482b348cb74a61bc144c0a9bd23550ebdc05001f2ca86d9
|
3 |
-
size 88036970
|
|
|
|
|
|
|
|
rtmo-l.fp16_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:0f2098f33be14598dee33f0203a6fa3ed72e80159b691e1c664ef9869a7ec215
|
3 |
-
size 88036970
|
|
|
|
|
|
|
|
rtmo-l_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:eb610ad52d5090881bbb5f7b8720773846a65257ddda8f7cba29d848688d8fb6
|
3 |
-
size 175941846
|
|
|
|
|
|
|
|
rtmo-l_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:eb610ad52d5090881bbb5f7b8720773846a65257ddda8f7cba29d848688d8fb6
|
3 |
-
size 175941846
|
|
|
|
|
|
|
|
rtmo-l_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:c83886f33bba6bda437ce9fafe2b395d33993f1bfc00a8b1f27f3a094ae69ef1
|
3 |
-
size 175941846
|
|
|
|
|
|
|
|
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:3803642557800cf7123088074513221743bbbda1f875337408925c2cf55b36d6
|
3 |
+
size 44714440
|
rtmo-m.fp16_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:59d4a54c134dabeecbe58597b323be6e31ae500745476f2f276e38a2b03c4ed9
|
3 |
-
size 44714757
|
|
|
|
|
|
|
|
rtmo-m.fp16_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:59d4a54c134dabeecbe58597b323be6e31ae500745476f2f276e38a2b03c4ed9
|
3 |
-
size 44714757
|
|
|
|
|
|
|
|
rtmo-m.fp16_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:a91b7825665588667ed4aff965327b3b7f759ea449c187e17b5141c1c6756fde
|
3 |
-
size 44714757
|
|
|
|
|
|
|
|
rtmo-m_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:26d4434838a4ff158f6cdcab421a08ddd82900f3fcc41ec0921d7245e2c5818d
|
3 |
-
size 89307171
|
|
|
|
|
|
|
|
rtmo-m_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:26d4434838a4ff158f6cdcab421a08ddd82900f3fcc41ec0921d7245e2c5818d
|
3 |
-
size 89307171
|
|
|
|
|
|
|
|
rtmo-m_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:9a263fb2e9310073d147fe1aeac80762c4213be1bcd84be689b0973a61c36efa
|
3 |
-
size 89307171
|
|
|
|
|
|
|
|
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:8e608f9f14608fa9b868e9aa320b9066fd37e1afa90c41e5513df9ae27684bca
|
3 |
+
size 19880915
|
rtmo-s.fp16_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:79491abe6e66eaa4277a29ff7d3c2b47276d2d0ef7fd29f4f3df492f2f09000f
|
3 |
-
size 19881232
|
|
|
|
|
|
|
|
rtmo-s.fp16_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:79491abe6e66eaa4277a29ff7d3c2b47276d2d0ef7fd29f4f3df492f2f09000f
|
3 |
-
size 19881232
|
|
|
|
|
|
|
|
rtmo-s.fp16_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:c4e649783597b0e5476f8bc3c97f73d8896b3e8e282849ad2e4495c13081b364
|
3 |
-
size 19881232
|
|
|
|
|
|
|
|
rtmo-s_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:699704b00b06b791f31d6b15a7e4bb4abd57f8dab1a60c58fc22490d4ab55c93
|
3 |
-
size 39651660
|
|
|
|
|
|
|
|
rtmo-s_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:699704b00b06b791f31d6b15a7e4bb4abd57f8dab1a60c58fc22490d4ab55c93
|
3 |
-
size 39651660
|
|
|
|
|
|
|
|
rtmo-s_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:f5d2304570931d9351d10f2940311f0dd8d774e92cc0ec88256d1fcfe4ee796c
|
3 |
-
size 39651660
|
|
|
|
|
|
|
|
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:5973ae0e3ac5feb91f28d113d5ca76be0f59aea137373e6231893b8853eba0e8
|
3 |
+
size 13742854
|
rtmo-t.fp16_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:af20fe3bc33039069697e5567262dcf79c9d47b502be5bc7b5a06460e730db03
|
3 |
-
size 13743171
|
|
|
|
|
|
|
|
rtmo-t.fp16_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:af20fe3bc33039069697e5567262dcf79c9d47b502be5bc7b5a06460e730db03
|
3 |
-
size 13743171
|
|
|
|
|
|
|
|
rtmo-t.fp16_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:3a7c066d130573f97dfdc8eb508a54efa56580c5f54003473c3799419f8b3bba
|
3 |
-
size 13743171
|
|
|
|
|
|
|
|
rtmo-t_batch1.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:3493fc0b00118d937db56e3aa523799441e2f1a0f40753f15c8e34f0761c3c94
|
3 |
-
size 27375829
|
|
|
|
|
|
|
|
rtmo-t_batch2.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:3493fc0b00118d937db56e3aa523799441e2f1a0f40753f15c8e34f0761c3c94
|
3 |
-
size 27375829
|
|
|
|
|
|
|
|
rtmo-t_batch4.onnx
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:5024770899ee523e13a6f683a443c4c0820f90e17cdfe3985035466a4520f772
|
3 |
-
size 27375829
|
|
|
|
|
|
|
|