Untitled

 avatar
user_9286359
plain_text
17 days ago
898 B
5
Indexable
import onnxruntime as ort
import numpy as np

# Path to the ONNX model
onnx_path = "deep_conv_net_no_pooling.onnx"

# Load the ONNX model
session = ort.InferenceSession(onnx_path)

# Generate random input matching the model's input shape (batch size 1, 3 channels, 64x64 image)
input_shape = (1, 3, 64, 64)
random_input = np.random.rand(*input_shape).astype(np.float32)

# Get the model's input and output names
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name

# Pass the random input through the ONNX model
output = session.run([output_name], {input_name: random_input})[0]

# Save the input to a raw file
input_file = "input.raw"
random_input.tofile(input_file)

# Save the output to a raw file
output_file = "output.raw"
output.tofile(output_file)

print(f"Random input has been saved to {input_file}")
print(f"Model output has been saved to {output_file}")
Leave a Comment