I made the dynamic the model:
face_detection_yunet_2023mar.onnx https://github.com/opencv/opencv_zoo/blob/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx
The way y Made it dynamic:
# Initialization
!pip install onnx==1.16 | tail -n 1
!pip install onnxruntime==1.16.3 | tail -n 1
import onnx
import onnxruntime as ort
from onnx.tools import update_model_dims
# We read the model
onnx_model_path = "face_detection_yunet_2023mar.onnx"
model = onnx.load(onnx_model_path)
## Vemos los dims
input_dims = {i.name: [d.dim_value for d in i.type.tensor_type.shape.dim] for i in model.graph.input}
output_dims = {o.name: [d.dim_value for d in o.type.tensor_type.shape.dim] for o in model.graph.output}
print(input_dims)
print(output_dims)
# Debug: we create a session (not needed)
ort.set_default_logger_severity(3)
ort_session = ort.InferenceSession(onnx_model_path, providers=['CPUExecutionProvider'])
print("Original Input Shapes:")
for i in ort_session.get_inputs():
print(f"Input Name: {i.name}, Shape: {i.shape}")
# Here we made the model dynamic. The character "N" means the input is dynamic
input_dims['input'] = [1, 3, "N", "N"]
updated_model = update_model_dims.update_inputs_outputs_dims(model, input_dims, output_dims)
# Finally we save the dynamic model
import os
os.mkdir("./save_dir")
dynamic_model_path = "./save_dir/face_detection_yunet_2023mar_dynamic.onnx"
onnx.save(updated_model, dynamic_model_path)
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
๐
Ask for provider support