meinvirgos commited on
Commit
76c75ac
·
verified ·
1 Parent(s): bd190ce

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -1
README.md CHANGED
@@ -1,3 +1,47 @@
1
  ---
2
  license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ ---
4
+
5
+ ## I made the dynamic the model:
6
+ face_detection_yunet_2023mar.onnx
7
+ https://github.com/opencv/opencv_zoo/blob/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx
8
+
9
+
10
+ ## The way y Made it dynamic:
11
+
12
+ ```
13
+ # Initialization
14
+ !pip install onnx==1.16 | tail -n 1
15
+ !pip install onnxruntime==1.16.3 | tail -n 1
16
+
17
+ import onnx
18
+ import onnxruntime as ort
19
+ from onnx.tools import update_model_dims
20
+
21
+ # We read the model
22
+ onnx_model_path = "face_detection_yunet_2023mar.onnx"
23
+ model = onnx.load(onnx_model_path)
24
+ ## Vemos los dims
25
+ input_dims = {i.name: [d.dim_value for d in i.type.tensor_type.shape.dim] for i in model.graph.input}
26
+ output_dims = {o.name: [d.dim_value for d in o.type.tensor_type.shape.dim] for o in model.graph.output}
27
+ print(input_dims)
28
+ print(output_dims)
29
+
30
+ # Debug: we create a session (not needed)
31
+ ort.set_default_logger_severity(3)
32
+ ort_session = ort.InferenceSession(onnx_model_path, providers=['CPUExecutionProvider'])
33
+ print("Original Input Shapes:")
34
+ for i in ort_session.get_inputs():
35
+ print(f"Input Name: {i.name}, Shape: {i.shape}")
36
+
37
+ # Here we made the model dynamic. The character "N" means the input is dynamic
38
+ input_dims['input'] = [1, 3, "N", "N"]
39
+ updated_model = update_model_dims.update_inputs_outputs_dims(model, input_dims, output_dims)
40
+
41
+ # Finally we save the dynamic model
42
+ import os
43
+ os.mkdir("./save_dir")
44
+ dynamic_model_path = "./save_dir/face_detection_yunet_2023mar_dynamic.onnx"
45
+ onnx.save(updated_model, dynamic_model_path)
46
+
47
+ ```