@@ -24,6 +24,7 @@ SUPPORTED_MODELS=(
2424 " yolov8n-seg"
2525 " centerface"
2626 " hsemotion"
27+ " deeplabv3"
2728)
2829
2930if ! [[ " ${SUPPORTED_MODELS[*]} " =~ $MODEL ]]; then
@@ -320,147 +321,43 @@ fi
320321
321322if [[ " $MODEL " == " centerface" ]] || [[ " $MODEL " == " all" ]]; then
322323 MODEL_NAME=" centerface"
323- MODEL_PATH=" $MODELS_PATH /public/$MODEL_NAME /FP16/ $MODEL_NAME .xml"
324+ MODEL_PATH=" $MODELS_PATH /public/$MODEL_NAME /$MODEL_NAME .xml"
324325 MODEL_DIR=$( dirname " $MODEL_PATH " )
325- PREV_DIR=$MODELS_PATH
326326 if [ ! -f " $MODEL_PATH " ]; then
327327 echo " Downloading and converting: ${MODEL_PATH} "
328328 mkdir -p " $MODEL_DIR "
329329 cd " $MODEL_DIR "
330330 git clone https://github.com/Star-Clouds/CenterFace.git
331331 cd CenterFace/models/onnx
332332 ovc centerface.onnx --input " [1,3,768,1280]"
333- mv centerface.xml " $MODEL_PATH "
333+ mv centerface.xml " $MODEL_DIR "
334334 mv centerface.bin " $MODEL_DIR "
335335 cd ../../..
336336 rm -rf CenterFace
337- cd " $PREV_DIR "
338337 python3 - << EOF $MODEL_PATH
339- import xml.etree.ElementTree as ET
340- from xml.dom import minidom
341- import sys
342-
343- # Define the path to your XML file
344- xml_file_path = sys.argv[1]
345-
346- # Load the XML file
347- tree = ET.parse(xml_file_path)
348- root = tree.getroot()
349-
350- # Define the attributes to search for and the new names
351- layer_search_attributes = {'id': '438', 'name': '537/sink_port_0', 'type': 'Result', 'version': 'opset1'}
352- layer_new_name = 'heatmap/sink_port_0'
353-
354- port_search_attributes = {'id': '1', 'precision': 'FP32', 'names': '537'}
355- port_new_name = 'heatmap'
356-
357- # Update 'layer' elements
358- for layer in root.findall(".//layer[@id='{}'][@name='{}'][@type='{}'][@version='{}']".format(
359- layer_search_attributes['id'],
360- layer_search_attributes['name'],
361- layer_search_attributes['type'],
362- layer_search_attributes['version'])):
363- layer.set('name', layer_new_name)
364-
365- # Update 'port' elements
366- for port in root.findall(".//port[@id='{}'][@precision='{}'][@names='{}']".format(
367- port_search_attributes['id'],
368- port_search_attributes['precision'],
369- port_search_attributes['names'])):
370- port.set('names', port_new_name)
371-
372- # Define the attributes to search for and the new names
373- layer_search_attributes = {'id': '430', 'name': '538/sink_port_0', 'type': 'Result', 'version': 'opset1'}
374- layer_new_name = 'scale/sink_port_0'
375-
376- port_search_attributes = {'id': '2', 'precision': 'FP32', 'names': '538'}
377- port_new_name = 'scale'
378-
379- # Update 'layer' elements
380- for layer in root.findall(".//layer[@id='{}'][@name='{}'][@type='{}'][@version='{}']".format(
381- layer_search_attributes['id'],
382- layer_search_attributes['name'],
383- layer_search_attributes['type'],
384- layer_search_attributes['version'])):
385- layer.set('name', layer_new_name)
386-
387- # Update 'port' elements
388- for port in root.findall(".//port[@id='{}'][@precision='{}'][@names='{}']".format(
389- port_search_attributes['id'],
390- port_search_attributes['precision'],
391- port_search_attributes['names'])):
392- port.set('names', port_new_name)
393-
394- # Define the attributes to search for and the new names
395- layer_search_attributes = {'id': '423', 'name': '539/sink_port_0', 'type': 'Result', 'version': 'opset1'}
396- layer_new_name = 'offset/sink_port_0'
397-
398- port_search_attributes = {'id': '2', 'precision': 'FP32', 'names': '539'}
399- port_new_name = 'offset'
400-
401- # Update 'layer' elements
402- for layer in root.findall(".//layer[@id='{}'][@name='{}'][@type='{}'][@version='{}']".format(
403- layer_search_attributes['id'],
404- layer_search_attributes['name'],
405- layer_search_attributes['type'],
406- layer_search_attributes['version'])):
407- layer.set('name', layer_new_name)
408-
409- # Update 'port' elements
410- for port in root.findall(".//port[@id='{}'][@precision='{}'][@names='{}']".format(
411- port_search_attributes['id'],
412- port_search_attributes['precision'],
413- port_search_attributes['names'])):
414- port.set('names', port_new_name)
415-
416- # Define the attributes to search for and the new names
417- layer_search_attributes = {'id': '416', 'name': '540/sink_port_0', 'type': 'Result', 'version': 'opset1'}
418- layer_new_name = 'landmarks/sink_port_0'
419-
420- port_search_attributes = {'id': '2', 'precision': 'FP32', 'names': '540'}
421- port_new_name = 'landmarks'
422-
423- # Update 'layer' elements
424- for layer in root.findall(".//layer[@id='{}'][@name='{}'][@type='{}'][@version='{}']".format(
425- layer_search_attributes['id'],
426- layer_search_attributes['name'],
427- layer_search_attributes['type'],
428- layer_search_attributes['version'])):
429- layer.set('name', layer_new_name)
430-
431- # Update 'port' elements
432- for port in root.findall(".//port[@id='{}'][@precision='{}'][@names='{}']".format(
433- port_search_attributes['id'],
434- port_search_attributes['precision'],
435- port_search_attributes['names'])):
436- port.set('names', port_new_name)
437-
438-
439- model_info = ET.Element('model_info')
440- confidence_threshold = ET.SubElement(model_info, 'confidence_threshold', {'value': '0.55'})
441- iou_threshold = ET.SubElement(model_info, 'iou_threshold', {'value': '0.5'})
442- model_type = ET.SubElement(model_info, 'model_type', {'value': 'centerface'})
443-
444- rt_info_elements = root.findall('.//rt_info[Runtime_version]')
445- rt_info = rt_info_elements[0]
446- rt_info.append(model_info)
447-
448- # Function to pretty print XML with proper indentation
449- def prettify(elem):
450- """Return a pretty-printed XML string for the Element."""
451- rough_string = ET.tostring(elem, 'utf-8')
452- reparsed = minidom.parseString(rough_string)
453- pretty_xml = reparsed.toprettyxml(indent="\t")
454- pretty_xml = '\n'.join([line for line in pretty_xml.split('\n') if line.strip()])
455- return pretty_xml
456-
457- # Get the pretty-printed XML string
458- pretty_xml = prettify(root)
459-
460- #tree.write(xml_file_path, xml_declaration=True)
461- # Write the modified and pretty-printed XML back to the file
462- with open(xml_file_path, 'w', encoding='utf-8') as xml_file:
463- xml_file.write(pretty_xml)
338+ import openvino
339+ import sys, os
340+
341+ orig_model_path = sys.argv[1]
342+
343+ core = openvino.Core()
344+ ov_model = core.read_model(model=orig_model_path)
345+
346+ ov_model.output(0).set_names({"heatmap"})
347+ ov_model.output(1).set_names({"scale"})
348+ ov_model.output(2).set_names({"offset"})
349+ ov_model.output(3).set_names({"landmarks"})
350+
351+ ov_model.set_rt_info("centerface", ['model_info', 'model_type'])
352+ ov_model.set_rt_info("0.55", ['model_info', 'confidence_threshold'])
353+ ov_model.set_rt_info("0.5", ['model_info', 'iou_threshold'])
354+
355+ print(ov_model)
356+
357+ openvino.save_model(ov_model, './FP32/' + 'centerface.xml', compress_to_fp16=False)
358+ openvino.save_model(ov_model, './FP16/' + 'centerface.xml', compress_to_fp16=True)
359+ os.remove('centerface.xml')
360+ os.remove('centerface.bin')
464361EOF
465362
466363 fi
@@ -486,4 +383,34 @@ if [ "$MODEL" == "hsemotion" ] || [ "$MODEL" == "all" ]; then
486383 python3 - << EOF $MODEL_PATH
487384EOF
488385 fi
489- fi
386+ fi
387+
388+ if [[ " $MODEL " == " deeplabv3" ]] || [[ " $MODEL " == " all" ]]; then
389+ MODEL_NAME=" deeplabv3"
390+ MODEL_PATH=" $MODELS_PATH /public/$MODEL_NAME /FP32/$MODEL_NAME .xml"
391+ if [ ! -f " $MODEL_PATH " ]; then
392+ mkdir -p " $MODELS_PATH "
393+ cd " $MODELS_PATH "
394+ echo " Downloading and converting: ${MODEL_PATH} "
395+ omz_downloader --name " $MODEL_NAME "
396+ omz_converter --name " $MODEL_NAME "
397+ cd " public/$MODEL_NAME "
398+ python3 - " $MODEL_PATH " << EOF
399+ import openvino
400+ import sys, os, shutil
401+
402+ orig_model_path = sys.argv[1]
403+
404+ core = openvino.Core()
405+ ov_model = core.read_model(model=orig_model_path)
406+ ov_model.set_rt_info("semantic_mask", ['model_info', 'model_type'])
407+
408+ print(ov_model)
409+
410+ shutil.rmtree('FP32')
411+ shutil.rmtree('FP16')
412+ openvino.save_model(ov_model, './FP32/' + 'deeplabv3.xml', compress_to_fp16=False)
413+ openvino.save_model(ov_model, './FP16/' + 'deeplabv3.xml', compress_to_fp16=True)
414+ EOF
415+ fi
416+ fi
0 commit comments