Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Joaquin Anton Guirao <[email protected]>
  • Loading branch information
jantonguirao committed Dec 19, 2024
1 parent c784fac commit ce3b3f7
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 35 deletions.
8 changes: 4 additions & 4 deletions dali/test/python/operator_1/test_arithmetic_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ def get_numpy_input(input, kind, orig_type, target_type):


def extract_un_data(pipe_out, sample_id, kind, target_type):
input = pipe_out[0].at(sample_id).as_cpu()
out = pipe_out[1].at(sample_id).as_cpu()
input = np.array(pipe_out[0].at(sample_id).as_cpu())
out = np.array(pipe_out[1].at(sample_id).as_cpu())
assert_equals(out.dtype, target_type)
in_np = get_numpy_input(input, kind, input.dtype.type, target_type)
return in_np, out
Expand All @@ -458,15 +458,15 @@ def extract_data(pipe_out, sample_id, kinds, target_type):
arity = len(kinds)
inputs = []
for i in range(arity):
dali_in = pipe_out[i].at(sample_id).as_cpu()
dali_in = np.array(pipe_out[i].at(sample_id).as_cpu())
numpy_in = get_numpy_input(
dali_in,
kinds[i],
dali_in.dtype.type,
target_type if target_type is not None else dali_in.dtype.type,
)
inputs.append(numpy_in)
out = pipe_out[arity].at(sample_id).as_cpu()
out = np.array(pipe_out[arity].at(sample_id).as_cpu())
return tuple(inputs) + (out,)


Expand Down
16 changes: 7 additions & 9 deletions dali/test/python/operator_1/test_coord_flip.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,20 @@ def check_operator_coord_flip(device, batch_size, layout, shape, center_x, cente
pipe = CoordFlipPipeline(device, batch_size, iter(eii1), layout, center_x, center_y, center_z)
pipe.build()
for i in range(30):
outputs = pipe.run()
outputs0, outputs1, outputs2, outputs3, outputs4 = pipe.run()
outputs1 = outputs1.as_cpu()
for sample in range(batch_size):
in_coords = outputs[0].at(sample)
if device == "gpu":
out_coords = outputs[1].at(sample).as_cpu()
else:
out_coords = outputs[1].at(sample)
in_coords = outputs0.at(sample)
out_coords = outputs1.at(sample)
if in_coords.shape == () or in_coords.shape[0] == 0:
assert out_coords.shape == () or out_coords.shape[0] == 0
continue

flip_x = outputs[2].at(sample)
flip_y = outputs[3].at(sample)
flip_x = outputs2.at(sample)
flip_y = outputs3.at(sample)
flip_z = None
if len(layout) == 3:
flip_z = outputs[4].at(sample)
flip_z = outputs4.at(sample)
_, ndim = in_coords.shape

flip_dim = [flip_x, flip_y]
Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/operator_1/test_input_promotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_slice_fn():
pipe.build()
o = pipe.run()
assert np.array_equal(o[0].at(0), np.array([[14], [17]]))
assert np.array_equal(o[1].at(0).as_cpu(), np.array([[14], [17]]))
assert np.array_equal(np.array(o[1].at(0).as_cpu()), np.array([[14], [17]]))


def test_slice_ops():
Expand All @@ -62,7 +62,7 @@ def test_slice_ops():
pipe.build()
o = pipe.run()
assert np.array_equal(o[0].at(0), np.array([[14], [17]]))
assert np.array_equal(o[1].at(0).as_cpu(), np.array([[14], [17]]))
assert np.array_equal(np.array(o[1].at(0).as_cpu()), np.array([[14], [17]]))


def test_python_function():
Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/operator_2/test_python_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from PIL import Image, ImageEnhance
from nvidia.dali.ops import _DataNode
from nose2.tools import params

import numpy as np
from nose_utils import raises
from test_utils import get_dali_extra_path, np_type_to_dali

Expand Down Expand Up @@ -320,7 +320,7 @@ def test_python_operator_brightness():
(numpy_output,) = numpy_brightness.run()
(dali_output,) = dali_brightness.run()
for i in range(len(dali_output)):
assert numpy.allclose(numpy_output.at(i), dali_output.at(i).as_cpu(), rtol=1e-5, atol=1)
assert numpy.allclose(numpy_output.at(i), np.array(dali_output.at(i).as_cpu()), rtol=1e-5, atol=1)


def invalid_function(image):
Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/operator_2/test_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ def resize_pipe():
pipe = resize_pipe()
pipe.build()
(outs,) = pipe.run()
out = outs.at(0).as_cpu()
out = np.array(outs.at(0).as_cpu())
global large_data_resized
if large_data_resized is None:
large_data_resized = make_cube(350, 224, 224)
Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/operator_2/test_resize_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def init_video_data():

video_pipe.build()
out = video_pipe.run()
in_seq = out[0].at(0).as_cpu()
in_seq = np.array(out[0].at(0).as_cpu())
return in_seq


Expand Down
16 changes: 8 additions & 8 deletions dali/test/python/operator_2/test_subscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_plain_indexing():
for i in range(len(inp)):
x = inp.at(i)
assert np.array_equal(x[1, 1], cpu.at(i))
assert np.array_equal(x[1, 1], gpu.at(i).as_cpu())
assert np.array_equal(x[1, 1], np.array(gpu.at(i).as_cpu()))


def _test_indexing(data_gen, input_layout, output_layout, dali_index_func, ref_index_func=None):
Expand All @@ -50,7 +50,7 @@ def _test_indexing(data_gen, input_layout, output_layout, dali_index_func, ref_i
x = inp.at(i)
ref = (ref_index_func or dali_index_func)(x)
assert np.array_equal(ref, cpu.at(i))
assert np.array_equal(ref, gpu.at(i).as_cpu())
assert np.array_equal(ref, np.array(gpu.at(i).as_cpu()))
assert cpu.layout() == output_layout
assert gpu.layout() == output_layout

Expand Down Expand Up @@ -94,7 +94,7 @@ def test_swapped_ends():
for i in range(len(inp)):
x = inp.at(i)
assert np.array_equal(x[2:1], cpu.at(i))
assert np.array_equal(x[2:1], gpu.at(i).as_cpu())
assert np.array_equal(x[2:1], np.array(gpu.at(i).as_cpu()))


def test_noop():
Expand Down Expand Up @@ -129,7 +129,7 @@ def data_gen():
j = (j + 1) % len(lo_idxs)
k = (k + 1) % len(hi_idxs)
assert np.array_equal(ref, cpu.at(i))
assert np.array_equal(ref, gpu.at(i).as_cpu())
assert np.array_equal(ref, np.array(gpu.at(i).as_cpu()))


def test_runtime_stride_dim1():
Expand All @@ -154,7 +154,7 @@ def data_gen():
ref = x[::strides[j]]
# fmt: on
assert np.array_equal(ref, cpu.at(i))
assert np.array_equal(ref, gpu.at(i).as_cpu())
assert np.array_equal(ref, np.array(gpu.at(i).as_cpu()))
j = (j + 1) % len(strides)


Expand All @@ -180,7 +180,7 @@ def data_gen():
ref = x[:, ::strides[j]]
# fmt: on
assert np.array_equal(ref, cpu.at(i))
assert np.array_equal(ref, gpu.at(i).as_cpu())
assert np.array_equal(ref, np.array(gpu.at(i).as_cpu()))
j = (j + 1) % len(strides)


Expand Down Expand Up @@ -304,7 +304,7 @@ def test_multiple_skipped_dims():
for i in range(len(inp)):
x = inp.at(i)
assert np.array_equal(x[1, :, :, 1], cpu.at(i))
assert np.array_equal(x[1, :, :, 1], gpu.at(i).as_cpu())
assert np.array_equal(x[1, :, :, 1], np.array(gpu.at(i).as_cpu()))


def test_empty_slice():
Expand All @@ -316,4 +316,4 @@ def test_empty_slice():
for i in range(len(inp)):
x = inp.at(i)
assert np.array_equal(x[0:0, 0:1], cpu.at(i))
assert np.array_equal(x[0:0, 0:1], gpu.at(i).as_cpu())
assert np.array_equal(x[0:0, 0:1], np.array(gpu.at(i).as_cpu()))
8 changes: 3 additions & 5 deletions dali/test/python/operator_2/test_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@ def get_data():
pipe.set_outputs(rotated)
pipe.build()

out = None
out_cpu = None
try:
(out,) = pipe.run()
out_cpu = out.as_cpu()
except RuntimeError as e:
if "bad_alloc" in str(e):
print("Skipping test due to out-of-memory error:", e)
Expand All @@ -296,10 +297,7 @@ def get_data():
except MemoryError as e:
print("Skipping test due to out-of-memory error:", e)
return
if device == "cpu":
out = out.at(0)
else:
out = out.at(0).as_cpu()
out = out_cpu.at(0)
assert out.shape == (out_size, out_size, channels)
for c in range(channels):
assert out[0, 0, c] == c
Expand Down
6 changes: 4 additions & 2 deletions dali/test/python/test_optical_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ def check_optflow(output_grid=1, hint_grid=1, use_temporal_hints=False):

for _ in range(2):
out = pipe.run()
out0 = out[0]
out1 = out[1].as_cpu()
for i in range(batch_size):
seq = out[0].at(i)
out_field = out[1].at(i).as_cpu()[0]
seq = out0.at(i)
out_field = out1.at(i)[0]
_, ref_field = get_mapping(seq.shape[1:3])
dsize = (out_field.shape[1], out_field.shape[0])
ref_field = cv2.resize(ref_field, dsize=dsize, interpolation=cv2.INTER_AREA)
Expand Down
3 changes: 2 additions & 1 deletion dali/test/python/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ def define_graph(self):
import cv2

orig_cpu = pipe_out[1].as_cpu()
dali_output_batch = pipe_out[2].as_cpu()
for i in range(128):
orig = orig_cpu.at(i)
# apply 0.5 correction for opencv's not-so-good notion of pixel centers
Expand All @@ -696,7 +697,7 @@ def define_graph(self):
borderValue=(128, 128, 128),
flags=(cv2.WARP_INVERSE_MAP + cv2.INTER_LINEAR),
)
dali_output = pipe_out[2].at(i).as_cpu()
dali_output = dali_output_batch.at(i)
maxdif = np.max(cv2.absdiff(out, dali_output) / 255.0)
assert maxdif < 0.025

Expand Down

0 comments on commit ce3b3f7

Please sign in to comment.