From: @xulei2020 Reviewed-by: @HilbertDavid,@liucunwei Signed-off-by: @HilbertDavidtags/v1.1.0
| @@ -110,7 +110,12 @@ Status Pad(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output | |||||
| const int32_t &pad_bottom, const int32_t &pad_left, const int32_t &pad_right, const BorderType &border_types, | 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); | 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<Tensor> &input, std::shared_ptr<Tensor> *output, const uint64_t orientation); | Status Rotate(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output, const uint64_t orientation); | ||||
| } // namespace dataset | } // namespace dataset | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_ | #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_ | ||||
| @@ -22,6 +22,7 @@ | |||||
| #include <unordered_map> | #include <unordered_map> | ||||
| #include <utility> | #include <utility> | ||||
| #include <vector> | #include <vector> | ||||
| #include <set> | |||||
| #include "album_op_android.h" //NOLINT | #include "album_op_android.h" //NOLINT | ||||
| #include "minddata/dataset/include/execute.h" | #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) << "MEAN: { " << MDConf.MEAN[0] << ", " << MDConf.MEAN[1] << ", " << MDConf.MEAN[2] << " }"; | ||||
| MS_LOG(WARNING) << "STD: { " << MDConf.STD[0] << ", " << MDConf.STD[1] << ", " << MDConf.STD[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)) { | if ((MDConf.ResizeSizeWH[0] != 0) && (MDConf.ResizeSizeWH[1] != 0)) { | ||||
| std::shared_ptr<TensorOperation> resize_op = | std::shared_ptr<TensorOperation> resize_op = | ||||
| mindspore::dataset::vision::Resize({MDConf.ResizeSizeWH[0], MDConf.ResizeSizeWH[1]}); | mindspore::dataset::vision::Resize({MDConf.ResizeSizeWH[0], MDConf.ResizeSizeWH[1]}); | ||||
| MS_LOG(WARNING) << "Push back resize"; | MS_LOG(WARNING) << "Push back resize"; | ||||
| mapOperations.push_back(resize_op); | mapOperations.push_back(resize_op); | ||||
| } | |||||
| if (1 == MDConf.fixOrientation) { | |||||
| std::shared_ptr<TensorOperation> rotate_op = mindspore::dataset::vision::Rotate(); | std::shared_ptr<TensorOperation> rotate_op = mindspore::dataset::vision::Rotate(); | ||||
| MS_LOG(WARNING) << "Push back rotate"; | MS_LOG(WARNING) << "Push back rotate"; | ||||
| mapOperations.push_back(rotate_op); | mapOperations.push_back(rotate_op); | ||||
| @@ -166,7 +167,7 @@ extern "C" MDToDApi *MDToDApi_createPipeLine(MDToDConf_t MDConf) { | |||||
| } | } | ||||
| template <typename T> | template <typename T> | ||||
| void MDBuffToVector(const MDToDBuff_t MDBuff, std::vector<T> *vec) { | |||||
| void MDBuffToVector(const MDToDBuff_t &MDBuff, std::vector<T> *vec) { | |||||
| vec->clear(); | vec->clear(); | ||||
| if (MDBuff.DataSize > 0) { | if (MDBuff.DataSize > 0) { | ||||
| int nofElements = MDBuff.DataSize / sizeof(T); | 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 | // create Execute functions, this replaces Map in Pipeline | ||||
| bool ret = pMDToDApi->_iter->GetNextRow(&row); | bool ret = pMDToDApi->_iter->GetNextRow(&row); | ||||
| uint32_t orientation = 0; | |||||
| if (row.size() != 0 && ret) { | if (row.size() != 0 && ret) { | ||||
| GetValue<uint32_t>(row, "orientation", &orientation); | |||||
| MS_LOG(WARNING) << "get orientation from row = " << orientation; | |||||
| if ((pMDToDApi->_augs).size() > 0) { | if ((pMDToDApi->_augs).size() > 0) { | ||||
| // String and Tensors | // 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 | // for each operation, run eager mode, single threaded operation, will have to memcpy | ||||
| // regardless | // regardless | ||||
| for (int i = 0; i < (pMDToDApi->_augs).size(); i++) { | 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) { | if (orientation > 1) { | ||||
| RotateOperation *p = static_cast<RotateOperation *>(pMDToDApi->_augs[i].get()); | RotateOperation *p = static_cast<RotateOperation *>(pMDToDApi->_augs[i].get()); | ||||
| p->setAngle(orientation); | p->setAngle(orientation); | ||||
| orientation = 0; // clear oriation filed if allready preformed | |||||
| } else { | } else { | ||||
| continue; | continue; | ||||
| } | } | ||||
| @@ -302,6 +305,7 @@ extern "C" int MDToDApi_GetNext(MDToDApi *pMDToDApi, MDToDResult_t *results) { | |||||
| // IS FOR TRAIN | // IS FOR TRAIN | ||||
| GetValue<int32_t>(row, "_isForTrain", &results->isForTrain); | GetValue<int32_t>(row, "_isForTrain", &results->isForTrain); | ||||
| GetValue<int32_t>(row, "_noOfFaces", &results->noOfFaces); | GetValue<int32_t>(row, "_noOfFaces", &results->noOfFaces); | ||||
| results->orientation = (int32_t)orientation; | |||||
| // String and Tensors | // String and Tensors | ||||
| GetTensorToBuff(row, "image_filename", pMDToDApi->_hasBatch, &results->fileNameBuff); | GetTensorToBuff(row, "image_filename", pMDToDApi->_hasBatch, &results->fileNameBuff); | ||||
| GetTensorToBuff(row, "image", pMDToDApi->_hasBatch, &results->imageBuff); | GetTensorToBuff(row, "image", pMDToDApi->_hasBatch, &results->imageBuff); | ||||
| @@ -36,6 +36,7 @@ typedef struct MDToDConf { | |||||
| float MEAN[3]; | float MEAN[3]; | ||||
| float STD[3]; | float STD[3]; | ||||
| int ResizeSizeWH[2]; | int ResizeSizeWH[2]; | ||||
| int fixOrientation; | |||||
| int CropSizeWH[2]; | int CropSizeWH[2]; | ||||
| int64_t fileid; // -1 All files, otherwise get a single specifc file | int64_t fileid; // -1 All files, otherwise get a single specifc file | ||||
| } MDToDConf_t; | } MDToDConf_t; | ||||
| @@ -44,6 +45,7 @@ typedef struct MDToDResult { | |||||
| int64_t fileid; | int64_t fileid; | ||||
| int32_t isForTrain; | int32_t isForTrain; | ||||
| int32_t noOfFaces; | int32_t noOfFaces; | ||||
| int32_t orientation; | |||||
| MDToDBuff_t fileNameBuff; | MDToDBuff_t fileNameBuff; | ||||
| MDToDBuff_t labelBuff; | MDToDBuff_t labelBuff; | ||||
| MDToDBuff_t imageBuff; | MDToDBuff_t imageBuff; | ||||
| @@ -48,8 +48,8 @@ class AlbumOp { | |||||
| /// \param[in] file_dir - directory of Album | /// \param[in] file_dir - directory of Album | ||||
| /// \param[in] do_decode - decode image files | /// \param[in] do_decode - decode image files | ||||
| /// \param[in] schema_file - schema file | /// \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] 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, | AlbumOp(const std::string &file_dir, bool do_decode, const std::string &schema_file, | ||||
| const std::vector<std::string> &column_names, const std::set<std::string> &exts); | const std::vector<std::string> &column_names, const std::set<std::string> &exts); | ||||
| @@ -57,9 +57,9 @@ class AlbumOp { | |||||
| /// \param[in] file_dir - directory of Album | /// \param[in] file_dir - directory of Album | ||||
| /// \param[in] do_decode - decode image files | /// \param[in] do_decode - decode image files | ||||
| /// \param[in] schema_file - schema file | /// \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] exts - set of file extensions to read, if empty, read everything under the dir | ||||
| /// \param[in] index - the specific file index | /// \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, | AlbumOp(const std::string &file_dir, bool do_decode, const std::string &schema_file, | ||||
| const std::vector<std::string> &column_names, const std::set<std::string> &exts, uint32_t index); | const std::vector<std::string> &column_names, const std::set<std::string> &exts, uint32_t index); | ||||
| @@ -79,11 +79,11 @@ class AlbumOp { | |||||
| /// \return bool - if file is bad then return false | /// \return bool - if file is bad then return false | ||||
| bool CheckImageType(const std::string &file_name, bool *valid); | 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"; } | std::string Name() const { return "AlbumOp"; } | ||||
| // Op name DisableRotate | |||||
| /// \brief disable rotate | |||||
| // @return | // @return | ||||
| void DisableRotate() { this->rotate_ = false; } | void DisableRotate() { this->rotate_ = false; } | ||||
| @@ -162,7 +162,10 @@ class AlbumOp { | |||||
| /// \param[in] file file path | /// \param[in] file file path | ||||
| int GetOrientation(const std::string &file); | int GetOrientation(const std::string &file); | ||||
| /// \brief is read column name | |||||
| /// \param[in] column_name | |||||
| bool IsReadColumn(const std::string &column_name); | bool IsReadColumn(const std::string &column_name); | ||||
| std::string folder_path_; // directory of image folder | std::string folder_path_; // directory of image folder | ||||
| bool decode_; | bool decode_; | ||||
| std::vector<std::string> columns_to_load_; | std::vector<std::string> columns_to_load_; | ||||