mxnet
op_util.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
27 #ifndef MXNET_CPP_OP_UTIL_H_
28 #define MXNET_CPP_OP_UTIL_H_
29 
30 #include <string>
31 
32 #if defined(MXNET_USE_CAFFE) && MXNET_USE_CAFFE != 0
33 #include <caffe/proto/caffe.pb.h>
34 #include <google/protobuf/text_format.h>
35 #endif
36 
37 namespace mxnet {
38 namespace cpp {
39 
40 #if defined(MXNET_USE_CAFFE) && MXNET_USE_CAFFE != 0
41 
42 inline ::caffe::LayerParameter textToCaffeLayerParameter(const std::string& text) {
43  caffe::NetParameter np;
44  const bool success = google::protobuf::TextFormat::ParseFromString(text, &np);
45  CHECK_EQ(success, true) << "Invalid protpbuf layer string: " << text;
46  return ::caffe::LayerParameter(np.layer(0));
47 }
48 
49 template<typename StreamType>
50 inline StreamType& operator << (StreamType& os, const ::caffe::LayerParameter& op) {
51  std::string s;
52  caffe::NetParameter np;
53  // Avoid wasting time making a copy -- just push in out default object's pointer
54  np.mutable_layer()->AddAllocated(const_cast<::caffe::LayerParameter *>(&op));
55  google::protobuf::TextFormat::PrintToString(np, &s);
56  np.mutable_layer()->ReleaseLast();
57  os << s;
58  return os;
59 }
60 #endif
61 
62 } // namespace cpp
63 } // namespace mxnet
64 
65 #endif // MXNET_CPP_OP_UTIL_H_
namespace of mxnet
Definition: base.h:127
std::ostream & operator<<(std::ostream &out, const NDArray &ndarray)