Skip to content

Commit

Permalink
Revert "Move old ImageDecoder to legacy module and make the nvImageCo…
Browse files Browse the repository at this point in the history
…dec based ImageDecoder the default (#5445)" (#5464)

This reverts commit da8204c.
  • Loading branch information
jantonguirao committed May 13, 2024
1 parent 3640441 commit 37288b7
Show file tree
Hide file tree
Showing 32 changed files with 567 additions and 367 deletions.
3 changes: 2 additions & 1 deletion dali/operators/decoder/host/fused/host_decoder_crop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ HostDecoderCrop::HostDecoderCrop(const OpSpec &spec)
, CropAttr(spec) {
}

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

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

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

} // namespace dali
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019 NVIDIA CORPORATION. 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("legacy__decoders__ImageRandomCrop")
OpSpec("decoders__ImageRandomCrop")
.AddInput("file", "cpu")
.AddOutput("decoded", "cpu"));

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

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

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

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

} // namespace dali
76 changes: 59 additions & 17 deletions dali/operators/decoder/image_decoder.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019-2021, 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,12 +163,9 @@ allocation might be useful to determine suitable values for ``device_memory_padd
)code",
false);

DALI_SCHEMA(legacy__decoders__Image)
DALI_SCHEMA(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 @@ -198,13 +195,10 @@ Please note that GPU acceleration for JPEG 2000 decoding is only available for C

// Fused

DALI_SCHEMA(legacy__decoders__ImageCrop)
DALI_SCHEMA(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 @@ -225,12 +219,9 @@ Supported formats: JPG, BMP, PNG, TIFF, PNM, PPM, PGM, PBM, JPEG 2000, WebP.
.AddParent("ImageDecoderAttr")
.AddParent("CropAttr");

DALI_SCHEMA(legacy__decoders__ImageRandomCrop)
DALI_SCHEMA(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 @@ -255,12 +246,9 @@ Supported formats: JPG, BMP, PNG, TIFF, PNM, PPM, PGM, PBM, JPEG 2000, WebP.
.AddParent("RandomCropAttr");


DALI_SCHEMA(legacy__decoders__ImageSlice)
DALI_SCHEMA(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 @@ -323,4 +311,58 @@ 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: 3 additions & 2 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-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019, NVIDIA CORPORATION. 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,6 +17,7 @@

namespace dali {

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

} // namespace dali
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019, NVIDIA CORPORATION. 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,6 +40,7 @@ nvJPEGDecoderRandomCrop::DeserializeCheckpoint(OpCheckpoint &cpt, const std::str
SnapshotSerializer().Deserialize<std::vector<std::mt19937>>(data);
}

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

} // namespace dali
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019, NVIDIA CORPORATION. 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("legacy__decoders__ImageRandomCrop")
OpSpec("decoders__ImageRandomCrop")
.AddInput("file", "cpu")
.AddOutput("decoded", "gpu")
.AddArg("device", "mixed"));
Expand Down
5 changes: 3 additions & 2 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-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019, NVIDIA CORPORATION. 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,6 +17,7 @@

namespace dali {

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

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

namespace dali {

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

} // namespace dali
Loading

0 comments on commit 37288b7

Please sign in to comment.