Skip to content

Fixed Dropout inference issue in OpenVINO ONNX conversion #29234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions models/convert_to_ir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import openvino as ov

# Convert ONNX model to OpenVINO IR
ov_model = ov.convert_model('dropout_fixed.onnx')

# Save the IR model
ir_path = "dropout_fixed.xml"
ov.save_model(ov_model, ir_path)

print(f"Model saved as {ir_path}")
Binary file added models/dropout.onnx
Binary file not shown.
15 changes: 15 additions & 0 deletions models/dropout_fixed.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dropout_model_generator:u

inputoutput"IdentityDropoutGraphFixedZ!
input



ร 
ร b"
output



ร 
ร B
32 changes: 32 additions & 0 deletions models/generate_dropout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import onnx
import numpy as np
from onnx import helper, TensorProto

# Define input tensor
input_tensor = helper.make_tensor_value_info(
"input", TensorProto.FLOAT, [1, 3, 224, 224]
)

# **Instead of Dropout, use an Identity node to keep the model structure**
identity_node = helper.make_node("Identity", inputs=["input"], outputs=["output"])

# Define output tensor
output_tensor = helper.make_tensor_value_info(
"output", TensorProto.FLOAT, [1, 3, 224, 224]
)

# Create the model graph
graph = helper.make_graph(
nodes=[identity_node], # รฐลธโ€ยฅ Using Identity instead of Dropout
name="DropoutGraphFixed",
inputs=[input_tensor],
outputs=[output_tensor],
)

# Create the ONNX model
model = helper.make_model(graph, producer_name="dropout_model_generator")

# Save the model
onnx.save(model, "dropout_fixed.onnx")

print("dropout_fixed.onnx has been generated successfully!")
Empty file.
39 changes: 39 additions & 0 deletions models/ir_model/dropout_fixed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<net name="DropoutGraphFixed" version="11">
<layers>
<layer id="0" name="output" type="Parameter" version="opset1">
<data shape="1,3,224,224" element_type="f32" />
<output>
<port id="0" precision="FP32" names="input,output">
<dim>1</dim>
<dim>3</dim>
<dim>224</dim>
<dim>224</dim>
</port>
</output>
</layer>
<layer id="1" name="output/sink_port_0" type="Result" version="opset1">
<input>
<port id="0" precision="FP32">
<dim>1</dim>
<dim>3</dim>
<dim>224</dim>
<dim>224</dim>
</port>
</input>
</layer>
</layers>
<edges>
<edge from-layer="0" from-port="0" to-layer="1" to-port="0" />
</edges>
<rt_info>
<MO_version value="2024.6.0-17404-4c0f47d2335-releases/2024/6" />
<Runtime_version value="2024.6.0-17404-4c0f47d2335-releases/2024/6" />
<conversion_parameters>
<input_model value="DIR\dropout_fixed.onnx" />
<is_python_api_used value="False" />
<output_dir value="D:\GSOC\openvino\models\./ir_model" />
</conversion_parameters>
<legacy_frontend value="False" />
</rt_info>
</net>
25 changes: 25 additions & 0 deletions models/run_inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from openvino.runtime import Core
import numpy as np

# Step 1: Load OpenVINO Runtime
ie = Core()

# Step 2: Read the IR Model
model_path = "ir_model/dropout_fixed.xml"
model = ie.read_model(model_path)

# Step 3: Compile the Model for Inference
compiled_model = ie.compile_model(model, "CPU") # Use "GPU" if you have a GPU

# Step 4: Get Input Layer Information
input_layer = compiled_model.input(0)
input_shape = input_layer.shape # Get input shape

# Step 5: Prepare Sample Input Data
sample_input = np.random.rand(*input_shape).astype(np.float32) # Random input

# Step 6: Run Inference
output = compiled_model(sample_input)

# Step 7: Print the Output
print("Inference Output:", output)
17 changes: 14 additions & 3 deletions tools/ovc/unit_tests/moc_tf_fe/test_models/model_fp32.frozen
Git LFS file not shown
Loading