Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Retail content with double MYRIAD fix #17

Open
wants to merge 3 commits into
base: lab-retail-workshop-linux
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions Video_Analytics/Python/Age_Gender_Detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Video_Analytics/Python/Explore_OpenVINO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```

Expand All @@ -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**
Expand Down
29 changes: 11 additions & 18 deletions Video_Analytics/Python/Face_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```

Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
52 changes: 27 additions & 25 deletions Video_Analytics/Python/Head_Pose_Detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,52 +109,54 @@ 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

# 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
Expand All @@ -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
Expand Down
Loading