Skip to content

Commit

Permalink
Adjust Python decoders tests to decoders module (#2741)
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
  • Loading branch information
klecki committed Mar 1, 2021
1 parent 8b5a334 commit ef85a60
Show file tree
Hide file tree
Showing 48 changed files with 175 additions and 175 deletions.
2 changes: 1 addition & 1 deletion dali/python/nvidia/dali/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ def pipeline_def(fn=None, **pipeline_kwargs):
def my_pipe(flip_vertical, flip_horizontal):
''' Creates a DALI pipeline, which returns flipped and original images '''
data, _ = fn.readers.file(file_root=images_dir)
img = fn.image_decoder(data, device="mixed")
img = fn.decoders.image(data, device="mixed")
flipped = fn.flip(img, horizontal=flip_horizontal, vertical=flip_vertical)
return flipped, img
Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/test_RN50_data_fw_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RN50Pipeline(Pipeline):
def __init__(self, batch_size, num_threads, device_id, num_gpus, data_paths, prefetch, fp16, nhwc):
super(RN50Pipeline, self).__init__(batch_size, num_threads, device_id, prefetch_queue_depth=prefetch)
self.input = ops.readers.File(file_root = data_paths[0], shard_id = device_id, num_shards = num_gpus)
self.decode_gpu = ops.ImageDecoder(device = "mixed", output_type = types.RGB)
self.decode_gpu = ops.decoders.Image(device = "mixed", output_type = types.RGB)
self.res = ops.RandomResizedCrop(device="gpu", size =(224,224))

layout = types.args.nhwc if nhwc else types.NCHW
Expand Down
10 changes: 5 additions & 5 deletions dali/test/python/test_RN50_data_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ def __init__(self, data_paths, num_shards, batch_size, num_threads, device_id, p
super(CommonPipeline, self).__init__(batch_size, num_threads, device_id, random_shuffle, prefetch_queue_depth=prefetch)
if decoder_type == 'roi':
print('Using nvJPEG with ROI decoding')
self.decode_gpu = ops.ImageDecoderRandomCrop(device = "mixed", output_type = types.RGB)
self.decode_gpu = ops.decoders.ImageRandomCrop(device = "mixed", output_type = types.RGB)
self.res = ops.Resize(device="gpu", resize_x=224, resize_y=224)
elif decoder_type == 'roi_split':
print('Using nvJPEG with ROI decoding and split CPU/GPU stages')
self.decode_gpu = ops.ImageDecoderRandomCrop(device = "mixed", output_type = types.RGB, split_stages=True)
self.decode_gpu = ops.decoders.ImageRandomCrop(device = "mixed", output_type = types.RGB, split_stages=True)
self.res = ops.Resize(device="gpu", resize_x=224, resize_y=224)
elif decoder_type == 'cached':
assert decoder_cache_params['cache_enabled'] == True
cache_size = decoder_cache_params['cache_size']
cache_threshold = decoder_cache_params['cache_threshold']
cache_type = decoder_cache_params['cache_type']
print('Using nvJPEG with cache (size : {} threshold: {}, type: {})'.format(cache_size, cache_threshold, cache_type))
self.decode_gpu = ops.ImageDecoder(device = "mixed", output_type = types.RGB,
self.decode_gpu = ops.decoders.Image(device = "mixed", output_type = types.RGB,
cache_size=cache_size, cache_threshold=cache_threshold,
cache_type=cache_type, cache_debug=False)
self.res = ops.RandomResizedCrop(device="gpu", size =(224,224))
elif decoder_type == 'split':
print('Using nvJPEG with split CPU/GPU stages')
self.decode_gpu = ops.ImageDecoder(device = "mixed", output_type = types.RGB, split_stages=True)
self.decode_gpu = ops.decoders.Image(device = "mixed", output_type = types.RGB, split_stages=True)
self.res = ops.RandomResizedCrop(device="gpu", size =(224,224))
else:
print('Using nvJPEG')
self.decode_gpu = ops.ImageDecoder(device = "mixed", output_type = types.RGB)
self.decode_gpu = ops.decoders.Image(device = "mixed", output_type = types.RGB)
self.res = ops.RandomResizedCrop(device="gpu", size =(224,224))

layout = types.NHWC if nhwc else types.NCHW
Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/test_coco_tfrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, args):
num_shards=1,
random_shuffle=False)

self.decode_gpu = ops.ImageDecoder(device="mixed", output_type=types.RGB)
self.decode_gpu = ops.decoders.Image(device="mixed", output_type=types.RGB)
self.cast = ops.Cast(dtype = types.INT32)
self.box_encoder = ops.BoxEncoder(
device="cpu",
Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self, args, data_path = test_data_path):
ltrb=True,
random_shuffle=False)

self.decode_gpu = ops.ImageDecoder(device="mixed", output_type=types.RGB)
self.decode_gpu = ops.decoders.Image(device="mixed", output_type=types.RGB)
self.box_encoder = ops.BoxEncoder(
device="cpu",
criteria=0.5,
Expand Down
14 changes: 7 additions & 7 deletions dali/test/python/test_dali_cpu_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_gpu_op_bad_device():
def check_mixed_op_bad_device(device_id):
pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=device_id)
input, _ = fn.readers.file(file_root=images_dir, shard_id=0, num_shards=1)
decoded = fn.image_decoder(input, device="mixed", output_type=types.RGB)
decoded = fn.decoders.image(input, device="mixed", output_type=types.RGB)
pipe.set_outputs(decoded)
assert_raises(RuntimeError, pipe.build)

Expand All @@ -97,7 +97,7 @@ def test_mixed_op_bad_device():
def test_image_decoder_cpu():
pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=None)
input, _ = fn.readers.file(file_root=images_dir, shard_id=0, num_shards=1)
decoded = fn.image_decoder(input, output_type=types.RGB)
decoded = fn.decoders.image(input, output_type=types.RGB)
pipe.set_outputs(decoded)
pipe.build()
for _ in range(3):
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_flip_cpu():
def test_image_decoder_crop_device():
pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=None)
input, _ = fn.readers.file(file_root=images_dir, shard_id=0, num_shards=1)
decoded = fn.image_decoder_crop(input, output_type=types.RGB, crop = (10, 10))
decoded = fn.decoders.image_crop(input, output_type=types.RGB, crop = (10, 10))
pipe.set_outputs(decoded)
pipe.build()
for _ in range(3):
Expand All @@ -183,7 +183,7 @@ def test_image_decoder_crop_device():
def test_image_decoder_random_crop_device():
pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=None)
input, _ = fn.readers.file(file_root=images_dir, shard_id=0, num_shards=1)
decoded = fn.image_decoder_random_crop(input, output_type=types.RGB)
decoded = fn.decoders.image_random_crop(input, output_type=types.RGB)
pipe.set_outputs(decoded)
pipe.build()
for _ in range(3):
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_transpose_cpu():
def test_audio_decoder_cpu():
pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=None)
input, _ = fn.readers.file(file_root=audio_dir, shard_id=0, num_shards=1)
decoded, _ = fn.audio_decoder(input)
decoded, _ = fn.decoders.audio(input)
pipe.set_outputs(decoded)
pipe.build()
for _ in range(3):
Expand Down Expand Up @@ -383,7 +383,7 @@ def get_shape():
input, _ = fn.readers.file(file_root=images_dir, shard_id=0, num_shards=1)
anchors = fn.external_source(source = get_anchors)
shape = fn.external_source(source = get_shape)
processed = fn.image_decoder_slice(input, anchors, shape)
processed = fn.decoders.image_slice(input, anchors, shape)
pipe.set_outputs(processed)
pipe.build()
for _ in range(3):
Expand Down Expand Up @@ -794,7 +794,7 @@ def test_separated_exec_setup():
batch_size = 128
pipe = Pipeline(batch_size=batch_size, num_threads=3, device_id=None, prefetch_queue_depth = {"cpu_size": 5, "gpu_size": 3})
inputs, labels = fn.readers.caffe(path = caffe_dir, shard_id = 0, num_shards = 1)
images = fn.image_decoder(inputs, output_type = types.RGB)
images = fn.decoders.image(inputs, output_type = types.RGB)
images = fn.resize(images, resize_x=224, resize_y=224)
images_cpu = fn.dump_image(images, suffix = "cpu")
pipe.set_outputs(images, images_cpu)
Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/test_dali_tf_dataset_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def mnist_pipeline(
with pipeline:
jpegs, labels = fn.readers.caffe2(
path=path, random_shuffle=True, shard_id=shard_id, num_shards=num_shards)
images = fn.image_decoder(jpegs, device='mixed' if device == 'gpu' else 'cpu', output_type=types.GRAY)
images = fn.decoders.image(jpegs, device='mixed' if device == 'gpu' else 'cpu', output_type=types.GRAY)
if device == 'gpu':
labels = labels.gpu()
images = fn.crop_mirror_normalize(
Expand Down
6 changes: 3 additions & 3 deletions dali/test/python/test_dali_tf_dataset_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestPipeline(pipeline.Pipeline):
def __init__(self, **kwargs):
super(TestPipeline, self).__init__(**kwargs)
self.reader = ops.readers.File(file_root=data_path, file_list=file_list_path)
self.decoder = ops.ImageDecoder(device='mixed')
self.decoder = ops.decoders.Image(device='mixed')

def define_graph(self):
data, _ = self.reader()
Expand Down Expand Up @@ -84,7 +84,7 @@ class TestPipeline(pipeline.Pipeline):
def __init__(self, **kwargs):
super(TestPipeline, self).__init__(**kwargs)
self.reader = ops.readers.File(file_root=data_path, file_list=file_list_path)
self.decoder = ops.ImageDecoder(device='mixed')
self.decoder = ops.decoders.Image(device='mixed')
self.resize = ops.Resize(device="gpu", resize_x = 200, resize_y = 200)

def define_graph(self):
Expand Down Expand Up @@ -125,7 +125,7 @@ class TestPipeline(pipeline.Pipeline):
def __init__(self, **kwargs):
super(TestPipeline, self).__init__(**kwargs)
self.reader = ops.readers.File(file_root=data_path, file_list=file_list_path)
self.decoder = ops.ImageDecoder(device='mixed')
self.decoder = ops.decoders.Image(device='mixed')
self.resize = ops.Resize(device="gpu", resize_x = 200, resize_y = 200)

def define_graph(self):
Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/test_dali_tf_plugin_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CommonPipeline(Pipeline):
def __init__(self, batch_size, num_threads, device_id):
super(CommonPipeline, self).__init__(batch_size, num_threads, device_id)

self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB)
self.decode = ops.decoders.Image(device = "mixed", output_type = types.RGB)
self.resize = ops.Resize(device = "gpu", interp_type = types.INTERP_LINEAR)
self.cmn = ops.CropMirrorNormalize(device = "gpu",
output_dtype = types.FLOAT,
Expand Down
12 changes: 6 additions & 6 deletions dali/test/python/test_dali_variable_batch_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
6. If your operator performs random operation, this approach won't provide
a comparable result. In this case, the best thing you can do is to check
whether the operator works, without qualitative comparison. Use `run_pipeline`
instead of `check_pipeline`.
instead of `check_pipeline`.
"""


Expand Down Expand Up @@ -602,7 +602,7 @@ def test_audio_decoders():
def audio_decoder_pipe(max_batch_size, input_data, device):
pipe = Pipeline(batch_size=max_batch_size, num_threads=4, device_id=0)
encoded = fn.external_source(source=input_data, cycle=False, device='cpu')
decoded, _ = fn.audio_decoder(encoded, downmix=True, sample_rate=12345, device=device)
decoded, _ = fn.decoders.audio(encoded, downmix=True, sample_rate=12345, device=device)
pipe.set_outputs(decoded)
return pipe

Expand All @@ -614,14 +614,14 @@ def test_image_decoders():
def image_decoder_pipe(max_batch_size, input_data, device):
pipe = Pipeline(batch_size=max_batch_size, num_threads=4, device_id=0)
encoded = fn.external_source(source=input_data, cycle=False, device='cpu')
decoded = fn.image_decoder(encoded, device=device)
decoded = fn.decoders.image(encoded, device=device)
pipe.set_outputs(decoded)
return pipe

def image_decoder_crop_pipe(max_batch_size, input_data, device):
pipe = Pipeline(batch_size=max_batch_size, num_threads=4, device_id=0)
encoded = fn.external_source(source=input_data, cycle=False, device='cpu')
decoded = fn.image_decoder_crop(encoded, device=device)
decoded = fn.decoders.image_crop(encoded, device=device)
pipe.set_outputs(decoded)
return pipe

Expand All @@ -630,14 +630,14 @@ def image_decoder_slice_pipe(max_batch_size, input_data, device):
encoded = fn.external_source(source=input_data, cycle=False, device='cpu')
anch = fn.constant(fdata=.1)
sh = fn.constant(fdata=.4)
decoded = fn.image_decoder_slice(encoded, anch, sh, axes=0, device=device)
decoded = fn.decoders.image_slice(encoded, anch, sh, axes=0, device=device)
pipe.set_outputs(decoded)
return pipe

def image_decoder_rcrop_pipe(max_batch_size, input_data, device):
pipe = Pipeline(batch_size=max_batch_size, num_threads=4, device_id=0)
encoded = fn.external_source(source=input_data, cycle=False, device='cpu')
decoded = fn.image_decoder_random_crop(encoded, device=device)
decoded = fn.decoders.image_random_crop(encoded, device=device)
pipe.set_outputs(decoded)
return pipe

Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/test_data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class CommonPipeline(Pipeline):
def __init__(self, batch_size, num_threads, device_id):
super(CommonPipeline, self).__init__(batch_size, num_threads, device_id)

self.decode_gpu = ops.ImageDecoder(device = "mixed", output_type = types.RGB)
self.decode_host = ops.ImageDecoder(device = "cpu", output_type = types.RGB)
self.decode_gpu = ops.decoders.Image(device = "mixed", output_type = types.RGB)
self.decode_host = ops.decoders.Image(device = "cpu", output_type = types.RGB)

def base_define_graph(self, inputs, labels):
images_gpu = self.decode_gpu(inputs)
Expand Down
8 changes: 4 additions & 4 deletions dali/test/python/test_detection_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def __init__(self, args, device_id, file_root, annotations_file):
ltrb=True,
random_shuffle=True)

self.decode_cpu = ops.ImageDecoder(device="cpu", output_type=types.RGB)
self.decode_crop = ops.ImageDecoderSlice(device="cpu", output_type=types.RGB)
self.decode_cpu = ops.decoders.Image(device="cpu", output_type=types.RGB)
self.decode_crop = ops.decoders.ImageSlice(device="cpu", output_type=types.RGB)

self.decode_gpu = ops.ImageDecoder(device="mixed", output_type=types.RGB, hw_decoder_load=0)
self.decode_gpu_crop = ops.ImageDecoderSlice(device="mixed", output_type=types.RGB)
self.decode_gpu = ops.decoders.Image(device="mixed", output_type=types.RGB, hw_decoder_load=0)
self.decode_gpu_crop = ops.decoders.ImageSlice(device="mixed", output_type=types.RGB)

self.ssd_crop = ops.SSDRandomCrop(
device="cpu", num_attempts=1, seed=args.seed)
Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/test_dltensor_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def __init__(self, device):
super(CommonPipeline, self).__init__(BATCH_SIZE, NUM_WORKERS, DEVICE_ID, seed=SEED,
exec_async=False, exec_pipelined=False)
self.input = ops.readers.File(file_root=images_dir)
self.decode = ops.ImageDecoder(device='mixed' if device == 'gpu' else 'cpu',
output_type=types.RGB)
self.decode = ops.decoders.Image(device='mixed' if device == 'gpu' else 'cpu',
output_type=types.RGB)
self.resize = ops.Resize(resize_x=400, resize_y=400, device=device)
self.flip = ops.Flip(device=device)

Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/test_fw_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def create_custom_pipeline(batch_size, num_threads, device_id, num_gpus, data_pa
with pipe:
jpegs, _ = fn.readers.file(
file_root=data_paths, shard_id=device_id, num_shards=num_gpus, name="Reader")
images = fn.image_decoder(jpegs, device="mixed", output_type=types.RGB)
images = fn.decoders.image(jpegs, device="mixed", output_type=types.RGB)
images = fn.random_resized_crop(images, size=(224, 224))
images = fn.crop_mirror_normalize(images,
dtype=types.FLOAT,
Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/test_gpu_python_function_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def __init__(self, function, device, num_outputs=1):
exec_async=False, exec_pipelined=False)
self.device = device
self.reader = ops.readers.File(file_root=images_dir)
self.decode = ops.ImageDecoder(device='cpu',
output_type=types.RGB)
self.decode = ops.decoders.Image(device='cpu',
output_type=types.RGB)
self.norm = ops.CropMirrorNormalize(std=255., mean=0., device=device, output_layout="HWC")
self.func = ops.PythonFunction(device=device, function=function, num_outputs=num_outputs)

Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/test_nvjpeg_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, batch_size, num_threads, device_id, cache_size):
policy = None
if cache_size > 0:
policy = "threshold"
self.decode = ops.ImageDecoder(device = 'mixed', output_type = types.RGB, cache_debug = False, cache_size = cache_size, cache_type = policy, cache_batch_copy = True)
self.decode = ops.decoders.Image(device = 'mixed', output_type = types.RGB, cache_debug = False, cache_size = cache_size, cache_type = policy, cache_batch_copy = True)

def define_graph(self):
jpegs, labels = self.input(name="Reader")
Expand Down
10 changes: 5 additions & 5 deletions dali/test/python/test_operator_audio_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def __init__(self):
super(DecoderPipeline, self).__init__(batch_size=8, num_threads=3, device_id=0,
exec_async=True, exec_pipelined=True)
self.file_source = ops.ExternalSource()
self.plain_decoder = ops.AudioDecoder(dtype = types.INT16)
self.resampling_decoder = ops.AudioDecoder(sample_rate=rate1, dtype = types.INT16)
self.downmixing_decoder = ops.AudioDecoder(downmix=True, dtype = types.INT16)
self.resampling_downmixing_decoder = ops.AudioDecoder(sample_rate=rate2, downmix=True,
quality=50, dtype = types.FLOAT)
self.plain_decoder = ops.decoders.Audio(dtype = types.INT16)
self.resampling_decoder = ops.decoders.Audio(sample_rate=rate1, dtype = types.INT16)
self.downmixing_decoder = ops.decoders.Audio(downmix=True, dtype = types.INT16)
self.resampling_downmixing_decoder = ops.decoders.Audio(sample_rate=rate2, downmix=True,
quality=50, dtype = types.FLOAT)

def define_graph(self):
self.raw_file = self.file_source()
Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/test_operator_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def test_compose_change_device():

size = fn.random.uniform(shape=2, range=(300,500))
c = ops.Compose([
ops.ImageDecoder(device="cpu"),
ops.decoders.Image(device="cpu"),
ops.Resize(size=size, device="gpu")
])
files, labels = fn.readers.caffe(path=caffe_db_folder, seed=1)
pipe.set_outputs(c(files), fn.resize(fn.image_decoder(files).gpu(), size=size))
pipe.set_outputs(c(files), fn.resize(fn.decoders.image(files).gpu(), size=size))

pipe.build()
out = pipe.run()
Expand Down
4 changes: 2 additions & 2 deletions dali/test/python/test_operator_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def test_constant_promotion_mixed():
pipe = Pipeline(1, 3, 0)
with pipe:
jpegs, _ = fn.readers.file(files=[filename])
from_reader = fn.image_decoder(jpegs, device="mixed")
from_constant = fn.image_decoder(file_contents, device="mixed")
from_reader = fn.decoders.image(jpegs, device="mixed")
from_constant = fn.decoders.image(file_contents, device="mixed")
pipe.set_outputs(from_constant, from_reader)
pipe.build()
from_reader, from_constant = pipe.run()
Expand Down
Loading

0 comments on commit ef85a60

Please sign in to comment.