openvino道路分割

我这里仅显示道路和车道线

1 mask = np.zeros((hh, ww, 3), dtype=np.uint8)
2 mask[np.where(res > 0)] = (0, 255, 0) # 路面
3 mask[np.where(res > 1)] = (255, 0, 0) # 车道线

 

模型的下载还是老方法

Accuracy

The quality metrics calculated on 500 images from "Mighty AI" dataset that was converted for four class classification task are:

LabelIOUACC
mean 0.844 0.901
BG 0.986 0.994
road 0.954 0.974
curbs 0.727 0.831
marks 0.708 0.806
  • IOU=TP/(TP+FN+FP)
  • ACC=TP/GT
  • TP - number of true positive pixels for given class
  • FN - number of false negative pixels for given class
  • FP - number of false positive pixels for given class
  • GT - number of ground truth pixels for given class

Performance

Inputs

A blob with a BGR image in the format: [B, C=3, H=512, W=896], where:

  • B – batch size
  • C – number of channels
  • H – image height
  • W – image width

Outputs

The output is a blob with the shape [B, C=4, H=512, W=896]. It can be treated as a four-channel feature map, where each channel is a probability of one of the classes: BG, road, curb, mark.

 1 import time
 2 import cv2 as cv
 3 import numpy as np
 4 import numpy as py
 5 from openvino.inference_engine import IECore
 6 
 7 gengers = ["femal", "male"]
 8 
 9 def face_landmarks35():
10     ie = IECore()
11     for device in ie.available_devices:
12         print(device)
13     model_xml = "road-segmentation-adas-0001.xml"
14     model_bin = "road-segmentation-adas-0001.bin"
15     net = ie.read_network(model=model_xml, weights=model_bin)
16     input_blob = next(iter(net.input_info))
17     out_blob = next(iter(net.outputs))
18     n, c, h, w = net.input_info[input_blob].input_data.shape
19     print(n, c, h, w)  # 1 3 384 384
20 
21     cap = cv.VideoCapture("2.mp4")
22     exec_net = ie.load_network(network=net, device_name="CPU")
23 
24     while True:
25         ret, frame = cap.read()
26         if ret is not True:
27             break
28         image = cv.resize(frame, (w, h))
29         image = image.transpose(2, 0, 1)
30         inf_start = time.time()
31         # 路面与车道线分割
32         res = exec_net.infer(inputs={input_blob: [image]})
33         inf_end = time.time() - inf_start
34         ih, iw, ic = frame.shape
35         res = res[out_blob]          # (1, 4, 512, 896)
36         res = np.squeeze(res, 0)     # (4, 512, 896)
37         #res = res.transpose(1, 2, 0) # (512, 896, 4)
38         res = np.argmax(res, 0)
39         hh, ww = res.shape
40         mask = np.zeros((hh, ww, 3), dtype=np.uint8)
41         mask[np.where(res > 0)] = (0, 255, 0) # 路面
42         mask[np.where(res > 1)] = (255, 0, 0) # 车道线
43         mask = cv.resize(mask, (frame.shape[1], frame.shape[0]))
44         result = cv.addWeighted(frame, 0.5, mask, 0.5, 0)
45 
46         cv.imshow("road segment", result)
47         cv.waitKey(1)
48     cv.destroyAllWindows()
49 
50 
51 if __name__ == "__main__":
52     face_landmarks35()
View Code

 

posted @ 2023-09-30 09:32  佚名12  阅读(37)  评论(0编辑  收藏  举报