forked from mindspore-Ecosystem/mindspore
fix code review
This commit is contained in:
parent
9d4f4da8d0
commit
7554a7eb0c
|
@ -34,7 +34,7 @@ Status AmplitudeToDBOp::Compute(const std::shared_ptr<Tensor> &input, std::share
|
|||
|
||||
float top_db = top_db_;
|
||||
float multiplier = stype_ == ScaleType::kPower ? 10.0 : 20.0;
|
||||
float amin = 1e-10;
|
||||
const float amin = 1e-10;
|
||||
float db_multiplier = std::log10(std::max(amin_, ref_value_));
|
||||
|
||||
// typecast
|
||||
|
|
|
@ -481,6 +481,7 @@ Status Decoding(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *o
|
|||
|
||||
while (itr != end) {
|
||||
auto x_mu = *itr;
|
||||
CHECK_FAIL_RETURN_SYNTAX_ERROR(mu != 0, "mu can not be zero.");
|
||||
x_mu = ((x_mu) / mu) * 2 - 1.0;
|
||||
x_mu = sgn(x_mu) * expm1(fabs(x_mu) * log1p(mu)) / mu;
|
||||
*itr_out = x_mu;
|
||||
|
|
|
@ -50,6 +50,7 @@ VOCOp::VOCOp(const TaskType &task_type, const std::string &task_mode, const std:
|
|||
std::unique_ptr<DataSchema> data_schema, std::shared_ptr<SamplerRT> sampler, bool extra_metadata)
|
||||
: MappableLeafOp(num_workers, queue_size, std::move(sampler)),
|
||||
decode_(decode),
|
||||
row_cnt_(0),
|
||||
task_type_(task_type),
|
||||
usage_(task_mode),
|
||||
folder_path_(folder_path),
|
||||
|
|
|
@ -126,7 +126,6 @@ Status DIV2KNode::GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_
|
|||
std::shared_ptr<SamplerRT> sampler_rt = nullptr;
|
||||
RETURN_IF_NOT_OK(sampler_->SamplerBuild(&sampler_rt));
|
||||
sample_size = sampler_rt->CalculateNumSamples(num_rows);
|
||||
|
||||
if (sample_size == -1) {
|
||||
RETURN_IF_NOT_OK(size_getter->DryRun(shared_from_this(), &sample_size));
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ Status CenterCropOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_p
|
|||
", crop width: " + std::to_string(crop_wid_) + "\t"
|
||||
: "";
|
||||
|
||||
if (err_msg.length() != 0) RETURN_STATUS_UNEXPECTED(err_head + err_msg);
|
||||
CHECK_FAIL_RETURN_SYNTAX_ERROR(err_msg.length() == 0, err_head + err_msg);
|
||||
|
||||
int32_t top = crop_het_ - input->shape()[0]; // number of pixels to pad (top and bottom)
|
||||
int32_t left = crop_wid_ - input->shape()[1];
|
||||
|
|
|
@ -37,6 +37,7 @@ LiteMat::LiteMat() {
|
|||
data_type_ = LDataType::UINT8;
|
||||
ref_count_ = nullptr;
|
||||
setSteps(0, 0, 0);
|
||||
release_flag = false;
|
||||
}
|
||||
|
||||
LiteMat::LiteMat(int width, LDataType data_type) {
|
||||
|
@ -51,6 +52,7 @@ LiteMat::LiteMat(int width, LDataType data_type) {
|
|||
ref_count_ = nullptr;
|
||||
size_ = 0;
|
||||
setSteps(0, 0, 0);
|
||||
release_flag = false;
|
||||
Init(width, data_type);
|
||||
}
|
||||
|
||||
|
@ -66,6 +68,7 @@ LiteMat::LiteMat(int width, int height, LDataType data_type) {
|
|||
ref_count_ = nullptr;
|
||||
size_ = 0;
|
||||
setSteps(0, 0, 0);
|
||||
release_flag = false;
|
||||
Init(width, height, data_type);
|
||||
}
|
||||
|
||||
|
@ -81,6 +84,7 @@ LiteMat::LiteMat(int width, int height, void *p_data, LDataType data_type) {
|
|||
ref_count_ = nullptr;
|
||||
size_ = 0;
|
||||
setSteps(0, 0, 0);
|
||||
release_flag = false;
|
||||
Init(width, height, p_data, data_type);
|
||||
}
|
||||
|
||||
|
@ -96,6 +100,7 @@ LiteMat::LiteMat(int width, int height, int channel, LDataType data_type) {
|
|||
ref_count_ = nullptr;
|
||||
size_ = 0;
|
||||
setSteps(0, 0, 0);
|
||||
release_flag = false;
|
||||
Init(width, height, channel, data_type);
|
||||
}
|
||||
|
||||
|
@ -111,6 +116,7 @@ LiteMat::LiteMat(int width, int height, int channel, void *p_data, LDataType dat
|
|||
ref_count_ = nullptr;
|
||||
size_ = 0;
|
||||
setSteps(0, 0, 0);
|
||||
release_flag = false;
|
||||
Init(width, height, channel, p_data, data_type);
|
||||
}
|
||||
|
||||
|
@ -133,6 +139,7 @@ LiteMat::LiteMat(const LiteMat &m) {
|
|||
data_type_ = m.data_type_;
|
||||
ref_count_ = m.ref_count_;
|
||||
size_ = m.size_;
|
||||
release_flag = m.release_flag;
|
||||
setSteps(m.steps_[0], m.steps_[1], m.steps_[2]);
|
||||
if (ref_count_) {
|
||||
addRef(ref_count_, 1);
|
||||
|
|
|
@ -34,7 +34,7 @@ static const std::vector<uint8_t> _clip8_table = []() {
|
|||
|
||||
static const uint8_t *clip8_table = &_clip8_table[640];
|
||||
|
||||
static inline uint8_t clip8(int input) { return clip8_table[input >> PrecisionBits]; }
|
||||
static inline uint8_t clip8(unsigned int input) { return clip8_table[input >> PrecisionBits]; }
|
||||
|
||||
static inline double cubic_interp(double x) {
|
||||
double a = -0.5;
|
||||
|
@ -60,6 +60,10 @@ int calc_coeff(int input_size, int out_size, int input0, int input1, struct inte
|
|||
double threshold, scale, interp_scale;
|
||||
int kernel_size;
|
||||
|
||||
if (out_size == 0) {
|
||||
MS_LOG(ERROR) << "out_size can not be zero.";
|
||||
return 0;
|
||||
}
|
||||
scale = static_cast<double>((input1 - input0)) / out_size;
|
||||
if (scale < 1.0) {
|
||||
interp_scale = 1.0;
|
||||
|
@ -133,7 +137,7 @@ void normalize_coeff(int out_size, int kernel_size, const std::vector<double> &p
|
|||
Status ImagingHorizontalInterp(LiteMat &output, LiteMat input, int offset, int kernel_size,
|
||||
const std::vector<int> ®ions, const std::vector<double> &prekk) {
|
||||
int ss0, ss1, ss2;
|
||||
int32_t *k;
|
||||
int32_t *k = nullptr;
|
||||
|
||||
// normalize previous calculated coefficients
|
||||
std::vector<int> kk(prekk.begin(), prekk.end());
|
||||
|
@ -202,7 +206,7 @@ Status ImagingVerticalInterp(LiteMat &output, LiteMat input, int offset, int ker
|
|||
}
|
||||
|
||||
bool ImageInterpolation(LiteMat input, LiteMat &output, int x_size, int y_size, struct interpolation *interp,
|
||||
int rect[4]) {
|
||||
const int rect[4]) {
|
||||
int horizontal_interp, vertical_interp, horiz_kernel, vert_kernel, rect_y0, rect_y1;
|
||||
std::vector<int> horiz_region, vert_region;
|
||||
std::vector<double> horiz_coeff, vert_coeff;
|
||||
|
@ -269,7 +273,11 @@ bool ResizeCubic(const LiteMat &input, LiteMat &dst, int dst_w, int dst_h) {
|
|||
struct interpolation interp = {cubic_interp, 2.0};
|
||||
bool res = ImageInterpolation(input, output, x_size, y_size, &interp, rect);
|
||||
|
||||
memcpy_s(dst.data_ptr_, output.size_, output.data_ptr_, output.size_);
|
||||
auto ret_code = memcpy_s(dst.data_ptr_, output.size_, output.data_ptr_, output.size_);
|
||||
if (ret_code != 0) {
|
||||
MS_LOG(ERROR) << "memcpy_s failed when copying tensor.";
|
||||
return false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace dataset
|
||||
|
|
|
@ -47,7 +47,7 @@ Status ImagingVerticalInterp(LiteMat &output, LiteMat input, int offset, int ker
|
|||
|
||||
/// \brief Mainly logic of Cubic interpolation
|
||||
bool ImageInterpolation(LiteMat input, LiteMat &output, int x_size, int y_size, struct interpolation *interp,
|
||||
int rect[4]);
|
||||
const int rect[4]);
|
||||
|
||||
/// \brief Apply cubic interpolation on input image and obtain the output image
|
||||
/// \param[in] input Input image
|
||||
|
|
|
@ -31,11 +31,20 @@ const uint8_t RotateOp::kDefFillR = 0;
|
|||
const uint8_t RotateOp::kDefFillG = 0;
|
||||
const uint8_t RotateOp::kDefFillB = 0;
|
||||
|
||||
RotateOp::RotateOp(int angle_id) : angle_id_(angle_id) {}
|
||||
RotateOp::RotateOp(int angle_id)
|
||||
: angle_id_(angle_id),
|
||||
degrees_(0),
|
||||
center_({}),
|
||||
interpolation_(InterpolationMode::kLinear),
|
||||
expand_(false),
|
||||
fill_r_(0),
|
||||
fill_g_(0),
|
||||
fill_b_(0) {}
|
||||
|
||||
RotateOp::RotateOp(float degrees, InterpolationMode resample, bool expand, std::vector<float> center, uint8_t fill_r,
|
||||
uint8_t fill_g, uint8_t fill_b)
|
||||
: degrees_(degrees),
|
||||
: angle_id_(0),
|
||||
degrees_(degrees),
|
||||
center_(center),
|
||||
interpolation_(resample),
|
||||
expand_(expand),
|
||||
|
|
|
@ -22,11 +22,22 @@ namespace mindspore {
|
|||
namespace dataset {
|
||||
namespace vision {
|
||||
// RotateOperation
|
||||
RotateOperation::RotateOperation(FixRotationAngle angle) : angle_id_(static_cast<uint64_t>(angle)) {}
|
||||
RotateOperation::RotateOperation(FixRotationAngle angle)
|
||||
: angle_id_(static_cast<uint64_t>(angle)),
|
||||
degrees_(0),
|
||||
interpolation_mode_(InterpolationMode::kLinear),
|
||||
expand_(false),
|
||||
center_({}),
|
||||
fill_value_({}) {}
|
||||
|
||||
RotateOperation::RotateOperation(float degrees, InterpolationMode resample, bool expand, std::vector<float> center,
|
||||
std::vector<uint8_t> fill_value)
|
||||
: degrees_(degrees), interpolation_mode_(resample), expand_(expand), center_(center), fill_value_(fill_value) {}
|
||||
: angle_id_(0),
|
||||
degrees_(degrees),
|
||||
interpolation_mode_(resample),
|
||||
expand_(expand),
|
||||
center_(center),
|
||||
fill_value_(fill_value) {}
|
||||
|
||||
RotateOperation::~RotateOperation() = default;
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ Status PluginOp::TensorRowToPlugin(const TensorRow &in_row, std::vector<plugin::
|
|||
int ret_code = memcpy_s(tensor.buffer_.data(), tensor.buffer_.size(), in_row[ind]->GetBuffer(), buffer_size);
|
||||
CHECK_FAIL_RETURN_UNEXPECTED(ret_code == 0, "Failed to copy data into plugin tensor.");
|
||||
} else {
|
||||
auto ret_code = std::memcpy(tensor.buffer_.data(), in_row[ind]->GetBuffer(), buffer_size);
|
||||
CHECK_FAIL_RETURN_UNEXPECTED(ret_code == tensor.buffer_.data(), "Failed to copy data into plugin tensor.");
|
||||
int ret_code = memcpy_s(tensor.buffer_.data(), buffer_size, in_row[ind]->GetBuffer(), buffer_size);
|
||||
CHECK_FAIL_RETURN_UNEXPECTED(ret_code == 0, "Failed to copy data into plugin tensor.");
|
||||
}
|
||||
} else { // string tensor, for now, only tensor with 1 string is supported!
|
||||
CHECK_FAIL_RETURN_UNEXPECTED(in_row[ind]->shape().NumOfElements() == 1,
|
||||
|
|
|
@ -316,7 +316,7 @@ class BPlusTree {
|
|||
|
||||
void Init() {
|
||||
typename LeafNode::alloc_type alloc(alloc_);
|
||||
LeafNode *p;
|
||||
LeafNode *p = nullptr;
|
||||
try {
|
||||
p = alloc.allocate(1);
|
||||
} catch (std::bad_alloc &e) {
|
||||
|
|
|
@ -3693,7 +3693,7 @@ class SamplerFn:
|
|||
if multi_process is True:
|
||||
try:
|
||||
self.eof = multiprocessing.Event()
|
||||
except:
|
||||
except Exception:
|
||||
raise RuntimeError("Init multiprocessing.Event() failed, This might be caused by insufficient shm,"
|
||||
+ " and the recommended shm size is at least 5 GB.")
|
||||
else:
|
||||
|
|
|
@ -581,7 +581,7 @@ def to_type(img, output_type):
|
|||
|
||||
try:
|
||||
return img.astype(output_type)
|
||||
except:
|
||||
except Exception:
|
||||
raise RuntimeError("output_type: " + str(output_type) + " is not a valid datatype.")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue