Skip to content

Commit 0224f4b

Browse files
Merge pull request #1531 from openvinotoolkit/revert-1524-fix/kgeneral/rm_cpu_layer_check
Revert "fix #38545 remove CPU network layer check for py demos"
2 parents 2a94f0f + 3e33518 commit 0224f4b

File tree

9 files changed

+94
-6
lines changed

9 files changed

+94
-6
lines changed

demos/python_demos/asl_recognition_demo/asl_recognition_demo/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def __init__(self, model_path, device, ie_core, num_requests, output_shape=None)
3737
self.net = ie_core.read_network(model_path + ".xml", model_path + ".bin")
3838
assert len(self.net.input_info) == 1, "One input is expected"
3939

40+
supported_layers = ie_core.query_network(self.net, device)
41+
not_supported_layers = [l for l in self.net.layers.keys() if l not in supported_layers]
42+
if len(not_supported_layers) > 0:
43+
raise RuntimeError("Following layers are not supported by the {} plugin:\n {}"
44+
.format(device, ', '.join(not_supported_layers)))
45+
4046
self.exec_net = ie_core.load_network(network=self.net,
4147
device_name=device,
4248
num_requests=num_requests)

demos/python_demos/instance_segmentation_demo/instance_segmentation_demo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ def main():
133133
log.info('Loading network')
134134
net = ie.read_network(args.model, os.path.splitext(args.model)[0] + '.bin')
135135

136+
if 'CPU' in args.device:
137+
supported_layers = ie.query_network(net, 'CPU')
138+
not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
139+
if len(not_supported_layers) != 0:
140+
log.error('Following layers are not supported by the plugin for specified device {}:\n {}'.
141+
format(args.device, ', '.join(not_supported_layers)))
142+
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
143+
"or --cpu_extension command line argument")
144+
sys.exit(1)
145+
136146
required_input_keys = {'im_data', 'im_info'}
137147
assert required_input_keys == set(net.input_info), \
138148
'Demo supports only topologies with the following input keys: {}'.format(', '.join(required_input_keys))

demos/python_demos/monodepth_demo/monodepth_demo.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def main():
1717
"-m", "--model", help="Required. Path to an .xml file with a trained model", required=True, type=str)
1818
parser.add_argument(
1919
"-i", "--input", help="Required. Path to a input image file", required=True, type=str)
20-
parser.add_argument("-l", "--cpu_extension",
20+
parser.add_argument("-l", "--cpu_extension",
2121
help="Optional. Required for CPU custom layers. Absolute MKLDNN (CPU)-targeted custom layers. "
2222
"Absolute path to a shared library with the kernels implementations", type=str, default=None)
23-
parser.add_argument("-d", "--device",
23+
parser.add_argument("-d", "--device",
2424
help="Optional. Specify the target device to infer on; CPU, GPU, FPGA, HDDL or MYRIAD is acceptable. "
2525
"Sample will look for a suitable plugin for device specified. Default value is CPU", default="CPU", type=str)
2626

@@ -38,6 +38,18 @@ def main():
3838
log.info("Loading network")
3939
net = ie.read_network(args.model, os.path.splitext(args.model)[0] + ".bin")
4040

41+
if "CPU" in args.device:
42+
supported_layers = ie.query_network(net, "CPU")
43+
not_supported_layers = [
44+
l for l in net.layers.keys() if l not in supported_layers]
45+
46+
if len(not_supported_layers) != 0:
47+
log.error("Following layers are not supported by the plugin for specified device {}:\n {}".
48+
format(args.device, ', '.join(not_supported_layers)))
49+
log.error("Please try to specify a CPU extensions library path in sample's command line parameters "
50+
"using -l or --cpu_extension command line argument")
51+
sys.exit(1)
52+
4153
assert len(net.input_info) == 1, "Sample supports only single input topologies"
4254
assert len(net.outputs) == 1, "Sample supports only single output topologies"
4355

@@ -57,7 +69,7 @@ def main():
5769
log.info("Image is resized from {} to {}".format(
5870
image.shape[:-1], (height, width)))
5971
image = cv2.resize(image, (width, height), cv2.INTER_CUBIC)
60-
72+
6173
# prepare input
6274
image = image.astype(np.float32)
6375
image = image.transpose((2, 0, 1))

demos/python_demos/multi_camera_multi_target_tracking/utils/ie_tools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ def load_ie_model(ie, model_xml, device, plugin_dir, cpu_extension='', num_reqs=
6969
log.info("Loading network")
7070
net = ie.read_network(model_xml, os.path.splitext(model_xml)[0] + ".bin")
7171

72+
if "CPU" in device:
73+
supported_layers = ie.query_network(net, "CPU")
74+
not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
75+
if not_supported_layers:
76+
log.error("Following layers are not supported by the plugin for specified device %s:\n %s",
77+
device, ', '.join(not_supported_layers))
78+
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
79+
"or --cpu_extension command line argument")
80+
sys.exit(1)
81+
7282
assert len(net.input_info) == 1 or len(net.input_info) == 2, \
7383
"Supports topologies with only 1 or 2 inputs"
7484
assert len(net.outputs) == 1 or len(net.outputs) == 4 or len(net.outputs) == 5, \

demos/python_demos/object_detection_demo_ssd_async/object_detection_demo_ssd_async.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ def main():
111111
log.info("Loading network")
112112
net = ie.read_network(args.model, os.path.splitext(args.model)[0] + ".bin")
113113

114+
if "CPU" in args.device:
115+
supported_layers = ie.query_network(net, "CPU")
116+
not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
117+
if len(not_supported_layers) != 0:
118+
log.error("Following layers are not supported by the plugin for specified device {}:\n {}".
119+
format(args.device, ', '.join(not_supported_layers)))
120+
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
121+
"or --cpu_extension command line argument")
122+
sys.exit(1)
123+
114124
img_info_input_blob = None
115125
feed_dict = {}
116126
for blob_name in net.input_info:

demos/python_demos/object_detection_demo_yolov3_async/object_detection_demo_yolov3_async.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,20 @@ def main():
319319
log.info("Loading network")
320320
net = ie.read_network(args.model, os.path.splitext(args.model)[0] + ".bin")
321321

322+
# ---------------------------------- 3. Load CPU extension for support specific layer ------------------------------
323+
if "CPU" in args.device:
324+
supported_layers = ie.query_network(net, "CPU")
325+
not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
326+
if len(not_supported_layers) != 0:
327+
log.error("Following layers are not supported by the plugin for specified device {}:\n {}".
328+
format(args.device, ', '.join(not_supported_layers)))
329+
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
330+
"or --cpu_extension command line argument")
331+
sys.exit(1)
332+
322333
assert len(net.input_info) == 1, "Sample supports only YOLO V3 based single input topologies"
323334

324-
# ---------------------------------------------- 3. Preparing inputs -----------------------------------------------
335+
# ---------------------------------------------- 4. Preparing inputs -----------------------------------------------
325336
log.info("Preparing inputs")
326337
input_blob = next(iter(net.input_info))
327338

@@ -345,7 +356,7 @@ def main():
345356
cap = cv2.VideoCapture(input_stream)
346357
wait_key_time = 1
347358

348-
# ----------------------------------------- 4. Loading model to the plugin -----------------------------------------
359+
# ----------------------------------------- 5. Loading model to the plugin -----------------------------------------
349360
log.info("Loading model to the plugin")
350361
exec_nets = {}
351362

@@ -364,7 +375,7 @@ def main():
364375
event = threading.Event()
365376
callback_exceptions = []
366377

367-
# ----------------------------------------------- 5. Doing inference -----------------------------------------------
378+
# ----------------------------------------------- 6. Doing inference -----------------------------------------------
368379
log.info("Starting inference...")
369380
print("To close the application, press 'CTRL+C' here or switch to the output window and press ESC key")
370381
print("To switch between min_latency/user_specified modes, press TAB key in the output window")

demos/python_demos/segmentation_demo/segmentation_demo.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ def main():
8181
log.info("Loading network")
8282
net = ie.read_network(args.model, os.path.splitext(args.model)[0] + ".bin")
8383

84+
if "CPU" in args.device:
85+
supported_layers = ie.query_network(net, "CPU")
86+
not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
87+
if len(not_supported_layers) != 0:
88+
log.error("Following layers are not supported by the plugin for specified device {}:\n {}".
89+
format(args.device, ', '.join(not_supported_layers)))
90+
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
91+
"or --cpu_extension command line argument")
92+
sys.exit(1)
8493
assert len(net.input_info) == 1, "Sample supports only single input topologies"
8594
assert len(net.outputs) == 1, "Sample supports only single output topologies"
8695

demos/python_demos/text_spotting_demo/text_spotting_demo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ def main():
192192
log.info('Loading decoder part of text recognition network')
193193
text_dec_net = ie.read_network(args.text_dec_model, os.path.splitext(args.text_dec_model)[0] + '.bin')
194194

195+
if 'CPU' in args.device:
196+
supported_layers = ie.query_network(mask_rcnn_net, 'CPU')
197+
not_supported_layers = [l for l in mask_rcnn_net.layers.keys() if l not in supported_layers]
198+
if len(not_supported_layers) != 0:
199+
log.error('Following layers are not supported by the plugin for specified device {}:\n {}'.
200+
format(args.device, ', '.join(not_supported_layers)))
201+
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
202+
"or --cpu_extension command line argument")
203+
sys.exit(1)
204+
195205
required_input_keys = {'im_data', 'im_info'}
196206
assert required_input_keys == set(mask_rcnn_net.input_info), \
197207
'Demo supports only topologies with the following input keys: {}'.format(', '.join(required_input_keys))

demos/python_demos/whiteboard_inpainting_demo/utils/ie_tools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ def load_ie_model(self, ie, model_xml, device, cpu_extension=''):
6868
log.info("Loading network files:\n\t%s\n\t%s", model_xml, model_bin)
6969
net = ie.read_network(model=model_xml, weights=model_bin)
7070

71+
if "CPU" in device:
72+
supported_layers = ie.query_network(net, "CPU")
73+
not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
74+
if not_supported_layers:
75+
log.error("Following layers are not supported by the plugin for specified device %s:\n %s",
76+
device, ', '.join(not_supported_layers))
77+
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
78+
"or --cpu_extension command line argument")
79+
sys.exit(1)
80+
7181
assert len(net.input_info) in self.get_allowed_inputs_len(), \
7282
"Supports topologies with only {} inputs, but got {}" \
7383
.format(self.get_allowed_inputs_len(), len(net.input_info))

0 commit comments

Comments
 (0)