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 
26 #ifndef MXNET_CPP_OP_UTIL_H_
27 #define MXNET_CPP_OP_UTIL_H_
28 
29 #include <string>
30 
31 #if defined(MXNET_USE_CAFFE) && MXNET_USE_CAFFE != 0
32 #include <caffe/proto/caffe.pb.h>
33 #include <google/protobuf/text_format.h>
34 #endif
35 
36 namespace mxnet {
37 namespace cpp {
38 
39 #if defined(MXNET_USE_CAFFE) && MXNET_USE_CAFFE != 0
40 
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));
46 }
47 
48 template<typename StreamType>
49 inline StreamType& operator << (StreamType& os, const ::caffe::LayerParameter& op) {
50  std::string s;
51  caffe::NetParameter np;
52  // Avoid wasting time making a copy -- just push in out default object's pointer
53  np.mutable_layer()->AddAllocated(const_cast<::caffe::LayerParameter *>(&op));
54  google::protobuf::TextFormat::PrintToString(np, &s);
55  np.mutable_layer()->ReleaseLast();
56  os << s;
57  return os;
58 }
59 #endif
60 
61 } // namespace cpp
62 } // namespace mxnet
63 
64 #endif // MXNET_CPP_OP_UTIL_H_
namespace of mxnet
Definition: base.h:126
std::ostream & operator<<(std::ostream &out, const NDArray &ndarray)