/** * Copyright 2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_VISION_ASCEND_H_ #define MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_VISION_ASCEND_H_ #include #include #include #include #include #include "include/api/status.h" #include "minddata/dataset/include/constants.h" #include "minddata/dataset/include/transforms.h" namespace mindspore { namespace dataset { // Transform operations for performing computer vision. namespace vision { // Char arrays storing name of corresponding classes (in alphabetical order) constexpr char kDvppCropJpegOperation[] = "DvppCropJpeg"; constexpr char kDvppDecodeResizeOperation[] = "DvppDecodeResize"; constexpr char kDvppDecodeResizeCropOperation[] = "DvppDecodeResizeCrop"; constexpr char kDvppDecodeJpegOperation[] = "DvppDecodeJpeg"; constexpr char kDvppDecodePngOperation[] = "DvppDecodePng"; constexpr char kDvppResizeJpegOperation[] = "DvppResizeJpeg"; class DvppCropJpegOperation; class DvppDecodeResizeOperation; class DvppDecodeResizeCropOperation; class DvppDecodeJpegOperation; class DvppDecodePngOperation; class DvppResizeJpegOperation; /// \brief Function to create a DvppCropJpeg TensorOperation. /// \notes Tensor operation to crop JPEG image using the simulation algorithm of Ascend series /// chip DVPP module. It is recommended to use this algorithm in the following scenarios: /// When training, the DVPP of the Ascend chip is not used, /// and the DVPP of the Ascend chip is used during inference, /// and the accuracy of inference is lower than the accuracy of training; /// and the input image size should be in range [32*32, 2048*2048]. /// Only images with an even resolution can be output. The output of odd resolution is not supported. /// \param[in] crop vector representing the output size of the final crop image. /// \param[in] size A vector representing the output size of the intermediate resized image. /// If size is a single value, the shape will be a square. If size has 2 values, it should be (height, width). /// \return Shared pointer to the current TensorOperation. std::shared_ptr DvppCropJpeg(std::vector crop = {256, 256}); /// \brief Function to create a DvppDecodeResizeJpeg TensorOperation. /// \notes Tensor operation to decode and resize JPEG image using the simulation algorithm of Ascend series /// chip DVPP module. It is recommended to use this algorithm in the following scenarios: /// When training, the DVPP of the Ascend chip is not used, /// and the DVPP of the Ascend chip is used during inference, /// and the accuracy of inference is lower than the accuracy of training; /// and the input image size should be in range [32*32, 2048*2048]. /// Only images with an even resolution can be output. The output of odd resolution is not supported. /// \param[in] crop vector representing the output size of the final crop image. /// \param[in] size A vector representing the output size of the intermediate resized image. /// If size is a single value, smaller edge of the image will be resized to this value with /// the same image aspect ratio. If size has 2 values, it should be (height, width). /// \return Shared pointer to the current TensorOperation. std::shared_ptr DvppDecodeResizeJpeg(std::vector resize = {256, 256}); /// \brief Function to create a DvppDecodeResizeCropJpeg TensorOperation. /// \notes Tensor operation to decode and resize JPEG image using the simulation algorithm of Ascend series /// chip DVPP module. It is recommended to use this algorithm in the following scenarios: /// When training, the DVPP of the Ascend chip is not used, /// and the DVPP of the Ascend chip is used during inference, /// and the accuracy of inference is lower than the accuracy of training; /// and the input image size should be in range [32*32, 2048*2048]. /// Only images with an even resolution can be output. The output of odd resolution is not supported. /// \param[in] crop vector representing the output size of the final crop image. /// \param[in] Resize vector representing the output size of the intermediate resized image. /// If size is a single value, smaller edge of the image will be resized to the value with /// the same image aspect ratio. If size has 2 values, it should be (height, width). /// \return Shared pointer to the current TensorOperation. std::shared_ptr DvppDecodeResizeCropJpeg(std::vector crop = {224, 224}, std::vector resize = {256, 256}); /// \brief Function to create a DvppDecodeJpeg TensorOperation. /// \notes Tensor operation to decode JPEG image using the simulation algorithm of Ascend series /// chip DVPP module. It is recommended to use this algorithm in the following scenarios: /// When training, the DVPP of the Ascend chip is not used, /// and the DVPP of the Ascend chip is used during inference, /// and the accuracy of inference is lower than the accuracy of training; /// and the input image size should be in range [32*32, 2048*2048]. /// Only images with an even resolution can be output. The output of odd resolution is not supported. /// \return Shared pointer to the current TensorOperation. std::shared_ptr DvppDecodeJpeg(); /// \brief Function to create a DvppDecodePng TensorOperation. /// \notes Tensor operation to decode PNG image using the simulation algorithm of Ascend series /// chip DVPP module. It is recommended to use this algorithm in the following scenarios: /// When training, the DVPP of the Ascend chip is not used, /// and the DVPP of the Ascend chip is used during inference, /// and the accuracy of inference is lower than the accuracy of training; /// and the input image size should be in range [32*32, 2048*2048]. /// Only images with an even resolution can be output. The output of odd resolution is not supported. /// \return Shared pointer to the current TensorOperation. std::shared_ptr DvppDecodePng(); /// \brief Function to create a DvppResizeJpeg TensorOperation. /// \notes Tensor operation to resize JPEG image using Ascend series chip DVPP module. /// It is recommended to use this algorithm in the following scenarios: /// When training, the DVPP of the Ascend chip is not used, /// and the DVPP of the Ascend chip is used during inference, /// and the accuracy of inference is lower than the accuracy of training; /// and the input image size should be in range [32*32, 2048*2048]. /// Only images with an even resolution can be output. The output of odd resolution is not supported. /// \param[in] resize vector represents the shape of image after resize. /// \return Shared pointer to the current TensorOperation. std::shared_ptr DvppResizeJpeg(std::vector resize = {256, 256}); class DvppCropJpegOperation : public TensorOperation { public: explicit DvppCropJpegOperation(const std::vector &resize); ~DvppCropJpegOperation() = default; std::shared_ptr Build() override; Status ValidateParams() override; std::string Name() const override { return kDvppCropJpegOperation; } private: std::vector crop_; }; class DvppDecodeResizeOperation : public TensorOperation { public: explicit DvppDecodeResizeOperation(const std::vector &resize); ~DvppDecodeResizeOperation() = default; std::shared_ptr Build() override; Status ValidateParams() override; std::string Name() const override { return kDvppDecodeResizeOperation; } private: std::vector resize_; }; class DvppDecodeResizeCropOperation : public TensorOperation { public: explicit DvppDecodeResizeCropOperation(const std::vector &crop, const std::vector &resize); ~DvppDecodeResizeCropOperation() = default; std::shared_ptr Build() override; Status ValidateParams() override; std::string Name() const override { return kDvppDecodeResizeCropOperation; } private: std::vector crop_; std::vector resize_; }; class DvppDecodeJpegOperation : public TensorOperation { public: ~DvppDecodeJpegOperation() = default; std::shared_ptr Build() override; Status ValidateParams() override; std::string Name() const override { return kDvppDecodeJpegOperation; } }; class DvppDecodePngOperation : public TensorOperation { public: ~DvppDecodePngOperation() = default; std::shared_ptr Build() override; Status ValidateParams() override; std::string Name() const override { return kDvppDecodePngOperation; } }; class DvppResizeJpegOperation : public TensorOperation { public: explicit DvppResizeJpegOperation(const std::vector &resize); ~DvppResizeJpegOperation() = default; std::shared_ptr Build() override; Status ValidateParams() override; std::string Name() const override { return kDvppResizeJpegOperation; } private: std::vector resize_; }; } // namespace vision } // namespace dataset } // namespace mindspore #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_VISION_ASCEND_H_