From 0e4364d12e903b52371fa0e6cd25d0a090584923 Mon Sep 17 00:00:00 2001 From: xulei2020 <“xulei83@huawei.com”> Date: Tue, 8 Dec 2020 19:02:12 +0800 Subject: [PATCH] add code --- .../dataset/kernels/image/lite_image_utils.h | 5 +++++ mindspore/lite/minddata/wrapper/MDToDApi.cc | 16 ++++++++++------ mindspore/lite/minddata/wrapper/MDToDApi.h | 2 ++ .../lite/minddata/wrapper/album_op_android.h | 13 ++++++++----- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h index 7c38e2257ca..72276cc7fb6 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h @@ -110,7 +110,12 @@ Status Pad(const std::shared_ptr &input, std::shared_ptr *output const int32_t &pad_bottom, const int32_t &pad_left, const int32_t &pad_right, const BorderType &border_types, uint8_t fill_r = 0, uint8_t fill_g = 0, uint8_t fill_b = 0); +/// \brief Rotate the input image by orientation +/// \param input: input Tensor +/// \param output: padded Tensor +/// \param orientation: the orientation of EXIF Status Rotate(const std::shared_ptr &input, std::shared_ptr *output, const uint64_t orientation); + } // namespace dataset } // namespace mindspore #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_ diff --git a/mindspore/lite/minddata/wrapper/MDToDApi.cc b/mindspore/lite/minddata/wrapper/MDToDApi.cc index 55ccbf92aa3..2d703b9eb33 100644 --- a/mindspore/lite/minddata/wrapper/MDToDApi.cc +++ b/mindspore/lite/minddata/wrapper/MDToDApi.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include "album_op_android.h" //NOLINT #include "minddata/dataset/include/execute.h" @@ -115,13 +116,13 @@ extern "C" MDToDApi *MDToDApi_createPipeLine(MDToDConf_t MDConf) { MS_LOG(WARNING) << "MEAN: { " << MDConf.MEAN[0] << ", " << MDConf.MEAN[1] << ", " << MDConf.MEAN[2] << " }"; MS_LOG(WARNING) << "STD: { " << MDConf.STD[0] << ", " << MDConf.STD[1] << ", " << MDConf.STD[2] << " }"; - MDConf.ResizeSizeWH[0] = 224; - MDConf.ResizeSizeWH[1] = 224; if ((MDConf.ResizeSizeWH[0] != 0) && (MDConf.ResizeSizeWH[1] != 0)) { std::shared_ptr resize_op = mindspore::dataset::vision::Resize({MDConf.ResizeSizeWH[0], MDConf.ResizeSizeWH[1]}); MS_LOG(WARNING) << "Push back resize"; mapOperations.push_back(resize_op); + } + if (1 == MDConf.fixOrientation) { std::shared_ptr rotate_op = mindspore::dataset::vision::Rotate(); MS_LOG(WARNING) << "Push back rotate"; mapOperations.push_back(rotate_op); @@ -166,7 +167,7 @@ extern "C" MDToDApi *MDToDApi_createPipeLine(MDToDConf_t MDConf) { } template -void MDBuffToVector(const MDToDBuff_t MDBuff, std::vector *vec) { +void MDBuffToVector(const MDToDBuff_t &MDBuff, std::vector *vec) { vec->clear(); if (MDBuff.DataSize > 0) { int nofElements = MDBuff.DataSize / sizeof(T); @@ -270,12 +271,13 @@ extern "C" int MDToDApi_GetNext(MDToDApi *pMDToDApi, MDToDResult_t *results) { // create Execute functions, this replaces Map in Pipeline bool ret = pMDToDApi->_iter->GetNextRow(&row); + uint32_t orientation = 0; if (row.size() != 0 && ret) { + GetValue(row, "orientation", &orientation); + MS_LOG(WARNING) << "get orientation from row = " << orientation; if ((pMDToDApi->_augs).size() > 0) { // String and Tensors - uint32_t orientation; - row["orientation"]->GetItemAt(&orientation, {}); - MS_LOG(WARNING) << "get orientation from row = " << orientation; + // for each operation, run eager mode, single threaded operation, will have to memcpy // regardless for (int i = 0; i < (pMDToDApi->_augs).size(); i++) { @@ -285,6 +287,7 @@ extern "C" int MDToDApi_GetNext(MDToDApi *pMDToDApi, MDToDResult_t *results) { if (orientation > 1) { RotateOperation *p = static_cast(pMDToDApi->_augs[i].get()); p->setAngle(orientation); + orientation = 0; // clear oriation filed if allready preformed } else { continue; } @@ -302,6 +305,7 @@ extern "C" int MDToDApi_GetNext(MDToDApi *pMDToDApi, MDToDResult_t *results) { // IS FOR TRAIN GetValue(row, "_isForTrain", &results->isForTrain); GetValue(row, "_noOfFaces", &results->noOfFaces); + results->orientation = (int32_t)orientation; // String and Tensors GetTensorToBuff(row, "image_filename", pMDToDApi->_hasBatch, &results->fileNameBuff); GetTensorToBuff(row, "image", pMDToDApi->_hasBatch, &results->imageBuff); diff --git a/mindspore/lite/minddata/wrapper/MDToDApi.h b/mindspore/lite/minddata/wrapper/MDToDApi.h index 5b76e8959be..4568eca9866 100644 --- a/mindspore/lite/minddata/wrapper/MDToDApi.h +++ b/mindspore/lite/minddata/wrapper/MDToDApi.h @@ -36,6 +36,7 @@ typedef struct MDToDConf { float MEAN[3]; float STD[3]; int ResizeSizeWH[2]; + int fixOrientation; int CropSizeWH[2]; int64_t fileid; // -1 All files, otherwise get a single specifc file } MDToDConf_t; @@ -44,6 +45,7 @@ typedef struct MDToDResult { int64_t fileid; int32_t isForTrain; int32_t noOfFaces; + int32_t orientation; MDToDBuff_t fileNameBuff; MDToDBuff_t labelBuff; MDToDBuff_t imageBuff; diff --git a/mindspore/lite/minddata/wrapper/album_op_android.h b/mindspore/lite/minddata/wrapper/album_op_android.h index d9e472252ab..b63e36b9c7c 100644 --- a/mindspore/lite/minddata/wrapper/album_op_android.h +++ b/mindspore/lite/minddata/wrapper/album_op_android.h @@ -48,8 +48,8 @@ class AlbumOp { /// \param[in] file_dir - directory of Album /// \param[in] do_decode - decode image files /// \param[in] schema_file - schema file + /// \param[in] column_names - column name /// \param[in] exts - set of file extensions to read, if empty, read everything under the dir - /// \param[in] rotate - rotate image exif orientation AlbumOp(const std::string &file_dir, bool do_decode, const std::string &schema_file, const std::vector &column_names, const std::set &exts); @@ -57,9 +57,9 @@ class AlbumOp { /// \param[in] file_dir - directory of Album /// \param[in] do_decode - decode image files /// \param[in] schema_file - schema file + /// \param[in] column_names - column name /// \param[in] exts - set of file extensions to read, if empty, read everything under the dir /// \param[in] index - the specific file index - /// \param[in] rotate - rotate image exif orientation AlbumOp(const std::string &file_dir, bool do_decode, const std::string &schema_file, const std::vector &column_names, const std::set &exts, uint32_t index); @@ -79,11 +79,11 @@ class AlbumOp { /// \return bool - if file is bad then return false bool CheckImageType(const std::string &file_name, bool *valid); - // Op name getter - // @return Name of the current Op + /// \brief Name of the current Op + /// @return op name std::string Name() const { return "AlbumOp"; } - // Op name DisableRotate + /// \brief disable rotate // @return void DisableRotate() { this->rotate_ = false; } @@ -162,7 +162,10 @@ class AlbumOp { /// \param[in] file file path int GetOrientation(const std::string &file); + /// \brief is read column name + /// \param[in] column_name bool IsReadColumn(const std::string &column_name); + std::string folder_path_; // directory of image folder bool decode_; std::vector columns_to_load_;