diff --git a/Video_Analytics/Python/Age_Gender_Detection.md b/Video_Analytics/Python/Age_Gender_Detection.md index f5eb962..e06cc96 100644 --- a/Video_Analytics/Python/Age_Gender_Detection.md +++ b/Video_Analytics/Python/Age_Gender_Detection.md @@ -30,49 +30,46 @@ parser.add_argument("-d_ag", "--device_ag", type=str) #TODO Head_Pose command line arguments ``` -### 2. Inializing Plugin for Myriad for Age amd Gender +### 2. Initializing Plugin for Age and Gender Initialize Plugin for Myriad for Age and Gender since it cannot be loaded twice. - +- Replace **#TODO Age_Gender_Detection 1** +- Paste the following lines ```python - MYRIAD_plugin_ag = IEPlugin(args.device_ag.upper(),args.plugin_dir) - #TODO Initializing Plugin for Myriad for Head Pose + + if args.model and args.ag_model: + plugin_ag,ag_net = load_model("Age/Gender Recognition",args.ag_model,args.device_ag,args.plugin_dir,1,2,args.cpu_extension) + if args.device == args.device_ag: + plugin_ag = plugin + #TODO Head_Pose_Detection 2 + ``` ### 3. Load Pre-trained Optimized Model for Age and Gender Inferencing In previous step, CPU is selected as plugin device. Now, load pre-trained optimized model for age and gender detection inferencing on CPU. -- Replace **#TODO Age_Gender_Detection 1** +- Replace **#TODO Age_Gender_Detection 2** - Paste the following lines ```python + + # age and gender if args.model and args.ag_model: age_enabled =True - #log.info("Loading network files for Age/Gender Recognition") - plugin,ag_net=load_model("Age/Gender Recognition",args.ag_model,args.device_ag.upper(),args.plugin_dir,1,2,args.cpu_extension) age_input_blob=next(iter(ag_net.inputs)) age_out_blob=next(iter(ag_net.outputs)) - - - if ((args.device_ag.upper() == "MYRIAD") and (not args.device.upper() == "MYRIAD")): - age_exec_net = MYRIAD_plugin_ag.load(network=ag_net, num_requests=2) - elif (args.device_ag == "MYRIAD"): - age_exec_net = MYRIAD_plugin.load(network=ag_net, num_requests=2) - else : - age_exec_net = plugin.load(network=ag_net, num_requests=2) - - + age_exec_net = plugin.load(network=ag_net, num_requests=2) ag_n, ag_c, ag_h, ag_w = ag_net.inputs[input_blob].shape del ag_net - #TODO Head_Pose_Detection 2 + #TODO Head_Pose_Detection 3 ``` ### 4. Initialize the parameters Here initialize the parameters which are required to process the output. -- Replace **#TODO Age_Gender_Detection 2** +- Replace **#TODO Age_Gender_Detection 3** - Paste the following lines ```python @@ -87,7 +84,7 @@ attentivityindex = 0 ### 5. Resetting the parameters for each frame The initialized parameters which are required to process the output are reset to zero. -- Replace **#TODO Age_Gender_Detection 3** +- Replace **#TODO Age_Gender_Detection 4** - Paste the following lines ```python @@ -100,7 +97,7 @@ attentivityindex=0 ### 6. Process Face detection Inference Results At this stage face detection Inference results will be available for further processing. Here, identified face will be clipped off and will be used for identifying age and gender in next request for inferencing. -- Replace **#TODO Age_Gender_Detection 4** +- Replace **#TODO Age_Gender_Detection 5** - Paste the following lines ```python @@ -117,13 +114,13 @@ if age_enabled: if age_exec_net.requests[cur_request_id].wait(-1) == 0: age_inf_end = time.time() age_inf_time=age_inf_end - age_inf_start -#TODO Head_Pose_Detection 3 +#TODO Head_Pose_Detection 4 ``` ### 7. Process Age and Gender detection Results for display Now we got result for Face, Age and Gender detection. We can customize the output and display this on the screen -- Replace **#TODO Age_Gender_Detection 5** +- Replace **#TODO Age_Gender_Detection 6** - Paste the following lines ```python diff --git a/Video_Analytics/Python/Explore_OpenVINO.md b/Video_Analytics/Python/Explore_OpenVINO.md index e76b6c7..dffca94 100644 --- a/Video_Analytics/Python/Explore_OpenVINO.md +++ b/Video_Analytics/Python/Explore_OpenVINO.md @@ -66,7 +66,7 @@ Upon the start-up, the demo application reads command line parameters and loads - **Case 1:** To run the sample application on **CPU**, execute the following commands: ``` -python3 object_detection_demo_ssd_async/object_detection_demo_ssd_async.py -i cam -m /opt/intel/openvino/deployment_tools/tools/model_downloader/Retail/object_detection/face/sqnet1.0modif-ssd/0004/dldt/face-detection-retail-0004.xml -l/opt/intel/openvino/deployment_tools/inference_engine/samples/build/intel64/Release/lib/libcpu_extension.so -d CPU +python3 object_detection_demo_ssd_async/object_detection_demo_ssd_async.py -i cam -m /opt/intel/openvino/deployment_tools/tools/model_downloader/Retail/object_detection/face/sqnet1.0modif-ssd/0004/dldt/face-detection-retail-0004.xml -l /opt/intel/openvino/deployment_tools/inference_engine/samples/build/intel64/Release/lib/libcpu_extension.so -d CPU ``` @@ -76,7 +76,7 @@ Next, we repeat the exercise with **GPU** and observe the performance. - **case2:** To run the sample application on **GPU**, execute the following commands; ``` -python3 object_detection_demo_ssd_async/object_detection_demo_ssd_async.py -i cam -m /opt/intel/openvino/deployment_tools/tools/model_downloader/Retail/object_detection/face/sqnet1.0modif-ssd/0004/dldt/face-detection-retail-0004.xml -l/opt/intel/openvino/deployment_tools/inference_engine/samples/build/intel64/Release/lib/libcpu_extension.so -d GPU +python3 object_detection_demo_ssd_async/object_detection_demo_ssd_async.py -i cam -m /opt/intel/openvino/deployment_tools/tools/model_downloader/Retail/object_detection/face/sqnet1.0modif-ssd/0004/dldt/face-detection-retail-0004.xml -l /opt/intel/openvino/deployment_tools/inference_engine/samples/build/intel64/Release/lib/libcpu_extension.so -d GPU ``` - **Output and Performance** diff --git a/Video_Analytics/Python/Face_detection.md b/Video_Analytics/Python/Face_detection.md index 6bb8dcc..2520a73 100644 --- a/Video_Analytics/Python/Face_detection.md +++ b/Video_Analytics/Python/Face_detection.md @@ -139,33 +139,26 @@ First, the pre-trained model XML files have been optimized and generated by the ```python + log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout) args = build_argparser().parse_args() age_enabled = False headPose_enabled = False #TODO Cloud_Integration 2 - - MYRIAD_plugin = IEPlugin(args.device.upper(),args.plugin_dir) - #TODO Initializing Plugin for Myriad for Age and Gender + #Make sure only one IEPlugin was created for one type of device + plugin,net = load_model("Face Detection",args.model,args.device,args.plugin_dir,1,1,args.cpu_extension) + #TODO Age_Gender_Detection 1 log.info("Reading IR...") # Face detection - #log.info("Loading network files for Face Detection") - - plugin,net=load_model("Face Detection",args.model,args.device.upper(),args.plugin_dir,1,1,args.cpu_extension) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) - - if (args.device.upper() == "MYRIAD"): - exec_net = MYRIAD_plugin.load(network=net, num_requests=2) - else : - exec_net = plugin.load(network=net, num_requests=2) - + exec_net = plugin.load(network=net, num_requests=2) n, c, h, w = net.inputs[input_blob].shape del net - #TODO Age_Gender_Detection 1 + #TODO Age_Gender_Detection 2 ``` @@ -197,7 +190,7 @@ log.info("Starting inference ...") log.info("To stop the demo execution press Esc button") is_async_mode = True render_time = 0 -#TODO Age_Gender_Detection 2 +#TODO Age_Gender_Detection 3 decode_time = 0 visual_time = 0 framesCounter = 0 @@ -215,7 +208,7 @@ decode_prev_time = decode_prev_finish - decode_prev_start ```python while cap.isOpened(): - #TODO Age_Gender_Detection 3 + #TODO Age_Gender_Detection 4 analytics_time = 0 decode_next_start = time.time() ret, frame = cap.read() @@ -258,16 +251,16 @@ while cap.isOpened(): height = ymax - ymin width = xmax -xmin - #TODO Age_Gender_Detection 4 + #TODO Age_Gender_Detection 5 visual_start = time.time() if args.no_show==False: - #TODO Age_Gender_Detection 5 + #TODO Age_Gender_Detection 6 class_id = int(obj[1]) # Draw box and label\class_id color = (min(class_id * 12.5, 255), min(class_id * 7, 255), min(class_id * 5, 255)) cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255,10,10), 2) det_label = labels_map[class_id] if labels_map else str(class_id) - #TODO Head_Pose_Detection 4 + #TODO Head_Pose_Detection 5 render_time_message = "OpenCV cap/rendering time: {:.2f} ms".format(render_time * 1000) inf_time_message = "Face Detection time: {:.2f} ms ({:.2f} fps)".format((det_time * 1000),1/(det_time)) diff --git a/Video_Analytics/Python/Head_Pose_Detection.md b/Video_Analytics/Python/Head_Pose_Detection.md index 8dc71dd..e86e315 100644 --- a/Video_Analytics/Python/Head_Pose_Detection.md +++ b/Video_Analytics/Python/Head_Pose_Detection.md @@ -109,14 +109,35 @@ def drawAxes(pitch,yaw,roll,cpoint,frame): ``` ### 3. Initializing Plugin for Myriad for Head Pose Initialize Plugin for Myriad for Head Pose +- Replace **#TODO Head_Pose_Detection 2** +- Paste the following lines ```python - MYRIAD_plugin_hp = IEPlugin(args.device_hp.upper(),args.plugin_dir) + + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device == args.device_hp: + plugin_hp = plugin + + else : + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device_ag == args.device_hp: + plugin_hp = plugin_ag + elif args.device == args.device_hp: + plugin_hp = plugin + + else : + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device == args.device_hp: + plugin_hp = plugin + ``` ### 4. Load Pre-trained Optimized Model for HeadPose Inferencing Load pre-retained optimized model for head pose detection on CPU as CPU is already selected as plugin device previously. -- Replace **#TODO Head_Pose_Detection 2** +- Replace **#TODO Head_Pose_Detection 3** - Paste the following lines ```python @@ -124,37 +145,18 @@ Load pre-retained optimized model for head pose detection on CPU as CPU is alrea # Head Pose if args.model and args.hp_model: headPose_enabled = True - #log.info("Loading network files for Head Pose Estimation") - plugin,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp.upper(),args.plugin_dir,1,3,args.cpu_extension) hp_input_blob=next(iter(hp_net.inputs)) hp_out_blob=next(iter(hp_net.outputs)) - - if (args.device_hp.upper() == "MYRIAD" and not args.device.upper() =="MYRIAD" and not args.device_ag.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin_hp.load(network=hp_net, num_requests=2) - - elif (args.device_hp.upper() == "MYRIAD"): - if (args.device_ag.upper() == "MYRIAD"): - if (args.device.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin.load(network=hp_net, num_requests=2) - else : - hp_exec_net = MYRIAD_plugin_ag.load(network=hp_net, num_requests=2) - elif (args.device.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin.load(network=hp_net, num_requests=2) - else : - hp_exec_net = MYRIAD_plugin_hp.load(network=hp_net, num_requests=2) - - else : - hp_exec_net = plugin.load(network=hp_net, num_requests=2) - - + hp_exec_net=plugin_hp.load(network=hp_net, num_requests=2) hp_n, hp_c, hp_h, hp_w = hp_net.inputs[input_blob].shape del hp_net + ``` ### 5. Use Identified Face for HeadPose Detection Clip the identified Faces and send inference request for detecting head pose -- Replace **#TODO Head_Pose_Detection 3** +- Replace **#TODO Head_Pose_Detection 4** - Paste the following lines ```python @@ -178,7 +180,7 @@ analytics_time = age_inf_time + hp_inf_time ### 6. Calculate attentivity index Now, the attentivityindex will be calculated using Yaw angle available from head pose inference result. -- Replace **#TODO Head_Pose_Detection 4** +- Replace **#TODO Head_Pose_Detection 5** - Paste the following lines ```python diff --git a/Video_Analytics/Python/solutions/Headposedetection.md b/Video_Analytics/Python/solutions/Headposedetection.md index 4dc4662..66339e4 100644 --- a/Video_Analytics/Python/solutions/Headposedetection.md +++ b/Video_Analytics/Python/solutions/Headposedetection.md @@ -1,5 +1,21 @@ ```python + #!/usr/bin/env python +""" + Copyright (c) 2019 Intel Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" from __future__ import print_function #TODO Import Cloud_Integration packages @@ -133,12 +149,11 @@ def load_model(feature,model_xml,device,plugin_dirs,input_key_length,output_key_ not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers] if len(not_supported_layers) != 0: log.error("Following layers are not supported by the plugin for specified device {}:\n {}". - format(plugin.device, ', '.join(not_supported_layers))) + format(plugin.device, ', '.join(not_supported_layers))) log.error("Please try to specify cpu extensions library path in demo's command line parameters using -l " - "or --cpu_extension command line argument") + "or --cpu_extension command line argument") sys.exit(1) - log.info("Checking {} network inputs".format(feature)) assert len(net.inputs.keys()) == input_key_length, "Demo supports only single input topologies" log.info("Checking {} network outputs".format(feature)) @@ -152,77 +167,59 @@ def main(): args = build_argparser().parse_args() age_enabled = False headPose_enabled = False - #TODO Cloud Integration 2 + #TODO Cloud_Integration 2 + #Make sure only one IEPlugin was created for one type of device + plugin,net = load_model("Face Detection",args.model,args.device,args.plugin_dir,1,1,args.cpu_extension) + + if args.model and args.ag_model: + plugin_ag,ag_net = load_model("Age/Gender Recognition",args.ag_model,args.device_ag,args.plugin_dir,1,2,args.cpu_extension) + if args.device == args.device_ag: + plugin_ag = plugin + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device == args.device_hp: + plugin_hp = plugin + + else : + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device_ag == args.device_hp: + plugin_hp = plugin_ag + elif args.device == args.device_hp: + plugin_hp = plugin + + else : + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device == args.device_hp: + plugin_hp = plugin - MYRIAD_plugin = IEPlugin(args.device.upper(),args.plugin_dir) - MYRIAD_plugin_ag = IEPlugin(args.device_ag.upper(),args.plugin_dir) - MYRIAD_plugin_hp = IEPlugin(args.device_hp.upper(),args.plugin_dir) log.info("Reading IR...") # Face detection - #log.info("Loading network files for Face Detection") - - plugin,net=load_model("Face Detection",args.model,args.device.upper(),args.plugin_dir,1,1,args.cpu_extension) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) - - if (args.device.upper() == "MYRIAD"): - exec_net = MYRIAD_plugin.load(network=net, num_requests=2) - else : - exec_net = plugin.load(network=net, num_requests=2) - + exec_net = plugin.load(network=net, num_requests=2) n, c, h, w = net.inputs[input_blob].shape del net # age and gender if args.model and args.ag_model: - age_enabled =True - #log.info("Loading network files for Age/Gender Recognition") - plugin,ag_net=load_model("Age/Gender Recognition",args.ag_model,args.device_ag.upper(),args.plugin_dir,1,2,args.cpu_extension) age_input_blob=next(iter(ag_net.inputs)) age_out_blob=next(iter(ag_net.outputs)) - - - if ((args.device_ag.upper() == "MYRIAD") and (not args.device.upper() == "MYRIAD")): - age_exec_net = MYRIAD_plugin_ag.load(network=ag_net, num_requests=2) - elif (args.device_ag == "MYRIAD"): - age_exec_net = MYRIAD_plugin.load(network=ag_net, num_requests=2) - else : - age_exec_net = plugin.load(network=ag_net, num_requests=2) - - + age_exec_net=plugin_ag.load(network=ag_net, num_requests=2) ag_n, ag_c, ag_h, ag_w = ag_net.inputs[input_blob].shape del ag_net # Head Pose if args.model and args.hp_model: headPose_enabled = True - #log.info("Loading network files for Head Pose Estimation") - plugin,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp.upper(),args.plugin_dir,1,3,args.cpu_extension) hp_input_blob=next(iter(hp_net.inputs)) hp_out_blob=next(iter(hp_net.outputs)) - - if (args.device_hp.upper() == "MYRIAD" and not args.device.upper() =="MYRIAD" and not args.device_ag.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin_hp.load(network=hp_net, num_requests=2) - - elif (args.device_hp.upper() == "MYRIAD"): - if (args.device_ag.upper() == "MYRIAD"): - if (args.device.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin.load(network=hp_net, num_requests=2) - else : - hp_exec_net = MYRIAD_plugin_ag.load(network=hp_net, num_requests=2) - elif (args.device.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin.load(network=hp_net, num_requests=2) - else : - hp_exec_net = MYRIAD_plugin_hp.load(network=hp_net, num_requests=2) - - else : - hp_exec_net = plugin.load(network=hp_net, num_requests=2) - - + hp_exec_net=plugin_hp.load(network=hp_net, num_requests=2) hp_n, hp_c, hp_h, hp_w = hp_net.inputs[input_blob].shape del hp_net diff --git a/Video_Analytics/Python/solutions/agegenderdetection.md b/Video_Analytics/Python/solutions/agegenderdetection.md index 7ba352e..f96eee2 100644 --- a/Video_Analytics/Python/solutions/agegenderdetection.md +++ b/Video_Analytics/Python/solutions/agegenderdetection.md @@ -1,6 +1,20 @@ ```python #!/usr/bin/env python +""" + Copyright (c) 2019 Intel Corporation + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" from __future__ import print_function #TODO Import Cloud_Integration packages @@ -64,12 +78,11 @@ def load_model(feature,model_xml,device,plugin_dirs,input_key_length,output_key_ not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers] if len(not_supported_layers) != 0: log.error("Following layers are not supported by the plugin for specified device {}:\n {}". - format(plugin.device, ', '.join(not_supported_layers))) + format(plugin.device, ', '.join(not_supported_layers))) log.error("Please try to specify cpu extensions library path in demo's command line parameters using -l " - "or --cpu_extension command line argument") + "or --cpu_extension command line argument") sys.exit(1) - log.info("Checking {} network inputs".format(feature)) assert len(net.inputs.keys()) == input_key_length, "Demo supports only single input topologies" log.info("Checking {} network outputs".format(feature)) @@ -85,26 +98,20 @@ def main(): headPose_enabled = False #TODO Cloud_Integration 2 + #Make sure only one IEPlugin was created for one type of device + plugin,net = load_model("Face Detection",args.model,args.device,args.plugin_dir,1,1,args.cpu_extension) - - MYRIAD_plugin = IEPlugin(args.device.upper(),args.plugin_dir) - MYRIAD_plugin_ag = IEPlugin(args.device_ag.upper(),args.plugin_dir) - #TODO Initializing Plugin for Myriad for Head Pose - + if args.model and args.ag_model: + plugin_ag,ag_net = load_model("Age/Gender Recognition",args.ag_model,args.device_ag,args.plugin_dir,1,2,args.cpu_extension) + if args.device == args.device_ag: + plugin_ag = plugin + #TODO Head_Pose_Detection 2 log.info("Reading IR...") # Face detection - #log.info("Loading network files for Face Detection") - - plugin,net=load_model("Face Detection",args.model,args.device.upper(),args.plugin_dir,1,1,args.cpu_extension) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) - - if (args.device.upper() == "MYRIAD"): - exec_net = MYRIAD_plugin.load(network=net, num_requests=2) - else : - exec_net = plugin.load(network=net, num_requests=2) - + exec_net = plugin.load(network=net, num_requests=2) n, c, h, w = net.inputs[input_blob].shape del net @@ -112,24 +119,13 @@ def main(): if args.model and args.ag_model: age_enabled =True - #log.info("Loading network files for Age/Gender Recognition") - plugin,ag_net=load_model("Age/Gender Recognition",args.ag_model,args.device_ag.upper(),args.plugin_dir,1,2,args.cpu_extension) age_input_blob=next(iter(ag_net.inputs)) age_out_blob=next(iter(ag_net.outputs)) - - - if ((args.device_ag.upper() == "MYRIAD") and (not args.device.upper() == "MYRIAD")): - age_exec_net = MYRIAD_plugin_ag.load(network=ag_net, num_requests=2) - elif (args.device_ag == "MYRIAD"): - age_exec_net = MYRIAD_plugin.load(network=ag_net, num_requests=2) - else : - age_exec_net = plugin.load(network=ag_net, num_requests=2) - - + age_exec_net = plugin.load(network=ag_net, num_requests=2) ag_n, ag_c, ag_h, ag_w = ag_net.inputs[input_blob].shape del ag_net - #TODO Head_Pose_Detection 2 + #TODO Head_Pose_Detection 3 total_start = time.time() if args.input == 'cam': @@ -226,7 +222,7 @@ def main(): if age_exec_net.requests[cur_request_id].wait(-1) == 0: age_inf_end = time.time() age_inf_time=age_inf_end - age_inf_start - #TODO Head_Pose_Detection 3 + #TODO Head_Pose_Detection 4 visual_start = time.time() @@ -248,7 +244,7 @@ def main(): color = (min(class_id * 12.5, 255), min(class_id * 7, 255), min(class_id * 5, 255)) cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255,10,10), 2) det_label = labels_map[class_id] if labels_map else str(class_id) - #TODO Head_Pose_Detection 4 + #TODO Head_Pose_Detection 5 render_time_message = "OpenCV cap/rendering time: {:.2f} ms".format(render_time * 1000) inf_time_message = "Face Detection time: {:.2f} ms ({:.2f} fps)".format((det_time * 1000),1/(det_time)) diff --git a/Video_Analytics/Python/solutions/cloudanalysis.md b/Video_Analytics/Python/solutions/cloudanalysis.md index ece6dc7..36b5bfc 100644 --- a/Video_Analytics/Python/solutions/cloudanalysis.md +++ b/Video_Analytics/Python/solutions/cloudanalysis.md @@ -1,6 +1,20 @@ ```python #!/usr/bin/env python +""" + Copyright (c) 2019 Intel Corporation + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" from __future__ import print_function import requests @@ -162,75 +176,58 @@ def main(): headPose_enabled = False deviceid="1234" + #Make sure only one IEPlugin was created for one type of device + plugin,net = load_model("Face Detection",args.model,args.device,args.plugin_dir,1,1,args.cpu_extension) + + if args.model and args.ag_model: + plugin_ag,ag_net = load_model("Age/Gender Recognition",args.ag_model,args.device_ag,args.plugin_dir,1,2,args.cpu_extension) + if args.device == args.device_ag: + plugin_ag = plugin + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device == args.device_hp: + plugin_hp = plugin + + else : + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device_ag == args.device_hp: + plugin_hp = plugin_ag + elif args.device == args.device_hp: + plugin_hp = plugin + + + else : + if args.model and args.hp_model: + plugin_hp,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp,args.plugin_dir,1,3,args.cpu_extension) + if args.device == args.device_hp: + plugin_hp = plugin - MYRIAD_plugin = IEPlugin(args.device.upper(),args.plugin_dir) - MYRIAD_plugin_ag = IEPlugin(args.device_ag.upper(),args.plugin_dir) - MYRIAD_plugin_hp = IEPlugin(args.device_hp.upper(),args.plugin_dir) log.info("Reading IR...") # Face detection - #log.info("Loading network files for Face Detection") - - plugin,net=load_model("Face Detection",args.model,args.device.upper(),args.plugin_dir,1,1,args.cpu_extension) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) - - if (args.device.upper() == "MYRIAD"): - exec_net = MYRIAD_plugin.load(network=net, num_requests=2) - else : - exec_net = plugin.load(network=net, num_requests=2) - + exec_net = plugin.load(network=net, num_requests=2) n, c, h, w = net.inputs[input_blob].shape del net # age and gender if args.model and args.ag_model: - age_enabled =True - #log.info("Loading network files for Age/Gender Recognition") - plugin,ag_net=load_model("Age/Gender Recognition",args.ag_model,args.device_ag.upper(),args.plugin_dir,1,2,args.cpu_extension) age_input_blob=next(iter(ag_net.inputs)) age_out_blob=next(iter(ag_net.outputs)) - - - if ((args.device_ag.upper() == "MYRIAD") and (not args.device.upper() == "MYRIAD")): - age_exec_net = MYRIAD_plugin_ag.load(network=ag_net, num_requests=2) - elif (args.device_ag == "MYRIAD"): - age_exec_net = MYRIAD_plugin.load(network=ag_net, num_requests=2) - else : - age_exec_net = plugin.load(network=ag_net, num_requests=2) - - + age_exec_net=plugin_ag.load(network=ag_net, num_requests=2) ag_n, ag_c, ag_h, ag_w = ag_net.inputs[input_blob].shape del ag_net # Head Pose if args.model and args.hp_model: headPose_enabled = True - #log.info("Loading network files for Head Pose Estimation") - plugin,hp_net=load_model("Head Pose Estimation",args.hp_model,args.device_hp.upper(),args.plugin_dir,1,3,args.cpu_extension) hp_input_blob=next(iter(hp_net.inputs)) hp_out_blob=next(iter(hp_net.outputs)) - - if (args.device_hp.upper() == "MYRIAD" and not args.device.upper() =="MYRIAD" and not args.device_ag.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin_hp.load(network=hp_net, num_requests=2) - - elif (args.device_hp.upper() == "MYRIAD"): - if (args.device_ag.upper() == "MYRIAD"): - if (args.device.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin.load(network=hp_net, num_requests=2) - else : - hp_exec_net = MYRIAD_plugin_ag.load(network=hp_net, num_requests=2) - elif (args.device.upper() == "MYRIAD"): - hp_exec_net = MYRIAD_plugin.load(network=hp_net, num_requests=2) - else : - hp_exec_net = MYRIAD_plugin_hp.load(network=hp_net, num_requests=2) - - else : - hp_exec_net = plugin.load(network=hp_net, num_requests=2) - - + hp_exec_net=plugin_hp.load(network=hp_net, num_requests=2) hp_n, hp_c, hp_h, hp_w = hp_net.inputs[input_blob].shape del hp_net diff --git a/Video_Analytics/Python/solutions/facedetection.md b/Video_Analytics/Python/solutions/facedetection.md index fa494b6..121fd8c 100644 --- a/Video_Analytics/Python/solutions/facedetection.md +++ b/Video_Analytics/Python/solutions/facedetection.md @@ -1,5 +1,22 @@ + +```python + #!/usr/bin/env python +""" + Copyright (c) 2019 Intel Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" from __future__ import print_function #TODO Import Cloud_Integration packages @@ -60,12 +77,11 @@ def load_model(feature,model_xml,device,plugin_dirs,input_key_length,output_key_ not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers] if len(not_supported_layers) != 0: log.error("Following layers are not supported by the plugin for specified device {}:\n {}". - format(plugin.device, ', '.join(not_supported_layers))) + format(plugin.device, ', '.join(not_supported_layers))) log.error("Please try to specify cpu extensions library path in demo's command line parameters using -l " - "or --cpu_extension command line argument") + "or --cpu_extension command line argument") sys.exit(1) - log.info("Checking {} network inputs".format(feature)) assert len(net.inputs.keys()) == input_key_length, "Demo supports only single input topologies" log.info("Checking {} network outputs".format(feature)) @@ -81,28 +97,19 @@ def main(): headPose_enabled = False #TODO Cloud_Integration 2 - - MYRIAD_plugin = IEPlugin(args.device.upper(),args.plugin_dir) - #TODO Initializing Plugin for Myriad - + #Make sure only one IEPlugin was created for one type of device + plugin,net = load_model("Face Detection",args.model,args.device,args.plugin_dir,1,1,args.cpu_extension) + #TODO Age_Gender_Detection 1 log.info("Reading IR...") # Face detection - #log.info("Loading network files for Face Detection") - - plugin,net=load_model("Face Detection",args.model,args.device.upper(),args.plugin_dir,1,1,args.cpu_extension) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) - - if (args.device.upper() == "MYRIAD"): - exec_net = MYRIAD_plugin.load(network=net, num_requests=2) - else : - exec_net = plugin.load(network=net, num_requests=2) - + exec_net = plugin.load(network=net, num_requests=2) n, c, h, w = net.inputs[input_blob].shape del net - #TODO Age_Gender_Detection 1 + #TODO Age_Gender_Detection 2 total_start = time.time() @@ -127,7 +134,7 @@ def main(): log.info("To stop the demo execution press Esc button") is_async_mode = True render_time = 0 - #TODO Age_Gender_Detection 2 + #TODO Age_Gender_Detection 3 decode_time = 0 visual_time = 0 framesCounter = 0 @@ -136,7 +143,7 @@ def main(): decode_prev_finish = time.time() decode_prev_time = decode_prev_finish - decode_prev_start while cap.isOpened(): - #TODO Age_Gender_Detection 3 + #TODO Age_Gender_Detection 4 analytics_time = 0 decode_next_start = time.time() ret, frame = cap.read() @@ -179,16 +186,16 @@ def main(): height = ymax - ymin width = xmax -xmin - #TODO Age_Gender_Detection 4 + #TODO Age_Gender_Detection 5 visual_start = time.time() if args.no_show==False: - #TODO Age_Gender_Detection 5 + #TODO Age_Gender_Detection 6 class_id = int(obj[1]) # Draw box and label\class_id color = (min(class_id * 12.5, 255), min(class_id * 7, 255), min(class_id * 5, 255)) cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255,10,10), 2) det_label = labels_map[class_id] if labels_map else str(class_id) - #TODO Head_Pose_Detection 4 + #TODO Head_Pose_Detection 5 render_time_message = "OpenCV cap/rendering time: {:.2f} ms".format(render_time * 1000) inf_time_message = "Face Detection time: {:.2f} ms ({:.2f} fps)".format((det_time * 1000),1/(det_time)) @@ -229,3 +236,4 @@ def main(): if __name__ == '__main__': sys.exit(main() or 0) +```