Open2
OpenVINO の XML から特定のOPを抹消するスクリプトの一例
make_openvino_xml_anchor_remove_fp32.py
import xml.etree.ElementTree as ET
from argparse import ArgumentParser
REMOVE_CONST_NAMES = [
'anchor_grid0',
'anchor_grid0/sink_port_0',
'anchor_grid1',
'anchor_grid1/sink_port_0',
'anchor_grid2',
'anchor_grid2/sink_port_0',
]
REMOVE_EDGE_LAYER_IDS = [
'976',
'974',
'972',
]
def main(input_file_path, output_file_path):
tree = ET.parse(input_file_path)
root = tree.getroot()
for child in root:
if child.tag == 'layers':
layers = child
print(f'layers before: {len(layers)}')
_ = [layers.remove(layer) for layer in layers[:] if layer.attrib['name'] in REMOVE_CONST_NAMES]
print(f'layers after : {len(layers)}')
elif child.tag == 'edges':
edges = child
print(f'edges before: {len(edges)}')
_ = [edges.remove(edge) for edge in edges[:] if edge.attrib['from-layer'] in REMOVE_EDGE_LAYER_IDS]
print(f'edges after : {len(edges)}')
tree.write(output_file_path, encoding='UTF-8')
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument(
'-if',
'--input_file_path',
type=str,
required=True,
help='INPUT OpenVINO XML file path',
)
parser.add_argument(
'-of',
'--output_file_path',
type=str,
required=True,
help='OUTPUT OpenVINO XML file path',
)
args = parser.parse_args()
input_file_path=args.input_file_path
output_file_path=args.output_file_path
main(input_file_path, output_file_path)
make_openvino_xml_anchor_remove_fp16.py
import xml.etree.ElementTree as ET
from argparse import ArgumentParser
REMOVE_CONST_NAMES = [
'anchor_grid0_compressed',
'anchor_grid0',
'anchor_grid0/sink_port_0',
'anchor_grid1_compressed',
'anchor_grid1',
'anchor_grid1/sink_port_0',
'anchor_grid2_compressed',
'anchor_grid2',
'anchor_grid2/sink_port_0',
]
REMOVE_EDGE_LAYER_IDS = [
'1291',
'1288',
'1285',
]
def main(input_file_path, output_file_path):
tree = ET.parse(input_file_path)
root = tree.getroot()
for child in root:
if child.tag == 'layers':
layers = child
print(f'layers before: {len(layers)}')
_ = [layers.remove(layer) for layer in layers[:] if layer.attrib['name'] in REMOVE_CONST_NAMES]
print(f'layers after : {len(layers)}')
elif child.tag == 'edges':
edges = child
print(f'edges before: {len(edges)}')
_ = [edges.remove(edge) for edge in edges[:] if edge.attrib['from-layer'] in REMOVE_EDGE_LAYER_IDS]
print(f'edges after : {len(edges)}')
tree.write(output_file_path, encoding='UTF-8')
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument(
'-if',
'--input_file_path',
type=str,
required=True,
help='INPUT OpenVINO XML file path',
)
parser.add_argument(
'-of',
'--output_file_path',
type=str,
required=True,
help='OUTPUT OpenVINO XML file path',
)
args = parser.parse_args()
input_file_path=args.input_file_path
output_file_path=args.output_file_path
main(input_file_path, output_file_path)