26 #ifndef MXNET_CPP_OP_UTIL_H_
27 #define MXNET_CPP_OP_UTIL_H_
31 #if defined(MXNET_USE_CAFFE) && MXNET_USE_CAFFE != 0
32 #include <caffe/proto/caffe.pb.h>
33 #include <google/protobuf/text_format.h>
39 #if defined(MXNET_USE_CAFFE) && MXNET_USE_CAFFE != 0
41 inline ::caffe::LayerParameter textToCaffeLayerParameter(
const std::string& text) {
42 caffe::NetParameter np;
43 const bool success = google::protobuf::TextFormat::ParseFromString(text, &np);
44 CHECK_EQ(success,
true) <<
"Invalid protpbuf layer string: " << text;
45 return ::caffe::LayerParameter(np.layer(0));
48 template <
typename StreamType>
49 inline StreamType&
operator<<(StreamType& os, const ::caffe::LayerParameter& op) {
51 caffe::NetParameter np;
53 np.mutable_layer()->AddAllocated(
const_cast<::caffe::LayerParameter*
>(&op));
54 google::protobuf::TextFormat::PrintToString(np, &s);
55 np.mutable_layer()->ReleaseLast();
64 #endif // MXNET_CPP_OP_UTIL_H_