def build(cls, model_name, model_version, model_xml, model_bin,
              mapping_config, batch_size_param, shape_param, num_ireq,
              target_device, plugin_config):
        plugin = IEPlugin(device=target_device,
                          plugin_dirs=GLOBAL_CONFIG['plugin_dir'])
        if GLOBAL_CONFIG['cpu_extension'] is not None \
                and 'CPU' in target_device:
            plugin.add_cpu_extension(GLOBAL_CONFIG['cpu_extension'])
        net = IENetwork(model=model_xml, weights=model_bin)
        batching_info = BatchingInfo(batch_size_param)
        shape_info = ShapeInfo(shape_param, net.inputs)
        if batching_info.mode == BatchingMode.FIXED:
            net.batch_size = batching_info.batch_size
        else:
            batching_info.batch_size = net.batch_size

        effective_batch_size = batching_info.get_effective_batch_size()
        logger.debug(
            "[Model: {}, version: {}] --- effective batch size - {}".format(
                model_name, model_version, effective_batch_size))
        ###############################
        # Initial shape setup
        if shape_info.mode == ShapeMode.FIXED:
            logger.debug("[Model: {}, version: {}] --- Setting shape to "
                         "fixed value: {}".format(model_name, model_version,
                                                  shape_info.shape))
            net.reshape(shape_info.shape)
        elif shape_info.mode == ShapeMode.AUTO:
            logger.debug("[Model: {}, version: {}] --- Setting shape to "
                         "automatic".format(model_name, model_version))
            net.reshape({})
        elif shape_info.mode == ShapeMode.DEFAULT:
            logger.debug("[Model: {}, version: {}] --- Setting shape to "
                         "default".format(model_name, model_version))
        ###############################
        # Creating free infer requests indexes queue
        free_ireq_index_queue = queue.Queue(maxsize=num_ireq)
        for ireq_index in range(num_ireq):
            free_ireq_index_queue.put(ireq_index)
        ###############################
        requests_queue = queue.Queue(
            maxsize=GLOBAL_CONFIG['engine_requests_queue_size'])

        exec_net = plugin.load(network=net,
                               num_requests=num_ireq,
                               config=plugin_config)
        ir_engine = cls(model_name=model_name,
                        model_version=model_version,
                        mapping_config=mapping_config,
                        net=net,
                        plugin=plugin,
                        exec_net=exec_net,
                        batching_info=batching_info,
                        shape_info=shape_info,
                        free_ireq_index_queue=free_ireq_index_queue,
                        num_ireq=num_ireq,
                        requests_queue=requests_queue,
                        target_device=target_device,
                        plugin_config=plugin_config)
        return ir_engine
Пример #2
0
def get_fake_ir_engine():
    mapping_config = 'mapping_config.json'
    exec_net = MockedExecNet()
    net = MockedNet(
        inputs={DEFAULT_INPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
        outputs={DEFAULT_OUTPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')})
    core = None
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    requests_queue = queue.Queue()
    free_ireq_index_queue = queue.Queue(maxsize=1)
    free_ireq_index_queue.put(0)
    engine = IrEngine(model_name='test',
                      model_version=1,
                      mapping_config=mapping_config,
                      exec_net=exec_net,
                      net=net,
                      core=core,
                      batching_info=batching_info,
                      shape_info=shape_info,
                      target_device="CPU",
                      free_ireq_index_queue=free_ireq_index_queue,
                      plugin_config=None,
                      num_ireq=1,
                      requests_queue=requests_queue)
    return engine
Пример #3
0
def test_init_class():
    mapping_config = 'mapping_config.json'
    exec_net = None
    net = MockedNet(inputs={'input': MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
                    outputs={'output': MockedIOInfo('FP32', [1, 1], 'NCHW')})
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    plugin = None
    requests_queue = queue.Queue()
    free_ireq_index_queue = queue.Queue(maxsize=1)
    free_ireq_index_queue.put(0)
    engine = IrEngine(model_name='test',
                      model_version=1,
                      mapping_config=mapping_config,
                      exec_net=exec_net,
                      net=net,
                      plugin=plugin,
                      batching_info=batching_info,
                      shape_info=shape_info,
                      num_ireq=1,
                      free_ireq_index_queue=free_ireq_index_queue,
                      requests_queue=requests_queue,
                      target_device='CPU',
                      plugin_config=None)
    assert exec_net == engine.exec_net
    assert list(net.inputs.keys()) == engine.input_tensor_names
    assert list(net.outputs.keys()) == engine.output_tensor_names
    assert engine.free_ireq_index_queue.qsize() == 1
Пример #4
0
def get_fake_model():
    mapping_config = 'mapping_config.json'
    exec_net = None
    net = MockedNet(
        inputs={DEFAULT_INPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
        outputs={DEFAULT_OUTPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')})
    plugin = None
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    new_engines = {}
    available_versions = [1, 2, 3]
    for version in available_versions:
        engine = IrEngine(model_name='test',
                          model_version=version,
                          mapping_config=mapping_config,
                          exec_net=exec_net,
                          net=net,
                          plugin=plugin,
                          batching_info=batching_info,
                          shape_info=shape_info)
        new_engines.update({version: engine})
    model_name = "test"
    versions_statuses = {}
    batch_size_param, shape_param = None, None
    for version in available_versions:
        versions_statuses[version] = ModelVersionStatus(model_name, version)
    new_model = LocalModel(model_name=model_name,
                           model_directory='fake_path/model/',
                           available_versions=available_versions,
                           engines=new_engines,
                           batch_size_param=batch_size_param,
                           shape_param=shape_param,
                           version_policy_filter=lambda versions: versions[:],
                           versions_statuses=versions_statuses)
    return new_model
Пример #5
0
    def build(cls, model_name, model_version, model_xml, model_bin,
              mapping_config, batch_size_param, shape_param):
        plugin = IEPlugin(device=DEVICE, plugin_dirs=PLUGIN_DIR)
        if CPU_EXTENSION and 'CPU' in DEVICE:
            plugin.add_cpu_extension(CPU_EXTENSION)
        net = IENetwork(model=model_xml, weights=model_bin)
        batching_info = BatchingInfo(batch_size_param)
        shape_info = ShapeInfo(shape_param, net.inputs)
        if batching_info.mode == BatchingMode.FIXED:
            net.batch_size = batching_info.batch_size
        else:
            batching_info.batch_size = net.batch_size

        effective_batch_size = batching_info.get_effective_batch_size()
        logger.debug(
            "[Model: {}, version: {}] --- effective batch size - {}".format(
                model_name, model_version, effective_batch_size))
        ###############################
        # Initial shape setup
        if shape_info.mode == ShapeMode.FIXED:
            logger.debug("[Model: {}, version: {}] --- Setting shape to "
                         "fixed value: {}".format(model_name, model_version,
                                                  shape_info.shape))
            net.reshape(shape_info.shape)
        elif shape_info.mode == ShapeMode.AUTO:
            logger.debug("[Model: {}, version: {}] --- Setting shape to "
                         "automatic".format(model_name, model_version))
            net.reshape({})
        elif shape_info.mode == ShapeMode.DEFAULT:
            logger.debug("[Model: {}, version: {}] --- Setting shape to "
                         "default".format(model_name, model_version))
        ###############################

        exec_net = plugin.load(network=net, num_requests=1)
        ir_engine = cls(model_name=model_name,
                        model_version=model_version,
                        mapping_config=mapping_config,
                        net=net,
                        plugin=plugin,
                        exec_net=exec_net,
                        batching_info=batching_info,
                        shape_info=shape_info)
        return ir_engine
def test_init_class():
    mapping_config = 'mapping_config.json'
    exec_net = None
    net = MockedNet(inputs={'input': MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
                    outputs={'output': MockedIOInfo('FP32', [1, 1], 'NCHW')})
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    plugin = None
    engine = IrEngine(model_name='test', model_version=1,
                      mapping_config=mapping_config,
                      exec_net=exec_net,
                      net=net, plugin=plugin, batching_info=batching_info,
                      shape_info=shape_info)
    assert exec_net == engine.exec_net
    assert list(net.inputs.keys()) == engine.input_tensor_names
    assert list(net.outputs.keys()) == engine.output_tensor_names
Пример #7
0
def get_fake_model():
    mapping_config = 'mapping_config.json'
    exec_net = MockedExecNet()
    net = MockedNet(
        inputs={DEFAULT_INPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
        outputs={DEFAULT_OUTPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')})
    core = None
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    new_engines = {}
    available_versions = [1, 2, 3]
    requests_queue = queue.Queue()
    free_ireq_index_queue = queue.Queue(maxsize=1)
    free_ireq_index_queue.put(0)
    for version in available_versions:
        engine = IrEngine(model_name='test',
                          model_version=version,
                          mapping_config=mapping_config,
                          exec_net=exec_net,
                          net=net,
                          core=core,
                          batching_info=batching_info,
                          shape_info=shape_info,
                          target_device="CPU",
                          free_ireq_index_queue=free_ireq_index_queue,
                          plugin_config=None,
                          num_ireq=1,
                          requests_queue=requests_queue)
        new_engines.update({version: engine})
    model_name = "test"
    versions_statuses = {}
    batch_size_param, shape_param = None, None
    for version in available_versions:
        versions_statuses[version] = ModelVersionStatus(model_name, version)
    new_model = LocalModel(model_name=model_name,
                           model_directory='fake_path/model/',
                           available_versions=available_versions,
                           engines=new_engines,
                           batch_size_param=batch_size_param,
                           shape_param=shape_param,
                           version_policy_filter=lambda versions: versions[:],
                           versions_statuses=versions_statuses,
                           update_locks={},
                           plugin_config=None,
                           target_device="CPU",
                           num_ireq=1)
    return new_model
Пример #8
0
def get_fake_ir_engine():
    mapping_config = 'mapping_config.json'
    exec_net = None
    net = MockedNet(
        inputs={DEFAULT_INPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
        outputs={DEFAULT_OUTPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')})
    plugin = None
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    engine = IrEngine(model_name='test',
                      model_version=1,
                      mapping_config=mapping_config,
                      exec_net=exec_net,
                      net=net,
                      plugin=plugin,
                      batching_info=batching_info,
                      shape_info=shape_info)
    return engine