Skip to content

Commit

Permalink
Reintroduce "Move old ImageDecoder to legacy module and make the nvIm…
Browse files Browse the repository at this point in the history
…ageCodec based ImageDecoder the default" (#5470)

Replaces default ImageDecoders with the nvImageCodec based implementations.
Move former default decoders to a legacy module

Signed-off-by: Joaquin Anton <janton@nvidia.com>
  • Loading branch information
jantonguirao committed May 23, 2024
1 parent 708af60 commit 814d004
Show file tree
Hide file tree
Showing 34 changed files with 413 additions and 840 deletions.
3 changes: 1 addition & 2 deletions dali/operators/decoder/host/fused/host_decoder_crop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ HostDecoderCrop::HostDecoderCrop(const OpSpec &spec)
, CropAttr(spec) {
}

DALI_REGISTER_OPERATOR(decoders__ImageCrop, HostDecoderCrop, CPU);
DALI_REGISTER_OPERATOR(ImageDecoderCrop, HostDecoderCrop, CPU);
DALI_REGISTER_OPERATOR(legacy__decoders__ImageCrop, HostDecoderCrop, CPU);

} // namespace dali
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ HostDecoderRandomCrop::DeserializeCheckpoint(OpCheckpoint &cpt, const std::strin
SnapshotSerializer().Deserialize<std::vector<std::mt19937>>(data);
}

DALI_REGISTER_OPERATOR(decoders__ImageRandomCrop, HostDecoderRandomCrop, CPU);
DALI_REGISTER_OPERATOR(ImageDecoderRandomCrop, HostDecoderRandomCrop, CPU);
DALI_REGISTER_OPERATOR(legacy__decoders__ImageRandomCrop, HostDecoderRandomCrop, CPU);

} // namespace dali
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,7 +80,7 @@ TEST_F(ImageRandomCropCheckpointingTest_CPU, Simple) {
.AddArg("files", std::vector{filepath}));

pipe.AddOperator(
OpSpec("decoders__ImageRandomCrop")
OpSpec("legacy__decoders__ImageRandomCrop")
.AddInput("file", "cpu")
.AddOutput("decoded", "cpu"));

Expand Down
3 changes: 1 addition & 2 deletions dali/operators/decoder/host/fused/host_decoder_slice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ HostDecoderSlice::HostDecoderSlice(const OpSpec &spec)
, slice_attr_(spec) {
}

DALI_REGISTER_OPERATOR(decoders__ImageSlice, HostDecoderSlice, CPU);
DALI_REGISTER_OPERATOR(ImageDecoderSlice, HostDecoderSlice, CPU);
DALI_REGISTER_OPERATOR(legacy__decoders__ImageSlice, HostDecoderSlice, CPU);

} // namespace dali
3 changes: 1 addition & 2 deletions dali/operators/decoder/host/host_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void HostDecoder::RunImpl(SampleWorkspace &ws) {
std::memcpy(out_data, decoded.get(), volume(shape));
}

DALI_REGISTER_OPERATOR(decoders__Image, HostDecoder, CPU);
DALI_REGISTER_OPERATOR(ImageDecoder, HostDecoder, CPU);
DALI_REGISTER_OPERATOR(legacy__decoders__Image, HostDecoder, CPU);

} // namespace dali
76 changes: 17 additions & 59 deletions dali/operators/decoder/image_decoder.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -163,9 +163,12 @@ allocation might be useful to determine suitable values for ``device_memory_padd
)code",
false);

DALI_SCHEMA(decoders__Image)
DALI_SCHEMA(legacy__decoders__Image)
.DocStr(R"code(Decodes images.
.. warning::
This is a legacy implementation of the image decoder. Use the ``decoders`` module instead.
For jpeg images, depending on the backend selected ("mixed" and "cpu"), the implementation uses
the *nvJPEG* library or *libjpeg-turbo*, respectively. Other image formats are decoded
with *OpenCV* or other specific libraries, such as *libtiff*.
Expand Down Expand Up @@ -195,10 +198,13 @@ Please note that GPU acceleration for JPEG 2000 decoding is only available for C

// Fused

DALI_SCHEMA(decoders__ImageCrop)
DALI_SCHEMA(legacy__decoders__ImageCrop)
.DocStr(R"code(Decodes images and extracts regions-of-interest (ROI) that are specified
by fixed window dimensions and variable anchors.
.. warning::
This is a legacy implementation of the image decoder. Use the ``decoders`` module instead.
When possible, the argument uses the ROI decoding APIs (for example, *libjpeg-turbo* and *nvJPEG*)
to reduce the decoding time and memory usage. When the ROI decoding is not supported for a given
image format, it will decode the entire image and crop the selected ROI.
Expand All @@ -219,9 +225,12 @@ Supported formats: JPG, BMP, PNG, TIFF, PNM, PPM, PGM, PBM, JPEG 2000, WebP.
.AddParent("ImageDecoderAttr")
.AddParent("CropAttr");

DALI_SCHEMA(decoders__ImageRandomCrop)
DALI_SCHEMA(legacy__decoders__ImageRandomCrop)
.DocStr(R"code(Decodes images and randomly crops them.
.. warning::
This is a legacy implementation of the image decoder. Use the ``decoders`` module instead.
The cropping window's area (relative to the entire image) and aspect ratio can be restricted to
a range of values specified by ``area`` and ``aspect_ratio`` arguments, respectively.
Expand All @@ -246,9 +255,12 @@ Supported formats: JPG, BMP, PNG, TIFF, PNM, PPM, PGM, PBM, JPEG 2000, WebP.
.AddParent("RandomCropAttr");


DALI_SCHEMA(decoders__ImageSlice)
DALI_SCHEMA(legacy__decoders__ImageSlice)
.DocStr(R"code(Decodes images and extracts regions of interest.
.. warning::
This is a legacy implementation of the image decoder. Use the ``decoders`` module instead.
The slice can be specified by proving the start and end coordinates, or start coordinates
and shape of the slice. Both coordinates and shapes can be provided in absolute or relative terms.
Expand Down Expand Up @@ -311,58 +323,4 @@ Integer coordinates are interpreted as absolute coordinates, while float coordin
interpreted as absolute or relative coordinates, depending on the value of
``normalized_shape``.)code");


// Deprecated aliases

DALI_SCHEMA(ImageDecoder)
.DocStr("Legacy alias for :meth:`decoders.image`.")
.NumInput(1)
.NumOutput(1)
.AddParent("decoders__Image")
.MakeDocPartiallyHidden()
.Deprecate(
"decoders__Image",
R"code(In DALI 1.0 all decoders were moved into a dedicated :mod:`~nvidia.dali.fn.decoders`
submodule and renamed to follow a common pattern. This is a placeholder operator with identical
functionality to allow for backward compatibility.)code"); // Deprecated in 1.0

// Fused

DALI_SCHEMA(ImageDecoderCrop)
.DocStr("Legacy alias for :meth:`decoders.image_crop`.")
.NumInput(1)
.NumOutput(1)
.AddParent("decoders__ImageCrop")
.MakeDocPartiallyHidden()
.Deprecate(
"decoders__ImageCrop",
R"code(In DALI 1.0 all decoders were moved into a dedicated :mod:`~nvidia.dali.fn.decoders`
submodule and renamed to follow a common pattern. This is a placeholder operator with identical
functionality to allow for backward compatibility.)code"); // Deprecated in 1.0

DALI_SCHEMA(ImageDecoderRandomCrop)
.DocStr("Legacy alias for :meth:`decoders.image_random_crop`.")
.NumInput(1)
.NumOutput(1)
.AddParent("decoders__ImageRandomCrop")
.MakeDocPartiallyHidden()
.Deprecate(
"decoders__ImageRandomCrop",
R"code(In DALI 1.0 all decoders were moved into a dedicated :mod:`~nvidia.dali.fn.decoders`
submodule and renamed to follow a common pattern. This is a placeholder operator with identical
functionality to allow for backward compatibility.)code"); // Deprecated in 1.0


DALI_SCHEMA(ImageDecoderSlice)
.DocStr("Legacy alias for :meth:`decoders.image_slice`.")
.NumInput(1, 3)
.NumOutput(1)
.AddParent("decoders__ImageSlice")
.MakeDocPartiallyHidden()
.Deprecate(
"decoders__ImageSlice",
R"code(In DALI 1.0 all decoders were moved into a dedicated :mod:`~nvidia.dali.fn.decoders`
submodule and renamed to follow a common pattern. This is a placeholder operator with identical
functionality to allow for backward compatibility.)code"); // Deprecated in 1.0

} // namespace dali
5 changes: 2 additions & 3 deletions dali/operators/decoder/nvjpeg/fused/nvjpeg_decoder_crop.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

namespace dali {

DALI_REGISTER_OPERATOR(decoders__ImageCrop, nvJPEGDecoderCrop, Mixed);
DALI_REGISTER_OPERATOR(ImageDecoderCrop, nvJPEGDecoderCrop, Mixed);
DALI_REGISTER_OPERATOR(legacy__decoders__ImageCrop, nvJPEGDecoderCrop, Mixed);

} // namespace dali
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,6 @@ nvJPEGDecoderRandomCrop::DeserializeCheckpoint(OpCheckpoint &cpt, const std::str
SnapshotSerializer().Deserialize<std::vector<std::mt19937>>(data);
}

DALI_REGISTER_OPERATOR(decoders__ImageRandomCrop, nvJPEGDecoderRandomCrop, Mixed);
DALI_REGISTER_OPERATOR(ImageDecoderRandomCrop, nvJPEGDecoderRandomCrop, Mixed);
DALI_REGISTER_OPERATOR(legacy__decoders__ImageRandomCrop, nvJPEGDecoderRandomCrop, Mixed);

} // namespace dali
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,7 +80,7 @@ TEST_F(ImageRandomCropCheckpointingTest_GPU, Simple) {
.AddArg("files", std::vector{filepath}));

pipe.AddOperator(
OpSpec("decoders__ImageRandomCrop")
OpSpec("legacy__decoders__ImageRandomCrop")
.AddInput("file", "cpu")
.AddOutput("decoded", "gpu")
.AddArg("device", "mixed"));
Expand Down
5 changes: 2 additions & 3 deletions dali/operators/decoder/nvjpeg/fused/nvjpeg_decoder_slice.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

namespace dali {

DALI_REGISTER_OPERATOR(decoders__ImageSlice, nvJPEGDecoderSlice, Mixed);
DALI_REGISTER_OPERATOR(ImageDecoderSlice, nvJPEGDecoderSlice, Mixed);
DALI_REGISTER_OPERATOR(legacy__decoders__ImageSlice, nvJPEGDecoderSlice, Mixed);

} // namespace dali
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ bool nvjpegIsSymbolAvailable(const char *name) {

namespace dali {

DALI_REGISTER_OPERATOR(decoders__Image, nvJPEGDecoder, Mixed);
DALI_REGISTER_OPERATOR(ImageDecoder, nvJPEGDecoder, Mixed);
DALI_REGISTER_OPERATOR(legacy__decoders__Image, nvJPEGDecoder, Mixed);

} // namespace dali
Loading

0 comments on commit 814d004

Please sign in to comment.