forked from mindspore-Ecosystem/mindspore
!5145 modify caffe relu6 & tanh parser format
Merge pull request !5145 from lyvette/parser
This commit is contained in:
commit
dda115c0aa
|
@ -14,14 +14,32 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include "mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h"
|
#include "mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight,
|
STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto,
|
||||||
schema::CNodeT *op, std::vector<schema::TensorT *> *weightVec) {
|
const caffe::LayerParameter &weight,
|
||||||
|
schema::CNodeT *op,
|
||||||
|
std::vector<schema::TensorT *> *weightVec) {
|
||||||
|
MS_LOG(DEBUG) << "parse CaffeRelu6Parser";
|
||||||
|
if (op == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "op is null";
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
|
op->primitive = std::make_unique<schema::PrimitiveT>();
|
||||||
|
if (op->primitive == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "op->primitive is null";
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<schema::ActivationT> attr(new schema::ActivationT());
|
std::unique_ptr<schema::ActivationT> attr(new schema::ActivationT());
|
||||||
|
if (attr == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "new op failed";
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
attr->type = schema::ActivationType_RELU6;
|
attr->type = schema::ActivationType_RELU6;
|
||||||
// relu: negative_slope = 0, no parameter;
|
// relu: negative_slope = 0, no parameter;
|
||||||
// leakyrelu: negative_slope != 0;
|
// leakyrelu: negative_slope != 0;
|
||||||
|
@ -32,9 +50,10 @@ STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, const caffe::
|
||||||
attr->alpha = negative_slope;
|
attr->alpha = negative_slope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
op->primitive = std::make_unique<schema::PrimitiveT>();
|
|
||||||
op->primitive->value.value = attr.release();
|
op->name = proto.name();
|
||||||
op->primitive->value.type = schema::PrimitiveType_Activation;
|
op->primitive->value.type = schema::PrimitiveType_Activation;
|
||||||
|
op->primitive->value.value = attr.release();
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#ifndef MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_
|
#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_
|
||||||
#define MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_
|
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h"
|
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h"
|
||||||
|
@ -26,10 +26,12 @@ class CaffeRelu6Parser : public CaffeNodeParser {
|
||||||
public:
|
public:
|
||||||
CaffeRelu6Parser() : CaffeNodeParser("relu6") {}
|
CaffeRelu6Parser() : CaffeNodeParser("relu6") {}
|
||||||
|
|
||||||
STATUS Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op,
|
STATUS Parse(const caffe::LayerParameter &proto,
|
||||||
|
const caffe::LayerParameter &weight,
|
||||||
|
schema::CNodeT *op,
|
||||||
std::vector<schema::TensorT *> *weightVec) override;
|
std::vector<schema::TensorT *> *weightVec) override;
|
||||||
};
|
};
|
||||||
} // namespace lite
|
} // namespace lite
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
||||||
#endif // MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU_PARSER_H_
|
#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_
|
||||||
|
|
|
@ -24,11 +24,27 @@ STATUS CaffeTanhParser::Parse(const caffe::LayerParameter &proto,
|
||||||
const caffe::LayerParameter &weight,
|
const caffe::LayerParameter &weight,
|
||||||
schema::CNodeT *op,
|
schema::CNodeT *op,
|
||||||
std::vector<schema::TensorT *> *weightVec) {
|
std::vector<schema::TensorT *> *weightVec) {
|
||||||
std::unique_ptr<schema::ActivationT> attr(new schema::ActivationT());
|
MS_LOG(DEBUG) << "parse CaffeTanhParser";
|
||||||
attr->type = schema::ActivationType_TANH;
|
if (op == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "op is null";
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
op->primitive = std::make_unique<schema::PrimitiveT>();
|
op->primitive = std::make_unique<schema::PrimitiveT>();
|
||||||
op->primitive->value.value = attr.release();
|
if (op->primitive == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "op->primitive is null";
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<schema::ActivationT> attr(new schema::ActivationT());
|
||||||
|
if (attr == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "new op failed";
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
|
attr->type = schema::ActivationType_TANH;
|
||||||
|
|
||||||
|
op->name = proto.name();
|
||||||
op->primitive->value.type = schema::PrimitiveType_Activation;
|
op->primitive->value.type = schema::PrimitiveType_Activation;
|
||||||
|
op->primitive->value.value = attr.release();
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LITE_CAFFE_TANH_PARSER_H
|
#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TANH_PARSER_H
|
||||||
#define LITE_CAFFE_TANH_PARSER_H
|
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TANH_PARSER_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "tools/converter/parser/caffe/caffe_node_parser.h"
|
#include "tools/converter/parser/caffe/caffe_node_parser.h"
|
||||||
|
@ -27,10 +27,12 @@ class CaffeTanhParser : public CaffeNodeParser {
|
||||||
public:
|
public:
|
||||||
CaffeTanhParser() : CaffeNodeParser("tanh") {}
|
CaffeTanhParser() : CaffeNodeParser("tanh") {}
|
||||||
|
|
||||||
STATUS Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op,
|
STATUS Parse(const caffe::LayerParameter &proto,
|
||||||
|
const caffe::LayerParameter &weight,
|
||||||
|
schema::CNodeT *op,
|
||||||
std::vector<schema::TensorT *> *weightVec) override;
|
std::vector<schema::TensorT *> *weightVec) override;
|
||||||
};
|
};
|
||||||
} // namespace lite
|
} // namespace lite
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
||||||
#endif // LITE_CAFFE_TANH_PARSER_H
|
#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TANH_PARSER_H
|
||||||
|
|
Loading…
Reference in New Issue