Skip to content

Commit cd8a0e6

Browse files
committed
Fix ONNX compatibility and numpy warnings
1 parent e71d6c6 commit cd8a0e6

File tree

16 files changed

+58
-64
lines changed

16 files changed

+58
-64
lines changed

src/bindings/python/requirements_test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ flake8_pep3101
2323
flake8_quotes
2424
import-order
2525
mypy
26-
onnx<1.12.0
26+
onnx<=1.12.0
2727
Pep8-naming
2828
pydocstyle
2929
pytest-xdist

src/bindings/python/tests/test_frontend/test_frontend_onnx.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ def create_onnx_model_with_custom_attributes():
7575
attribute_i32=np.int32(10),
7676
attribute_i64=np.int64(10),
7777
attribute_str="string",
78-
attribute_f32=np.float(10),
78+
attribute_f32=float(10),
7979
attribute_f64=np.float64(10),
80-
attribute_bool=np.bool(True),
80+
attribute_bool=True,
8181
attribute_type=onnx.TensorProto.INT32,
8282

8383
attribute_list_i32=np.array([1, 2, 3], dtype=np.int32),
8484
attribute_list_i64=np.array([1, 2, 3], dtype=np.int64),
85-
attribute_list_str=np.array(["a", "b", "c"], dtype=np.str),
86-
attribute_list_f32=np.array([1, 2, 3], dtype=np.float),
85+
attribute_list_str=np.array(["a", "b", "c"], dtype=str),
86+
attribute_list_f32=np.array([1, 2, 3], dtype=float),
8787
attribute_list_f64=np.array([1, 2, 3], dtype=np.float64),
8888
attribute_list_bool=[True, False, True],
8989
attribute_list_type=np.array([onnx.TensorProto.INT32,
@@ -340,15 +340,15 @@ def check_attribute(context, name, default_value):
340340
check_attribute(node, "attribute_str", "abc")
341341
check_attribute(node, "attribute_f32", np.float32(5))
342342
check_attribute(node, "attribute_f64", np.float64(5))
343-
check_attribute(node, "attribute_bool", np.bool(False))
343+
check_attribute(node, "attribute_bool", False)
344344
check_attribute(node, "attribute_type", onnx.TensorProto.FLOAT)
345345

346346
check_attribute(node, "attribute_list_i32", np.array([4, 5, 6], dtype=np.int32))
347347
check_attribute(node, "attribute_list_i64", np.array([4, 5, 6], dtype=np.int64))
348-
check_attribute(node, "attribute_list_str", np.array(["d", "e", "f"], dtype=np.str))
349-
check_attribute(node, "attribute_list_f32", np.array([4, 5, 6], dtype=np.float))
348+
check_attribute(node, "attribute_list_str", np.array(["d", "e", "f"], dtype=str))
349+
check_attribute(node, "attribute_list_f32", np.array([4, 5, 6], dtype=float))
350350
check_attribute(node, "attribute_list_f64", np.array([4, 5, 6], dtype=np.float64))
351-
check_attribute(node, "attribute_list_bool", np.array([True, False, True], dtype=np.bool))
351+
check_attribute(node, "attribute_list_bool", np.array([True, False, True], dtype=bool))
352352
check_attribute(node, "attribute_list_type", np.array([onnx.TensorProto.INT32,
353353
onnx.TensorProto.FLOAT]))
354354

@@ -395,15 +395,15 @@ def check_attribute(context, name, expected_value, dtype):
395395

396396
check_attribute(node, "attribute_i32", 10, float)
397397
check_attribute(node, "attribute_i64", 10, float)
398-
check_attribute(node, "attribute_str", "string", np.str)
398+
check_attribute(node, "attribute_str", "string", str)
399399
check_attribute(node, "attribute_f32", 10, int)
400400
check_attribute(node, "attribute_f64", 10, int)
401401
check_attribute(node, "attribute_bool", True, bool)
402402
check_attribute(node, "attribute_type", Type.i32, Type)
403403

404404
check_attribute(node, "attribute_list_i32", [1., 2., 3.], float)
405405
check_attribute(node, "attribute_list_i64", [1., 2., 3.], float)
406-
check_attribute(node, "attribute_list_str", ["a", "b", "c"], np.str)
406+
check_attribute(node, "attribute_list_str", ["a", "b", "c"], str)
407407
check_attribute(node, "attribute_list_f32", [1, 2, 3], int)
408408
check_attribute(node, "attribute_list_f64", [1, 2, 3], int)
409409
check_attribute(node, "attribute_list_bool", [True, False, True], bool)

src/bindings/python/tests/test_graph/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_bad_data_shape():
249249

250250
def test_constant_get_data_bool():
251251
input_data = np.array([True, False, False, True])
252-
node = ops.constant(input_data, dtype=np.bool)
252+
node = ops.constant(input_data, dtype=bool)
253253
retrieved_data = node.get_data()
254254
assert np.allclose(input_data, retrieved_data)
255255

src/bindings/python/tests/test_graph/test_create_op.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def test_rnn_sequence():
792792

793793

794794
def test_loop():
795-
bool_val = [True] # np.array([1], dtype=np.bool)
795+
bool_val = [True] # np.array([1], dtype=bool)
796796
condition = ov.constant(bool_val)
797797
trip_count = ov.constant(16, dtype=np.int32)
798798
# Body parameters
@@ -1816,11 +1816,11 @@ def test_multiclass_nms():
18161816
0.0, -0.1, 1.0, 0.9, 0.0, 10.0, 1.0, 11.0,
18171817
0.0, 10.1, 1.0, 11.1, 0.0, 100.0, 1.0, 101.0], dtype="float32")
18181818
boxes_data = boxes_data.reshape([1, 6, 4])
1819-
box = ov.constant(boxes_data, dtype=np.float)
1819+
box = ov.constant(boxes_data, dtype=float)
18201820
scores_data = np.array([0.9, 0.75, 0.6, 0.95, 0.5, 0.3,
18211821
0.95, 0.75, 0.6, 0.80, 0.5, 0.3], dtype="float32")
18221822
scores_data = scores_data.reshape([1, 2, 6])
1823-
score = ov.constant(scores_data, dtype=np.float)
1823+
score = ov.constant(scores_data, dtype=float)
18241824

18251825
nms_node = ov.multiclass_nms(box, score, None, output_type="i32", nms_top_k=3,
18261826
iou_threshold=0.5, score_threshold=0.0, sort_result_type="classid",
@@ -1841,13 +1841,13 @@ def test_multiclass_nms():
18411841
[9.66, 3.36, 18.57, 13.26]],
18421842
[[6.50, 7.00, 13.33, 17.63],
18431843
[0.73, 5.34, 19.97, 19.97]]]).astype("float32")
1844-
box = ov.constant(boxes_data, dtype=np.float)
1844+
box = ov.constant(boxes_data, dtype=float)
18451845
scores_data = np.array([[0.34, 0.66],
18461846
[0.45, 0.61],
18471847
[0.39, 0.59]]).astype("float32")
1848-
score = ov.constant(scores_data, dtype=np.float)
1848+
score = ov.constant(scores_data, dtype=float)
18491849
rois_num_data = np.array([3]).astype("int32")
1850-
roisnum = ov.constant(rois_num_data, dtype=np.int)
1850+
roisnum = ov.constant(rois_num_data, dtype=int)
18511851
nms_node = ov.multiclass_nms(box, score, roisnum, output_type="i32", nms_top_k=3,
18521852
iou_threshold=0.5, score_threshold=0.0, sort_result_type="classid",
18531853
nms_eta=1.0)
@@ -1867,11 +1867,11 @@ def test_matrix_nms():
18671867
0.0, -0.1, 1.0, 0.9, 0.0, 10.0, 1.0, 11.0,
18681868
0.0, 10.1, 1.0, 11.1, 0.0, 100.0, 1.0, 101.0], dtype="float32")
18691869
boxes_data = boxes_data.reshape([1, 6, 4])
1870-
box = ov.constant(boxes_data, dtype=np.float)
1870+
box = ov.constant(boxes_data, dtype=float)
18711871
scores_data = np.array([0.9, 0.75, 0.6, 0.95, 0.5, 0.3,
18721872
0.95, 0.75, 0.6, 0.80, 0.5, 0.3], dtype="float32")
18731873
scores_data = scores_data.reshape([1, 2, 6])
1874-
score = ov.constant(scores_data, dtype=np.float)
1874+
score = ov.constant(scores_data, dtype=float)
18751875

18761876
nms_node = ov.matrix_nms(box, score, output_type="i32", nms_top_k=3,
18771877
score_threshold=0.0, sort_result_type="score", background_class=0,

src/bindings/python/tests/test_graph/test_if.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def create_simple_if_with_two_outputs(condition_val):
15-
condition = ov.constant(condition_val, dtype=np.bool)
15+
condition = ov.constant(condition_val, dtype=bool)
1616

1717
# then_body
1818
x_t = ov.parameter([], np.float32, "X")
@@ -54,7 +54,7 @@ def create_simple_if_with_two_outputs(condition_val):
5454

5555

5656
def create_diff_if_with_two_outputs(condition_val):
57-
condition = ov.constant(condition_val, dtype=np.bool)
57+
condition = ov.constant(condition_val, dtype=bool)
5858

5959
# then_body
6060
x_t = ov.parameter([2], np.float32, "X")
@@ -90,7 +90,7 @@ def create_diff_if_with_two_outputs(condition_val):
9090

9191

9292
def simple_if(condition_val):
93-
condition = ov.constant(condition_val, dtype=np.bool)
93+
condition = ov.constant(condition_val, dtype=bool)
9494
# then_body
9595
x_t = ov.parameter([2], np.float32, "X")
9696
y_t = ov.parameter([2], np.float32, "Y")
@@ -121,15 +121,15 @@ def simple_if(condition_val):
121121

122122

123123
def simple_if_without_parameters(condition_val):
124-
condition = ov.constant(condition_val, dtype=np.bool)
124+
condition = ov.constant(condition_val, dtype=bool)
125125

126126
# then_body
127-
then_constant = ov.constant(0.7, dtype=np.float)
127+
then_constant = ov.constant(0.7, dtype=float)
128128
then_body_res_1 = ov.result(then_constant)
129129
then_body = Model([then_body_res_1], [])
130130

131131
# else_body
132-
else_const = ov.constant(9.0, dtype=np.float)
132+
else_const = ov.constant(9.0, dtype=float)
133133
else_body_res_1 = ov.result(else_const)
134134
else_body = Model([else_body_res_1], [])
135135

@@ -180,7 +180,7 @@ def test_simple_if_without_body_parameters():
180180

181181

182182
def test_simple_if_basic():
183-
condition = ov.constant(True, dtype=np.bool)
183+
condition = ov.constant(True, dtype=bool)
184184
# then_body
185185
x_t = ov.parameter([2], np.float32, "X")
186186
y_t = ov.parameter([2], np.float32, "Y")

src/bindings/python/tests/test_graph/test_loop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def test_simple_loop():
2626
x_i = ov.parameter(input_shape, np.float32)
2727
y_i = ov.parameter(input_shape, np.float32)
2828
m_body = ov.parameter(input_shape, np.float32)
29-
bool_val = np.array([1], dtype=np.bool)
29+
bool_val = np.array([1], dtype=bool)
3030
bool_val[0] = True
3131
body_condition = ov.constant(bool_val)
3232
trip_count = ov.constant(10, dtype=np.int64)
33-
exec_condition = ov.constant(True, dtype=np.bool)
33+
exec_condition = ov.constant(True, dtype=bool)
3434

3535
add = ov.add(x_i, y_i)
3636
zo = ov.multiply(add, m_body)
@@ -66,7 +66,7 @@ def test_simple_loop():
6666

6767

6868
def test_loop_basic():
69-
bool_val = np.array([1], dtype=np.bool)
69+
bool_val = np.array([1], dtype=bool)
7070
bool_val[0] = True
7171
condition = ov.constant(bool_val)
7272
trip_count = ov.constant(16, dtype=np.int32)

src/bindings/python/tests/test_graph/test_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def test_select():
556556
runtime = get_runtime()
557557
computation = runtime.computation(function, *parameter_list)
558558
result = computation(
559-
np.array([[True, False]], dtype=np.bool),
559+
np.array([[True, False]], dtype=bool),
560560
np.array([[5, 6]], dtype=np.float32),
561561
np.array([[7, 8]], dtype=np.float32),
562562
)[0]

src/bindings/python/tests/test_graph/test_ops_binary.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ def test_binary_logical_op(graph_api_helper, numpy_function):
9191
runtime = get_runtime()
9292

9393
shape = [2, 2]
94-
parameter_a = ov.parameter(shape, name="A", dtype=np.bool)
95-
parameter_b = ov.parameter(shape, name="B", dtype=np.bool)
94+
parameter_a = ov.parameter(shape, name="A", dtype=bool)
95+
parameter_b = ov.parameter(shape, name="B", dtype=bool)
9696

9797
model = graph_api_helper(parameter_a, parameter_b)
9898
computation = runtime.computation(model, parameter_a, parameter_b)
9999

100-
value_a = np.array([[True, False], [False, True]], dtype=np.bool)
101-
value_b = np.array([[False, True], [False, True]], dtype=np.bool)
100+
value_a = np.array([[True, False], [False, True]], dtype=bool)
101+
value_b = np.array([[False, True], [False, True]], dtype=bool)
102102

103103
result = computation(value_a, value_b)
104104
expected = numpy_function(value_a, value_b)
@@ -112,11 +112,11 @@ def test_binary_logical_op(graph_api_helper, numpy_function):
112112
def test_binary_logical_op_with_scalar(graph_api_helper, numpy_function):
113113
runtime = get_runtime()
114114

115-
value_a = np.array([[True, False], [False, True]], dtype=np.bool)
116-
value_b = np.array([[False, True], [False, True]], dtype=np.bool)
115+
value_a = np.array([[True, False], [False, True]], dtype=bool)
116+
value_b = np.array([[False, True], [False, True]], dtype=bool)
117117

118118
shape = [2, 2]
119-
parameter_a = ov.parameter(shape, name="A", dtype=np.bool)
119+
parameter_a = ov.parameter(shape, name="A", dtype=bool)
120120

121121
model = graph_api_helper(parameter_a, value_b)
122122
computation = runtime.computation(model, parameter_a)

src/bindings/python/tests/test_graph/test_reduction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_reduction_ops(graph_api_helper, numpy_function, reduction_axes):
5353
def test_reduction_logical_ops(graph_api_helper, numpy_function, reduction_axes):
5454
shape = [2, 4, 3, 2]
5555
np.random.seed(133391)
56-
input_data = np.random.randn(*shape).astype(np.bool)
56+
input_data = np.random.randn(*shape).astype(bool)
5757

5858
expected = numpy_function(input_data, axis=tuple(reduction_axes))
5959
result = run_op_node([input_data], graph_api_helper, reduction_axes)

src/bindings/python/tests/test_graph/test_utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99

1010
def test_get_constant_from_source_success():
11-
dtype = np.int
12-
input1 = ov.opset8.parameter(Shape([5, 5]), dtype=dtype, name="input_1")
13-
input2 = ov.opset8.parameter(Shape([25]), dtype=dtype, name="input_2")
11+
input1 = ov.opset8.parameter(Shape([5, 5]), dtype=int, name="input_1")
12+
input2 = ov.opset8.parameter(Shape([25]), dtype=int, name="input_2")
1413
shape_of = ov.opset8.shape_of(input2, name="shape_of")
1514
reshape = ov.opset8.reshape(input1, shape_of, special_zero=True)
1615
folded_const = ov.utils.get_constant_from_source(reshape.input(1).get_source_output())
@@ -20,9 +19,8 @@ def test_get_constant_from_source_success():
2019

2120

2221
def test_get_constant_from_source_failed():
23-
dtype = np.int
24-
input1 = ov.opset8.parameter(Shape([5, 5]), dtype=dtype, name="input_1")
25-
input2 = ov.opset8.parameter(Shape([1]), dtype=dtype, name="input_2")
22+
input1 = ov.opset8.parameter(Shape([5, 5]), dtype=int, name="input_1")
23+
input2 = ov.opset8.parameter(Shape([1]), dtype=int, name="input_2")
2624
reshape = ov.opset8.reshape(input1, input2, special_zero=True)
2725
folded_const = ov.utils.get_constant_from_source(reshape.input(1).get_source_output())
2826

0 commit comments

Comments
 (0)