forked from mindspore-Ecosystem/mindspore
Update Error message for dvpp operator.
This commit is contained in:
parent
795ac08f1d
commit
d032b69c2d
|
@ -692,13 +692,20 @@ Status DvppDecodeResizeCropOperation::ValidateParams() {
|
|||
}
|
||||
if (*min_element(crop_.begin(), crop_.end()) < 32 || *max_element(crop_.begin(), crop_.end()) > 2048) {
|
||||
std::string err_msg = "Dvpp module supports crop image with resolution in range [32, 2048], got Crop Parameters: ";
|
||||
MS_LOG(ERROR) << err_msg << crop_;
|
||||
if (crop_.size() == 2)
|
||||
MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[1] << "]";
|
||||
else
|
||||
MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[0] << "]";
|
||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||
}
|
||||
if (*min_element(resize_.begin(), resize_.end()) < 32 || *max_element(resize_.begin(), resize_.end()) > 2048) {
|
||||
std::string err_msg =
|
||||
"Dvpp module supports resize image with resolution in range [32, 2048], got Crop Parameters: ";
|
||||
MS_LOG(ERROR) << err_msg << resize_;
|
||||
if (resize_.size() == 2) {
|
||||
MS_LOG(ERROR) << err_msg << "[" << resize_[0] << ", " << resize_[1] << "]";
|
||||
} else {
|
||||
MS_LOG(ERROR) << err_msg << "[" << resize_[0] << ", " << resize_[0] << "]";
|
||||
}
|
||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||
}
|
||||
if (crop_.size() < resize_.size()) {
|
||||
|
|
|
@ -241,84 +241,6 @@ APP_ERROR AclProcess::RenameFile(std::string &filename) {
|
|||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* @description: Write result image to file
|
||||
* @param: resultSize specifies the size of the result image
|
||||
* @param: outBuf specifies the memory on the host to save the result image
|
||||
* @return: aclError which is error code of ACL API
|
||||
*/
|
||||
APP_ERROR AclProcess::WriteResult(uint32_t resultSize, std::shared_ptr<void> outBuf, std::string filename) {
|
||||
std::string resultPathName = "result";
|
||||
// Create result directory when it does not exist
|
||||
if (access(resultPathName.c_str(), 0) != 0) {
|
||||
int ret = mkdir(resultPathName.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); // for linux
|
||||
if (ret != 0) {
|
||||
MS_LOG(ERROR) << "Failed to create result directory: " << resultPathName << ", ret = " << ret;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
APP_ERROR ret = RenameFile(filename);
|
||||
if (ret != 0) {
|
||||
MS_LOG(ERROR) << "Failed to rename file: " << resultPathName << ", ret = " << ret;
|
||||
return ret;
|
||||
}
|
||||
resultPathName = resultPathName + "/" + filename + ".bin";
|
||||
SetFileDefaultUmask();
|
||||
FILE *fp = fopen(resultPathName.c_str(), "wb");
|
||||
if (fp == nullptr) {
|
||||
MS_LOG(ERROR) << "Failed to open file";
|
||||
return APP_ERR_COMM_OPEN_FAIL;
|
||||
}
|
||||
uint32_t result = fwrite(outBuf.get(), 1, resultSize, fp);
|
||||
if (result != resultSize) {
|
||||
MS_LOG(ERROR) << "Failed to write file";
|
||||
return APP_ERR_COMM_WRITE_FAIL;
|
||||
}
|
||||
MS_LOG(INFO) << "Write result to file successfully";
|
||||
// After write info onto desk, release the memory on device
|
||||
dvppCommon_->ReleaseDvppBuffer();
|
||||
uint32_t ff = fflush(fp);
|
||||
if (ff != 0) {
|
||||
MS_LOG(ERROR) << "Failed to fflush file";
|
||||
return APP_ERR_COMM_DESTORY_FAIL;
|
||||
}
|
||||
uint32_t fc = fclose(fp);
|
||||
if (fc != 0) {
|
||||
MS_LOG(ERROR) << "Failed to fclose file";
|
||||
return APP_ERR_COMM_DESTORY_FAIL;
|
||||
}
|
||||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
void AclProcess::YUV420TOYUV444(unsigned char *inputBuffer, unsigned char *outputBuffer, int w, int h) {
|
||||
unsigned char *srcY = nullptr, *srcU = nullptr, *srcV = nullptr;
|
||||
unsigned char *desY = nullptr, *desU = nullptr, *desV = nullptr;
|
||||
srcY = inputBuffer; // Y
|
||||
if (srcY == nullptr) std::cout << "Failure pointer transfer!";
|
||||
srcU = srcY + w * h; // U
|
||||
srcV = srcU + w * h / 4;
|
||||
; // V
|
||||
|
||||
desY = outputBuffer;
|
||||
desU = desY + w * h;
|
||||
desV = desU + w * h;
|
||||
memcpy(desY, srcY, w * h * sizeof(unsigned char));
|
||||
for (int i = 0; i < h; i += 2) { //行
|
||||
for (int j = 0; j < w; j += 2) { //列
|
||||
// U
|
||||
desU[i * w + j] = srcU[i / 2 * w / 2 + j / 2];
|
||||
desU[i * w + j + 1] = srcU[i / 2 * w / 2 + j / 2];
|
||||
desU[(i + 1) * w + j] = srcU[i / 2 * w / 2 + j / 2];
|
||||
desU[(i + 1) * w + j + 1] = srcU[i / 2 * w / 2 + j / 2];
|
||||
// V
|
||||
desV[i * w + j] = srcV[i / 2 * w / 2 + j / 2];
|
||||
desV[i * w + j + 1] = srcV[i / 2 * w / 2 + j / 2];
|
||||
desV[(i + 1) * w + j] = srcV[i / 2 * w / 2 + j / 2];
|
||||
desV[(i + 1) * w + j + 1] = srcV[i / 2 * w / 2 + j / 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AclProcess::CropConfigFilter(CropRoiConfig &cfg, DvppCropInputInfo &cropinfo) {
|
||||
cfg.up = (resizeHeight_ - cropHeight_) / 2;
|
||||
if (cfg.up % 2 != 0) {
|
||||
|
|
|
@ -55,10 +55,6 @@ class AclProcess {
|
|||
void set_mode(bool flag);
|
||||
// Get the mode of Acl process
|
||||
bool get_mode();
|
||||
// Save the result
|
||||
APP_ERROR WriteResult(uint32_t fileSize, std::shared_ptr<void> outBuf, std::string filename);
|
||||
// Color space reform
|
||||
void YUV420TOYUV444(unsigned char *inputBuffer, unsigned char *outputBuffer, int w, int h);
|
||||
// Crop definition
|
||||
void CropConfigFilter(CropRoiConfig &cfg, DvppCropInputInfo &cropinfo);
|
||||
// D-chip memory release
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include "common/common_test.h"
|
||||
#include "include/api/types.h"
|
||||
#include "minddata/dataset/include/minddata_eager.h"
|
||||
|
@ -73,11 +72,17 @@ TEST_F(TestDE, TestDvpp) {
|
|||
img = Transform(img);
|
||||
ASSERT_NE(img, nullptr);
|
||||
ASSERT_EQ(img->Shape().size(), 3);
|
||||
int32_t real_h = 0;
|
||||
int32_t real_w = 0;
|
||||
int remainder = crop_size[crop_size.size() - 1] % 16;
|
||||
if (crop_size.size() == 1) {
|
||||
ASSERT_EQ(img->Shape()[0], pow(crop_size[0], 2) * 1.5);
|
||||
real_h = (crop_size[0] % 2 == 0) ? crop_size[0] : crop_size[0] + 1;
|
||||
real_w = (remainder == 0) ? crop_size[0] : crop_size[0] + 16 - remainder;
|
||||
} else {
|
||||
ASSERT_EQ(img->Shape()[0], crop_size[0] * crop_size[1] * 1.5);
|
||||
real_h = (crop_size[0] % 2 == 0) ? crop_size[0] : crop_size[0] + 1;
|
||||
real_w = (remainder == 0) ? crop_size[1] : crop_size[1] + 16 - remainder;
|
||||
}
|
||||
ASSERT_EQ(img->Shape()[0], real_h * real_w * 1.5); // For image in YUV format, each pixel takes 1.5 byte
|
||||
ASSERT_EQ(img->Shape()[1], 1);
|
||||
ASSERT_EQ(img->Shape()[2], 1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue