Skip to content

Instantly share code, notes, and snippets.

@vuiseng9
Forked from daniil-lyakhov/inspect_ov_ir_weights.py
Created February 15, 2023 20:05
Show Gist options
  • Save vuiseng9/bbbdb097b4a4d3a12e75e081b8384d21 to your computer and use it in GitHub Desktop.
Save vuiseng9/bbbdb097b4a4d3a12e75e081b8384d21 to your computer and use it in GitHub Desktop.
Way to inspect OpenVino IR model weights (openvino==2022.1.0)
# Openvino==2022.1.0
import sys
from openvino.runtime import Core
DELIMITER = ' | '
if len(sys.argv) < 3:
print("Please provide path to model xml file as a first arg and"
" path to output text file to dump model constants.")
exit()
ie = Core()
model = ie.read_model(model=sys.argv[1])
with open(sys.argv[2], 'w') as out:
for op in model.get_ordered_ops():
if 'constant' in str(op.get_type_info()).lower():
out.write(op.get_name() + DELIMITER + str(op.get_output_shape(0)) +\
DELIMITER + str(op.get_vector()) + '\n')
print('Done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment