forked from mindspore-Ecosystem/mindspore
optimizer code v3
This commit is contained in:
parent
7f71a99993
commit
170ebcb89d
|
@ -28,7 +28,7 @@ int TransferStridedSliceAttr(Model::Node *node, std::vector<schema::Tensor *> *d
|
|||
dst_tensors->clear();
|
||||
auto prim = reinterpret_cast<const schema::v0::Primitive *>(node->primitive_);
|
||||
MS_ASSERT(prim != nullptr);
|
||||
int inputs_size = node->input_indices_.size();
|
||||
int inputs_size = static_cast<int>(node->input_indices_.size());
|
||||
|
||||
auto param = prim->value_as_StridedSlice();
|
||||
if (param == nullptr) {
|
||||
|
|
|
@ -53,8 +53,8 @@ OpParameter *PopulateAdderParameter(const void *prim) {
|
|||
param->stride_w_ = static_cast<int>(*(stride->begin() + 1));
|
||||
param->pad_u_ = static_cast<int>(*(pad_list->begin()));
|
||||
param->pad_d_ = static_cast<int>(*(pad_list->begin() + 1));
|
||||
param->pad_l_ = static_cast<int>(*(pad_list->begin() + 2));
|
||||
param->pad_r_ = static_cast<int>(*(pad_list->begin() + 3));
|
||||
param->pad_l_ = static_cast<int>(*(pad_list->begin() + kOffsetTwo));
|
||||
param->pad_r_ = static_cast<int>(*(pad_list->begin() + kOffsetThree));
|
||||
param->dilation_h_ = static_cast<int>(*(dilation->begin()));
|
||||
param->dilation_w_ = static_cast<int>(*(dilation->begin() + 1));
|
||||
param->input_channel_ = static_cast<int>(value->in_channel());
|
||||
|
|
|
@ -20,7 +20,6 @@ using mindspore::schema::PrimitiveType_Conv2DFusion;
|
|||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
constexpr auto kMinShapeSize = 2;
|
||||
OpParameter *PopulateConvParameter(const void *prim) {
|
||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||
MS_ASSERT(primitive != nullptr);
|
||||
|
@ -47,7 +46,8 @@ OpParameter *PopulateConvParameter(const void *prim) {
|
|||
free(param);
|
||||
return nullptr;
|
||||
}
|
||||
if (kernel_size->size() < kMinShapeSize || stride->size() < kMinShapeSize || dilation->size() < kMinShapeSize) {
|
||||
if (kernel_size->size() < kMinShapeSizeTwo || stride->size() < kMinShapeSizeTwo ||
|
||||
dilation->size() < kMinShapeSizeTwo) {
|
||||
MS_LOG(ERROR) << "Invalid shape size!kernel_size size: " << kernel_size->size()
|
||||
<< ", stride size: " << stride->size() << ", dilation size: " << dilation->size();
|
||||
free(param);
|
||||
|
@ -68,7 +68,7 @@ OpParameter *PopulateConvParameter(const void *prim) {
|
|||
default:
|
||||
param->pad_mode_ = Pad_pad;
|
||||
}
|
||||
if (pad_list == nullptr || pad_list->size() < 4) {
|
||||
if (pad_list == nullptr || pad_list->size() < kMinShapeSizeFour) {
|
||||
param->pad_u_ = 0;
|
||||
param->pad_d_ = 0;
|
||||
param->pad_l_ = 0;
|
||||
|
@ -76,8 +76,8 @@ OpParameter *PopulateConvParameter(const void *prim) {
|
|||
} else {
|
||||
param->pad_u_ = static_cast<int>(*(pad_list->begin()));
|
||||
param->pad_d_ = static_cast<int>(*(pad_list->begin() + 1));
|
||||
param->pad_l_ = static_cast<int>(*(pad_list->begin() + 2));
|
||||
param->pad_r_ = static_cast<int>(*(pad_list->begin() + 3));
|
||||
param->pad_l_ = static_cast<int>(*(pad_list->begin() + kOffsetTwo));
|
||||
param->pad_r_ = static_cast<int>(*(pad_list->begin() + kOffsetThree));
|
||||
}
|
||||
param->dilation_h_ = static_cast<int>(*(dilation->begin()));
|
||||
param->dilation_w_ = static_cast<int>(*(dilation->begin() + 1));
|
||||
|
|
|
@ -20,7 +20,6 @@ using mindspore::schema::PrimitiveType_Conv2dTransposeFusion;
|
|||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
constexpr auto kMinShapeSize = 2;
|
||||
OpParameter *PopulateDeconvParameter(const void *prim) {
|
||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||
MS_ASSERT(primitive != nullptr);
|
||||
|
@ -48,7 +47,8 @@ OpParameter *PopulateDeconvParameter(const void *prim) {
|
|||
free(param);
|
||||
return nullptr;
|
||||
}
|
||||
if (kernel_size->size() < kMinShapeSize || stride->size() < kMinShapeSize || dilation->size() < kMinShapeSize) {
|
||||
if (kernel_size->size() < kMinShapeSizeTwo || stride->size() < kMinShapeSizeTwo ||
|
||||
dilation->size() < kMinShapeSizeTwo) {
|
||||
MS_LOG(ERROR) << "Invalid shape size!kernel_size size: " << kernel_size->size()
|
||||
<< ", stride size: " << stride->size() << ", dilation size: " << dilation->size()
|
||||
<< ", output_paddings size:" << output_paddings->size();
|
||||
|
@ -72,7 +72,7 @@ OpParameter *PopulateDeconvParameter(const void *prim) {
|
|||
default:
|
||||
param->pad_mode_ = Pad_pad;
|
||||
}
|
||||
if (pad_list == nullptr || pad_list->size() < 4) {
|
||||
if (pad_list == nullptr || pad_list->size() < kMinShapeSizeFour) {
|
||||
param->pad_u_ = 0;
|
||||
param->pad_d_ = 0;
|
||||
param->pad_l_ = 0;
|
||||
|
@ -80,8 +80,8 @@ OpParameter *PopulateDeconvParameter(const void *prim) {
|
|||
} else {
|
||||
param->pad_u_ = static_cast<int>(*(pad_list->begin()));
|
||||
param->pad_d_ = static_cast<int>(*(pad_list->begin() + 1));
|
||||
param->pad_l_ = static_cast<int>(*(pad_list->begin() + 2));
|
||||
param->pad_r_ = static_cast<int>(*(pad_list->begin() + 3));
|
||||
param->pad_l_ = static_cast<int>(*(pad_list->begin() + kOffsetTwo));
|
||||
param->pad_r_ = static_cast<int>(*(pad_list->begin() + kOffsetThree));
|
||||
}
|
||||
param->dilation_h_ = static_cast<int>(*(dilation->begin()));
|
||||
param->dilation_w_ = static_cast<int>(*(dilation->begin() + 1));
|
||||
|
|
|
@ -19,7 +19,6 @@ using mindspore::schema::PrimitiveType_DetectionPostProcess;
|
|||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
constexpr auto kScaleMinSize = 4;
|
||||
OpParameter *PopulateDetectionPostProcessParameter(const void *prim) {
|
||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||
MS_ASSERT(primitive != nullptr);
|
||||
|
@ -43,15 +42,15 @@ OpParameter *PopulateDetectionPostProcessParameter(const void *prim) {
|
|||
free(param);
|
||||
return nullptr;
|
||||
}
|
||||
if (scale->size() < kScaleMinSize) {
|
||||
if (scale->size() < kMinShapeSizeFour) {
|
||||
MS_LOG(ERROR) << "Invalid scale shape size " << scale->size();
|
||||
free(param);
|
||||
return nullptr;
|
||||
}
|
||||
param->h_scale_ = *(scale->begin());
|
||||
param->w_scale_ = *(scale->begin() + 1);
|
||||
param->x_scale_ = *(scale->begin() + 2);
|
||||
param->y_scale_ = *(scale->begin() + 3);
|
||||
param->x_scale_ = *(scale->begin() + kOffsetTwo);
|
||||
param->y_scale_ = *(scale->begin() + kOffsetThree);
|
||||
param->nms_iou_threshold_ = value->nms_iou_threshold();
|
||||
param->nms_score_threshold_ = value->nms_score_threshold();
|
||||
param->max_detections_ = value->max_detections();
|
||||
|
|
|
@ -20,10 +20,6 @@ using mindspore::schema::PrimitiveType_MaxPoolFusion;
|
|||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
constexpr size_t kMinShapeSize = 2;
|
||||
constexpr size_t kMinPadSize = 4;
|
||||
constexpr int kOffsetTwo = 2;
|
||||
constexpr int kOffsetThree = 3;
|
||||
OpParameter *PopulateAvgPoolParameter(const void *primitive) {
|
||||
auto pooling_prim = static_cast<const schema::Primitive *>(primitive);
|
||||
MS_ASSERT(pooling_prim != nullptr);
|
||||
|
@ -44,7 +40,7 @@ OpParameter *PopulateAvgPoolParameter(const void *primitive) {
|
|||
param->pool_mode_ = PoolMode_AvgPool;
|
||||
param->global_ = value->global();
|
||||
auto strides = value->strides();
|
||||
if (strides == nullptr || strides->size() < kMinShapeSize) {
|
||||
if (strides == nullptr || strides->size() < kMinShapeSizeTwo) {
|
||||
MS_LOG(ERROR) << "strides is invalid!";
|
||||
free(param);
|
||||
return nullptr;
|
||||
|
@ -52,7 +48,7 @@ OpParameter *PopulateAvgPoolParameter(const void *primitive) {
|
|||
param->stride_w_ = static_cast<int>(*(strides->begin() + 1));
|
||||
param->stride_h_ = static_cast<int>(*(strides->begin()));
|
||||
auto pad = value->pad();
|
||||
if (pad != nullptr && pad->size() >= kMinPadSize) {
|
||||
if (pad != nullptr && pad->size() >= kMinShapeSizeFour) {
|
||||
param->pad_u_ = static_cast<int>(*(pad->begin()));
|
||||
param->pad_d_ = static_cast<int>(*(pad->begin() + 1));
|
||||
param->pad_l_ = static_cast<int>(*(pad->begin() + kOffsetTwo));
|
||||
|
@ -60,7 +56,7 @@ OpParameter *PopulateAvgPoolParameter(const void *primitive) {
|
|||
}
|
||||
if (!param->global_) {
|
||||
auto kernel_size = value->kernel_size();
|
||||
if (kernel_size == nullptr || kernel_size->size() < kMinShapeSize) {
|
||||
if (kernel_size == nullptr || kernel_size->size() < kMinShapeSizeTwo) {
|
||||
MS_LOG(ERROR) << "kernel_size is invalid";
|
||||
free(param);
|
||||
return nullptr;
|
||||
|
@ -126,8 +122,8 @@ OpParameter *PopulateMaxPoolParameter(const void *primitive) {
|
|||
if (!param->global_) {
|
||||
auto kernel_size = value->kernel_size();
|
||||
auto strides = value->strides();
|
||||
if (kernel_size == nullptr || strides == nullptr || kernel_size->size() < kMinShapeSize ||
|
||||
strides->size() < kMinShapeSize) {
|
||||
if (kernel_size == nullptr || strides == nullptr || kernel_size->size() < kMinShapeSizeTwo ||
|
||||
strides->size() < kMinShapeSizeTwo) {
|
||||
MS_LOG(ERROR) << "kernel_size or strides is invalid";
|
||||
free(param);
|
||||
return nullptr;
|
||||
|
@ -137,7 +133,7 @@ OpParameter *PopulateMaxPoolParameter(const void *primitive) {
|
|||
param->stride_w_ = static_cast<int>(*(strides->begin() + 1));
|
||||
param->stride_h_ = static_cast<int>(*(strides->begin()));
|
||||
auto pad = value->pad();
|
||||
if (pad != nullptr && pad->size() >= kMinPadSize) {
|
||||
if (pad != nullptr && pad->size() >= kMinShapeSizeFour) {
|
||||
param->pad_u_ = static_cast<int>(*(pad->begin()));
|
||||
param->pad_d_ = static_cast<int>(*(pad->begin() + 1));
|
||||
param->pad_l_ = static_cast<int>(*(pad->begin() + kOffsetTwo));
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
constexpr int kOffsetTwo = 2;
|
||||
constexpr int kOffsetThree = 3;
|
||||
constexpr size_t kMinShapeSizeTwo = 2;
|
||||
constexpr size_t kMinShapeSizeFour = 4;
|
||||
typedef OpParameter *(*ParameterGen)(const void *prim);
|
||||
|
||||
class PopulateRegistry {
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace converter {
|
|||
namespace {
|
||||
constexpr int kBase = 10;
|
||||
constexpr int kQuantBitNumInt16 = 16;
|
||||
constexpr int kPathLengthUpperLimit = 1024;
|
||||
} // namespace
|
||||
Flags::Flags() {
|
||||
AddFlag(&Flags::fmkIn, "fmk", "Input model framework type. TF | TFLITE | CAFFE | MINDIR | ONNX", "");
|
||||
|
@ -428,7 +429,7 @@ std::string GetStrFromConfigFile(const std::string &file, const std::string &tar
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
char *real_path = _fullpath(resolved_path.get(), file.c_str(), 1024);
|
||||
char *real_path = _fullpath(resolved_path.get(), file.c_str(), kPathLengthUpperLimit);
|
||||
#else
|
||||
char *real_path = realpath(file.c_str(), resolved_path.get());
|
||||
#endif
|
||||
|
@ -486,7 +487,6 @@ std::vector<std::string> SplitStringToVector(const std::string &raw_str, const c
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace converter
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -46,6 +46,5 @@ int ModelParserRegistry::RegParser(const FmkType fmk, ModelParserCreator creator
|
|||
instance->parsers_[fmk] = creator;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -1494,9 +1494,7 @@ CNodePtr GenTransposeNode(const FuncGraphPtr &func_graph, const AnfNodePtr &inpu
|
|||
auto cnode = func_graph->NewCNode(trans_prim, {input_node, perm_node});
|
||||
MS_ASSERT(cnode != nullptr);
|
||||
cnode->set_fullname_with_scope(cnode_name);
|
||||
size_t input_size = 2;
|
||||
size_t output_size = 1;
|
||||
auto quant_params_holder = std::make_shared<lite::QuantParamHolder>(input_size, output_size);
|
||||
auto quant_params_holder = std::make_shared<lite::QuantParamHolder>(kInputSizeTwo, 1);
|
||||
auto trans_insert_prim = GetValueNode<PrimitivePtr>(cnode->input(0));
|
||||
trans_insert_prim->AddAttr("quant_params", quant_params_holder);
|
||||
return cnode;
|
||||
|
|
Loading…
Reference in New Issue