Thanks @omria , I followed these steps
- I ran this code to print the output of the layers
import onnx model = onnx.load('/home/avinash/Downloads/yolov4.onnx') for node in model.graph.node: print(node.op_type,end=" ")
So it has few differences with the Hailo supported so i tried
`python3 -m onnxsim yolov4.onnx yolov4.onnx
Simplifying...
Finish! Here is the difference:
ββββββββββββββ³βββββββββββββββββ³βββββββββββββββββββ
β β Original Model β Simplified Model β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββ©
β Add β 95 β 95 β
β Cast β 6 β 6 β
β Concat β 18 β 18 β
β Constant β 231 β 230 β
β Conv β 110 β 110 β
β Exp β 72 β 72 β
β Gather β 3 β 3 β
β LeakyRelu β 35 β 35 β
β Log β 72 β 72 β
β MaxPool β 3 β 3 β
β Mul β 72 β 72 β
β Reshape β 4 β 3 β
β Resize β 2 β 2 β
β Shape β 5 β 5 β
β Sigmoid β 6 β 6 β
β Slice β 8 β 8 β
β Split β 3 β 3 β
β Tanh β 72 β 72 β
β Transpose β 4 β 4 β
β Model Size β 245.5MiB β 245.6MiB β
ββββββββββββββ΄βββββββββββββββββ΄βββββββββββββββββββ
`
So after this i checked the shape of model using this code
import onnx
model = onnx.load('yolov4.onnx')
input_names = [i.name for i in model.graph.input]
output_names = [o.name for o in model.graph.output]
print(f"Input names: {input_names}")
print(f"Output names: {output_names}")
# Get the shapes of the input tensors
input_shapes = {i.name: [dim.dim_value for dim in i.type.tensor_type.shape.dim] for i in model.graph.input}
# Print the input shapes
print("Input shapes:")
for input_name, shape in input_shapes.items():
print(f"{input_name}: {shape}")
So After this i ran this to check if there is dynamic shaping if yes then change that
import onnx
model = onnx.load("yolov4.onnx")
for tensor in model.graph.input:
if 'None' in str(tensor.type.tensor_type.shape.dim):
tensor.type.tensor_type.shape.dim[0].dim_value = 1 # Batch size of 1
onnx.save(model, "yolov4.onnx")
Atfter that Shape convert
import onnx
# Load the ONNX model
model = onnx.load('yolov4.onnx')
# Update the shape of each input tensor (in this case, set the batch size to 1)
for input_tensor in model.graph.input:
for dim in input_tensor.type.tensor_type.shape.dim:
if dim.dim_value == 0: # If batch size is dynamic (0)
dim.dim_value = 1 # Set batch size to 1 (or another fixed number)
# Save the updated model
onnx.save(model, 'yolov4.onnx')
After executing all this the shape,start_node ,End Node are
python3 shape.py
Input names: ['input_1:0']
Output names: ['Identity:0', 'Identity_1:0', 'Identity_2:0']
Input shapes:
input_1:0: [1, 416, 416, 3]
Before Shape Convert
python3 shape.py
Input names: ['input_1:0']
Output names: ['Identity:0', 'Identity_1:0', 'Identity_2:0']
Input shapes:
input_1:0: [0, 416, 416, 3]
But After doing all this iβm still getting error like this