本文整理汇总了Python中openvino.inference_engine.IEPlugin方法的典型用法代码示例。如果您正苦于以下问题:Python inference_engine.IEPlugin方法的具体用法?Python inference_engine.IEPlugin怎么用?Python inference_engine.IEPlugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openvino.inference_engine
的用法示例。
在下文中一共展示了inference_engine.IEPlugin方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def __init__(self, devid, frameBuffer, results, camera_width, camera_height, number_of_ncs, vidfps):
self.devid = devid
self.frameBuffer = frameBuffer
self.model_xml = "./lrmodels/YoloV3/FP16/frozen_yolo_v3.xml"
self.model_bin = "./lrmodels/YoloV3/FP16/frozen_yolo_v3.bin"
self.camera_width = camera_width
self.camera_height = camera_height
self.m_input_size = 416
self.threshould = 0.7
self.num_requests = 4
self.inferred_request = [0] * self.num_requests
self.heap_request = []
self.inferred_cnt = 0
self.plugin = IEPlugin(device="MYRIAD")
self.net = IENetwork(model=self.model_xml, weights=self.model_bin)
self.input_blob = next(iter(self.net.inputs))
self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests)
self.results = results
self.number_of_ncs = number_of_ncs
self.predict_async_time = 800
self.skip_frame = 0
self.roop_frame = 0
self.vidfps = vidfps
self.new_w = int(camera_width * self.m_input_size/camera_width)
self.new_h = int(camera_height * self.m_input_size/camera_height)
示例2: __init__
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def __init__(self, devid, frameBuffer, results, camera_width, camera_height, number_of_ncs, vidfps):
self.devid = devid
self.frameBuffer = frameBuffer
self.model_xml = "./lrmodels/tiny-YoloV3/FP16/frozen_tiny_yolo_v3.xml"
self.model_bin = "./lrmodels/tiny-YoloV3/FP16/frozen_tiny_yolo_v3.bin"
self.camera_width = camera_width
self.camera_height = camera_height
self.m_input_size = 416
self.threshould = 0.4
self.num_requests = 4
self.inferred_request = [0] * self.num_requests
self.heap_request = []
self.inferred_cnt = 0
self.plugin = IEPlugin(device="MYRIAD")
self.net = IENetwork(model=self.model_xml, weights=self.model_bin)
self.input_blob = next(iter(self.net.inputs))
self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests)
self.results = results
self.number_of_ncs = number_of_ncs
self.predict_async_time = 800
self.skip_frame = 0
self.roop_frame = 0
self.vidfps = vidfps
self.new_w = int(camera_width * self.m_input_size/camera_width)
self.new_h = int(camera_height * self.m_input_size/camera_height)
示例3: setup_network
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def setup_network():
global ARGS
# Select the myriad plugin and IRs to be used
plugin = IEPlugin(device='MYRIAD')
net = IENetwork(model = ARGS.ir, weights = ARGS.ir[:-3] + 'bin')
# Set up the input and output blobs
input_blob = next(iter(net.inputs))
output_blob = next(iter(net.outputs))
# Load the network and get the network shape information
exec_net = plugin.load(network = net)
input_shape = net.inputs[input_blob].shape
output_shape = net.outputs[output_blob].shape
del net
display_info(input_shape, output_shape)
return input_shape, input_blob, output_blob, exec_net
示例4: classify_frame
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def classify_frame(inputQueue, outputQueue):
plugin = IEPlugin("MYRIAD")
net = IENetwork(model=model_xml, weights=model_bin)
input_blob = next(iter(net.inputs))
exec_net = plugin.load(network=net)
# keep looping
while True:
# check to see if there is a frame in our input queue
if not inputQueue.empty():
# grab the frame from the input queue, resize it, and
# construct a blob from it
image = inputQueue.get()
prepimg = cv2.resize(image, (416, 416))
prepimg = prepimg[np.newaxis, :, :, :] # Batch size axis add
prepimg = prepimg.transpose((0, 3, 1, 2)) # NHWC to NCHW
outputs = exec_net.infer(inputs={input_blob: prepimg})
# write the detections to the output queue
outputQueue.put(outputs)
# initialize the input queue (frames), output queue (out),
# and the list of actual detections returned by the child process
示例5: __init__
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def __init__(self, devid, frameBuffer, results, camera_mode, camera_width, camera_height, number_of_ncs, vidfps, skpfrm):
self.devid = devid
self.frameBuffer = frameBuffer
self.model_xml = "./lrmodel/MobileNetSSD/MobileNetSSD_deploy.xml"
self.model_bin = "./lrmodel/MobileNetSSD/MobileNetSSD_deploy.bin"
self.camera_width = camera_width
self.camera_height = camera_height
self.num_requests = 4
self.inferred_request = [0] * self.num_requests
self.heap_request = []
self.inferred_cnt = 0
self.plugin = IEPlugin(device="MYRIAD")
self.net = IENetwork(model=self.model_xml, weights=self.model_bin)
self.input_blob = next(iter(self.net.inputs))
self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests)
self.results = results
self.camera_mode = camera_mode
self.number_of_ncs = number_of_ncs
if self.camera_mode == 0:
self.skip_frame = skpfrm
else:
self.skip_frame = 0
self.roop_frame = 0
self.vidfps = vidfps
开发者ID:PINTO0309,项目名称:MobileNet-SSD-RealSense,代码行数:26,代码来源:MultiStickSSDwithRealSense_OpenVINO_NCS2.py
示例6: __init__
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def __init__(self, devid, frameBuffer, results, camera_width, camera_height, number_of_ncs):
self.devid = devid
self.frameBuffer = frameBuffer
self.model_xml = "./lrmodel/MobileNetSSD/MobileNetSSD_deploy.xml"
self.model_bin = "./lrmodel/MobileNetSSD/MobileNetSSD_deploy.bin"
self.camera_width = camera_width
self.camera_height = camera_height
self.num_requests = 4
self.inferred_request = [0] * self.num_requests
self.heap_request = []
self.inferred_cnt = 0
self.plugin = IEPlugin(device="MYRIAD")
self.net = IENetwork(model=self.model_xml, weights=self.model_bin)
self.input_blob = next(iter(self.net.inputs))
self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests)
self.results = results
self.number_of_ncs = number_of_ncs
开发者ID:PINTO0309,项目名称:MobileNet-SSD-RealSense,代码行数:19,代码来源:MultiStickSSDwithPiCamera_OpenVINO_NCS2.py
示例7: __init__
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def __init__(self, devid, model_path, number_of_ncs):
global g_plugin
global g_inferred_request
global g_heap_request
global g_inferred_cnt
global g_number_of_allocated_ncs
self.devid = devid
if number_of_ncs == 0:
self.num_requests = 4
elif number_of_ncs == 1:
self.num_requests = 4
elif number_of_ncs == 2:
self.num_requests = 2
elif number_of_ncs >= 3:
self.num_requests = 1
print("g_number_of_allocated_ncs =", g_number_of_allocated_ncs, "number_of_ncs =", number_of_ncs)
if g_number_of_allocated_ncs < 1:
self.plugin = IEPlugin(device="MYRIAD")
self.inferred_request = [0] * self.num_requests
self.heap_request = []
self.inferred_cnt = 0
g_plugin = self.plugin
g_inferred_request = self.inferred_request
g_heap_request = self.heap_request
g_inferred_cnt = self.inferred_cnt
g_number_of_allocated_ncs += 1
else:
self.plugin = g_plugin
self.inferred_request = g_inferred_request
self.heap_request = g_heap_request
self.inferred_cnt = g_inferred_cnt
self.model_xml = model_path + ".xml"
self.model_bin = model_path + ".bin"
self.net = IENetwork(model=self.model_xml, weights=self.model_bin)
self.input_blob = next(iter(self.net.inputs))
self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests)
示例8: __init__
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def __init__(self, devid, device, model_xml, frameBuffer, results, camera_width, camera_height, number_of_ncs, vidfps, nPoints, w, h, new_w, new_h):
self.devid = devid
self.frameBuffer = frameBuffer
self.model_xml = model_xml
self.model_bin = os.path.splitext(model_xml)[0] + ".bin"
self.camera_width = camera_width
self.camera_height = camera_height
self.threshold = 0.1
self.nPoints = nPoints
self.num_requests = 4
self.inferred_request = [0] * self.num_requests
self.heap_request = []
self.inferred_cnt = 0
self.plugin = IEPlugin(device=device)
if "CPU" == device:
if platform.processor() == "x86_64":
self.plugin.add_cpu_extension("lib/libcpu_extension.so")
self.net = IENetwork(model=self.model_xml, weights=self.model_bin)
self.input_blob = next(iter(self.net.inputs))
self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests)
self.results = results
self.number_of_ncs = number_of_ncs
self.predict_async_time = 250
self.skip_frame = 0
self.roop_frame = 0
self.vidfps = vidfps
self.w = w #432
self.h = h #368
self.new_w = new_w
self.new_h = new_h
示例9: main
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def main():
ARGS = parse_args().parse_args()
####################### 1. Setup Plugin and Network #######################
# Select the myriad plugin and IRs to be used
plugin = IEPlugin(device='MYRIAD')
net = IENetwork(model = ARGS.ir, weights = ARGS.ir[:-3] + 'bin')
# Set up the input and output blobs
input_blob = next(iter(net.inputs))
output_blob = next(iter(net.outputs))
# Load the network and get the network shape information
exec_net = plugin.load(network = net)
input_shape = tuple(net.inputs[input_blob].shape)
output_shape = net.outputs[output_blob].shape
display_info(ARGS, input_shape, output_shape)
# Prepare Categories for age and gender networks
with open(ARGS.labels) as labels_file:
label_list = labels_file.read().splitlines()
####################### 2. Image Preprocessing #######################
# Read in the image.
img = cv2.imread(ARGS.image)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Image preprocessing
img = cv2.resize(img, NETWORK_DIM)
img = img.astype(numpy.float32)
img[:] = ((img[:]) * (1.0 / 255.0))
img = img.reshape(input_shape)
####################### 3. Run the inference #######################
res = exec_net.infer({input_blob: img})
####################### 4. Process and print the results #######################
top_ind = numpy.argsort(res[output_blob], axis=1)[0, -ARGS.number_top:][::-1]
print(YELLOW + '\n **********' + NOCOLOR + ' Results ' + YELLOW + '***********' + NOCOLOR)
for k, i in enumerate(top_ind):
print('Prediction is ' + YELLOW + label_list[int(i)] + NOCOLOR + " with a confidence of " + YELLOW + "%3.1f%%." % (100*res[output_blob][0, i]) + NOCOLOR)
print('')
示例10: _do_ncs_initialize
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def _do_ncs_initialize(self):
"""Create and opens the Neural Compute device and create a MnistProcessor."""
file_folder = os.path.dirname(os.path.realpath(__file__))
graph_filename = file_folder + '/mnist_inference'
self._plugin = IEPlugin(device="MYRIAD")
# Create processor object for this network
self._net_processor = MnistProcessor(graph_filename, self._plugin)
示例11: inference
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def inference(args, model_xml, model_bin, inputs, outputs):
from openvino.inference_engine import IENetwork
from openvino.inference_engine import IEPlugin
plugin = IEPlugin(device=args.device, plugin_dirs=args.plugin_dir)
if args.cpu_extension and 'CPU' in args.device:
plugin.add_cpu_extension(args.cpu_extension)
log.info('Loading network files:\n\t{}\n\t{}'.format(model_xml, model_bin))
net = IENetwork(model=model_xml, weights=model_bin)
if plugin.device == 'CPU':
supported_layers = plugin.get_supported_layers(net)
not_supported_layers = [l for l in net.layers.keys() if
l not in supported_layers]
if not_supported_layers:
log.error('Folowing layers are not supported by the plugin for '
'specified device {}:\n {}'.format(
plugin.device, ', '.join(not_supported_layers)))
log.error('Please try to specify cpu extensions library path in '
'sample\'s command line parameters using '
'--cpu-extension command line argument')
sys.exis(1)
assert len(net.inputs) == len(inputs)
ie_inputs = {}
for item in inputs:
assert item[0] in set(net.inputs.keys())
ie_inputs[item[0]] = item[1]
log.info('Loading model to the plugin')
exec_net = plugin.load(network=net)
res = exec_net.infer(inputs=ie_inputs)
assert len(res) == len(outputs)
for name, output in outputs:
assert name in res
actual_output = res[name]
np.testing.assert_allclose(output, actual_output, rtol=1e-3, atol=1e-4)
log.info('{}: OK'.format(name))
log.info('ALL OK')
def compute():
exec_net.infer(inputs=ie_inputs)
return run_onnx_util.run_benchmark(compute, args.iterations)
示例12: main
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def main(path_to_objxml, path_to_objbin, dev, ext, input, labels_map=None):
# Load network
obj_net = IENetwork(model=path_to_objxml, weights=path_to_objbin)
log.info("Loaded network")
input_layer = next(iter(obj_net.inputs))
output_layer = next(iter(obj_net.outputs))
# Pre-process image
n, c, h, w = obj_net.inputs[input_layer].shape
obj_frame = cv2.imread(input)
obj_in_frame = cv2.resize(obj_frame, (w, h))
obj_in_frame = obj_in_frame.transpose((2, 0, 1))
obj_in_frame = obj_in_frame.reshape((n, c, h, w))
log.info("Pre-processed image")
obj_plugin = IEPlugin(device=dev)
if dev == 'CPU':
obj_plugin.add_cpu_extension(ext)
obj_exec_net = obj_plugin.load(network=obj_net, num_requests=1)
log.info("Loaded network into plugin")
# Do inference
obj_res = obj_exec_net.infer({input_layer: obj_in_frame})
log.info("Inference successful!")
obj_det = obj_res[output_layer]
initial_w = obj_frame.shape[1]
initial_h = obj_frame.shape[0]
for obj in obj_det[0][0]:
# Draw only objects when probability more than specified threshold
if obj[2] > 0.5:
xmin = int(obj[3] * initial_w)
ymin = int(obj[4] * initial_h)
xmax = int(obj[5] * initial_w)
ymax = int(obj[6] * initial_h)
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))
det_label = labels_map[class_id - 1] if labels_map else str(class_id)
cv2.rectangle(obj_frame, (xmin, ymin), (xmax, ymax), color, thickness=16)
label_and_prob = det_label + ", " + str(obj[2] * 100) + "%"
log.info('Detection: ' + label_and_prob)
#cv2.putText(obj_frame, label_and_prob, (xmin, ymin - 7), cv2.FONT_HERSHEY_COMPLEX, 0.6, color, 1)
log.info("Hit q to close the window")
# Resizing to maintainable window
inHeight = 368
aspect_ratio = initial_w / initial_h
inWidth = int(((aspect_ratio*inHeight)*8)//8)
obj_frame = cv2.resize(obj_frame, (inWidth, inHeight))
while True:
cv2.imshow('Detections', obj_frame)
key = cv2.waitKey(1)
if (key & 0xFF) == ord('q'):
break
cv2.destroyAllWindows()
示例13: main_IE_infer
# 需要导入模块: from openvino import inference_engine [as 别名]
# 或者: from openvino.inference_engine import IEPlugin [as 别名]
def main_IE_infer():
image = cv2.imread('in.jpg')
image_width = np.size(image,1)
image_height = np.size(image,0)
model_xml = "models/frozen_yolo_v3.xml"
model_bin = "models/frozen_yolo_v3.bin"
time.sleep(1)
plugin = IEPlugin("MYRIAD")
net = IENetwork(model=model_xml, weights=model_bin)
input_blob = next(iter(net.inputs))
exec_net = plugin.load(network=net)
prepimg = cv2.resize(image, (m_input_size, m_input_size))
prepimg = prepimg[np.newaxis, :, :, :] # Batch size axis add
prepimg = prepimg.transpose((0, 3, 1, 2)) # NHWC to NCHW
outputs = exec_net.infer(inputs={input_blob: prepimg})
objects = []
for output in outputs.values():
objects = ParseYOLOV3Output(output, m_input_size, m_input_size, image_height, image_width, 0.7, objects)
# Filtering overlapping boxes
objlen = len(objects)
for i in range(objlen):
if (objects[i].confidence == 0.0):
continue
for j in range(i + 1, objlen):
if (IntersectionOverUnion(objects[i], objects[j]) >= 0.4):
objects[j].confidence = 0
# Drawing boxes
for obj in objects:
if obj.confidence < 0.2:
continue
label = obj.class_id
confidence = obj.confidence
if confidence > 0.2:
label_text = LABELS[label] + " (" + "{:.1f}".format(confidence * 100) + "%)"
cv2.rectangle(image, (obj.xmin, obj.ymin), (obj.xmax, obj.ymax), box_color, box_thickness)
cv2.rectangle(image, (obj.xmin-1, obj.ymin-1),(obj.xmin+70, obj.ymin-12), (0,0,0), -1)
cv2.putText(image, label_text, (obj.xmin, obj.ymin - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.3, label_text_color, 1)
while cv2.waitKey(1) < 0:
cv2.imshow("Result", image)
if cv2.waitKey(1)&0xFF == ord('q'):
break
cv2.imwrite('out.png', image)