-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
test_convolution.py
52 lines (40 loc) · 2.28 KB
/
test_convolution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
from openvino import Type
import openvino.runtime.opset8 as ov
@pytest.mark.parametrize(("strides", "pads_begin", "pads_end", "dilations", "expected_shape"), [
(np.array([1, 1]), np.array([1, 1]), np.array([1, 1]), np.array([1, 1]), [1, 1, 9, 9]),
(np.array([1, 1]), np.array([0, 0]), np.array([0, 0]), np.array([1, 1]), [1, 1, 7, 7]),
(np.array([2, 2]), np.array([0, 0]), np.array([0, 0]), np.array([1, 1]), [1, 1, 4, 4]),
(np.array([1, 1]), np.array([0, 0]), np.array([0, 0]), np.array([2, 2]), [1, 1, 5, 5]),
])
@pytest.mark.parametrize("op_name", ["Convolution", "convolution", "ConvolutionOpset8"])
def test_convolution_2d(strides, pads_begin, pads_end, dilations, expected_shape, op_name):
# input_x should have shape N(batch) x C x H x W
input_x = ov.parameter((1, 1, 9, 9), name="input_x", dtype=np.float32)
# filter weights should have shape M x C x kH x kW
input_filter = ov.parameter((1, 1, 3, 3), name="input_filter", dtype=np.float32)
node = ov.convolution(input_x, input_filter, strides, pads_begin, pads_end, dilations, name=op_name)
assert node.get_type_name() == "Convolution"
assert node.get_friendly_name() == op_name
assert node.get_output_size() == 1
assert list(node.get_output_shape(0)) == expected_shape
assert node.get_output_element_type(0) == Type.f32
@pytest.mark.parametrize("op_name", ["Convolution", "convolution", "ConvolutionOpset8"])
def test_convolution_backprop_data(op_name):
output_spatial_shape = [9, 9]
filter_shape = [1, 1, 3, 3]
data_shape = [1, 1, 7, 7]
strides = [1, 1]
data_node = ov.parameter(shape=data_shape)
filter_node = ov.parameter(shape=filter_shape)
output_shape_node = ov.constant(np.array(output_spatial_shape, dtype=np.int64))
deconvolution = ov.convolution_backprop_data(data_node, filter_node, strides, output_shape_node, name=op_name)
assert deconvolution.get_type_name() == "ConvolutionBackpropData"
assert deconvolution.get_friendly_name() == op_name
assert deconvolution.get_output_size() == 1
assert list(deconvolution.get_output_shape(0)) == [1, 1, 9, 9]
assert deconvolution.get_output_element_type(0) == Type.f32