Esempio n. 1
0
def test_is_dynamic():
    function = create_relu([-1, 3, 20, 20])
    net = ng.function_to_cnn(function)
    assert net.input_info["data"].input_data.is_dynamic
    assert net.outputs["out"].is_dynamic
    p_shape = ng.partial_shape_from_data(net.input_info["data"].input_data)
    assert isinstance(p_shape, ng.impl.PartialShape)
    p_shape = ng.partial_shape_from_data(net.outputs["out"])
    assert isinstance(p_shape, ng.impl.PartialShape)
    with pytest.raises(RuntimeError) as e:
        net.input_info["data"].input_data.shape
    assert  "Cannot return dims for Data with dynamic shapes!" in str(e.value)
    ie = IECore()
    ie.register_plugin("ov_template_plugin", "TEMPLATE")
    exec_net = ie.load_network(net, "TEMPLATE")
    assert exec_net.input_info["data"].input_data.is_dynamic
    p_shape = ng.partial_shape_from_data(exec_net.input_info["data"].input_data)
    assert isinstance(p_shape, ng.impl.PartialShape)
Esempio n. 2
0
    def get_dynamic_inputs(network):
        def is_dynamic(data_info):
            if hasattr(data_info, 'is_dynamic'):
                return data_info.is_dynamic
            return -1 in data_info.shape or not data_info.shape

        inputs_with_undefined_shapes = []
        outputs_with_undefined_shapes = []
        partial_shapes = {}
        if network is None:
            return inputs_with_undefined_shapes, partial_shapes

        for input_name, input_info in network.input_info.items():
            if is_dynamic(input_info.input_data):
                inputs_with_undefined_shapes.append(input_name)
        for out_name, out_info in network.outputs.items():
            if is_dynamic(out_info):
                outputs_with_undefined_shapes.append(out_name)
        if (inputs_with_undefined_shapes
                or outputs_with_undefined_shapes) and not isinstance(
                    ng, UnsupportedPackage):
            if hasattr(ng, 'partial_shape_from_data'):
                for input_name in inputs_with_undefined_shapes:
                    partial_shapes[input_name] = parse_partial_shape(
                        ng.partial_shape_from_data(
                            network.input_info[input_name].input_data))
                for out_name in outputs_with_undefined_shapes:
                    partial_shapes[out_name] = parse_partial_shape(
                        ng.partial_shape_from_data(network.outputs[out_name]))

            else:
                ng_function = ng.function_from_cnn(network)
                for node in ng_function.get_ordered_ops():
                    node_name = node.get_friendly_name()
                    if node_name not in inputs_with_undefined_shapes:
                        continue
                    partial_shapes[node_name] = node.get_partial_shape()

        return inputs_with_undefined_shapes, partial_shapes
Esempio n. 3
0
def test_is_dynamic():
    from conftest import create_ngraph_function
    import ngraph as ng
    function = create_ngraph_function([-1, 3, 20, 20])
    net = ng.function_to_cnn(function)
    ie = IECore()
    ie.register_plugin("templatePlugin", "TEMPLATE")
    exec_net = ie.load_network(net, "TEMPLATE")
    assert exec_net.outputs["out"].is_dynamic
    p_shape = ng.partial_shape_from_data(exec_net.outputs["out"])
    assert isinstance(p_shape, ng.impl.PartialShape)
    with pytest.raises(RuntimeError) as e:
       exec_net.outputs["out"].shape
    assert  "Cannot return dims for Data with dynamic shapes!" in str(e.value)