Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
global network_input_h, network_input_w
ie = IECore()
net = IENetwork(model = ir, weights = ir[:-3] + 'bin')
input_blob = next(iter(net.inputs))
output_blob = next(iter(net.outputs))
exec_net = ie.load_network(network = net, device_name = DEVICE)
n, c, network_input_h, network_input_w = net.inputs[input_blob].shape
# Read the image
validated_image = cv2.imread(validated_image_filename)
if validated_image is None:
print("Cannot read image.")
exit(1)
# Preprocess the image
preprocessed_image = preprocess_image(validated_image)
# Run the inference
def main():
log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
args = build_argparser().parse_args()
model_xml = args.model
model_bin = os.path.splitext(model_xml)[0] + ".bin"
# Plugin initialization for specified device and load extensions library if specified
log.info("Initializing plugin for {} device...".format(args.device))
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)
# Read IR
log.info("Reading IR...")
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 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)))
log.error("Please try to specify cpu extensions library path in demo's command line parameters using -l "
"or --cpu_extension command line argument")
sys.exit(1)
assert len(net.inputs.keys()) == 1, "Demo supports only single input topologies"
assert len(net.outputs) == 1, "Demo supports only single output topologies"
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
log.info("Loading IR to the plugin...")
exec_net = plugin.load(network=net, num_requests=2)
def __init__(self, model_path, device, cpu_extension):
ie = IECore()
if device == 'CPU':
ie.add_extension(cpu_extension, 'CPU')
path = '.'.join(model_path.split('.')[:-1])
self.net = IENetwork(model=path + '.xml', weights=path + '.bin')
self.exec_net = ie.load_network(network=self.net, device_name=device)
def main():
log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
args = build_argparser().parse_args()
model_xml = args.model
model_bin = os.path.splitext(model_xml)[0] + ".bin"
# Plugin initialization for specified device and load extensions library if specified
log.info("Initializing plugin for {} device...".format(args.device))
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)
# Read IR
log.info("Reading IR...")
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 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)))
log.error("Please try to specify cpu extensions library path in demo's command line parameters using -l "
"or --cpu_extension command line argument")
sys.exit(1)
assert len(net.inputs.keys()) == 1, "Demo supports only single input topologies"
assert len(net.outputs) == 1, "Demo supports only single output topologies"
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
log.info("Loading IR to the plugin...")
exec_net = plugin.load(network=net, num_requests=2)
def get_net(model: str):
model_xml = model
model_bin = os.path.splitext(model_xml)[0] + ".bin"
net = IENetwork(model=model_xml, weights=model_bin)
return net
def _create_network(self, input_shapes=None):
assert self.plugin, "create_ie_plugin should be called before _create_network"
self.network = ie.IENetwork(model=str(self._model), weights=str(self._weights))
self.original_outputs = self.network.outputs
outputs = self.config.get('outputs')
if outputs:
def output_preprocessing(output_string):
output_tuple = string_to_tuple(output_string, casting_type=None)
if len(output_tuple) == 1:
return output_string
return tuple([output_tuple[0], int(output_tuple[1])])
preprocessed_outputs = [output_preprocessing(output) for output in outputs]
self.network.add_outputs(preprocessed_outputs)
if input_shapes is not None:
self.network.reshape(input_shapes)
self._batch = self.config.get('batch', self.network.batch_size)
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 = {}
image = ARGS.image
labels = ARGS.labels
ir = ARGS.ir
threshold = ARGS.threshold
# Prepare Categories
with open(labels) as labels_file:
label_list = labels_file.read().splitlines()
print(YELLOW + 'Running NCS Caffe TinyYolo example...')
####################### 1. Setup Plugin and Network #######################
# Select the myriad plugin and IRs to be used
ie = IECore()
net = IENetwork(model = ir, weights = ir[:-3] + 'bin')
# Set up the input and output blobs
input_blob = next(iter(net.inputs))
output_blob = next(iter(net.outputs))
input_shape = net.inputs[input_blob].shape
output_shape = net.outputs[output_blob].shape
# Display model information
display_info(input_shape, output_shape, image, ir, labels)
# Load the network and get the network shape information
exec_net = ie.load_network(network = net, device_name = DEVICE)
n, c, h, w = input_shape
# Read image from file, resize it to network width and height