Untitled

 avatar
user_9286359
plain_text
17 days ago
821 B
3
Indexable
import onnxruntime as ort
import numpy as np

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

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

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

# Run 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