!9657 [MD] fix bug Updated add rotate and orientation to lite

From: @xulei2020
Reviewed-by: @HilbertDavid,@liucunwei
Signed-off-by: @HilbertDavid
This commit is contained in:
mindspore-ci-bot 2020-12-08 22:54:44 +08:00 committed by Gitee
commit 48f83e9039
4 changed files with 25 additions and 11 deletions

View File

@ -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,
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);
} // namespace dataset
} // namespace mindspore
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_

View File

@ -22,6 +22,7 @@
#include <unordered_map>
#include <utility>
#include <vector>
#include <set>
#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<TensorOperation> 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<TensorOperation> 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 <typename T>
void MDBuffToVector(const MDToDBuff_t MDBuff, std::vector<T> *vec) {
void MDBuffToVector(const MDToDBuff_t &MDBuff, std::vector<T> *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<uint32_t>(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<RotateOperation *>(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<int32_t>(row, "_isForTrain", &results->isForTrain);
GetValue<int32_t>(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);

View File

@ -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;

View File

@ -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<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] 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<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
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<std::string> columns_to_load_;