ONE - On-device Neural Engine
Loading...
Searching...
No Matches
caffe2_proto_helper.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "caffe2_proto_helper.h"
18
19namespace mir_caffe2
20{
21
22const ::caffe2::Argument &findArgumentByName(RepArgument args, const std::string &name)
23{
24 for (auto &arg : args)
25 if (arg.name() == name)
26 return arg;
27 throw std::runtime_error("Can't find argument with name: " + name);
28}
29
30bool hasArgument(RepArgument args, const std::string &name)
31{
32 for (auto &arg : args)
33 if (arg.name() == name)
34 return true;
35 return false;
36}
37
38int getSingleArgument(const ::caffe2::OperatorDef &op, const std::string &argument_name,
39 const int default_value)
40{
41 if (hasArgument(op.arg(), argument_name))
42 return static_cast<int>(findArgumentByName(op.arg(), argument_name).i());
43 return default_value;
44}
45
46float getSingleArgument(const ::caffe2::OperatorDef &op, const std::string &argument_name,
47 const float default_value)
48{
49 if (hasArgument(op.arg(), argument_name))
50 return findArgumentByName(op.arg(), argument_name).f();
51 return default_value;
52}
53
54std::string getSingleArgument(const ::caffe2::OperatorDef &op, const std::string &argument_name,
55 const std::string &default_value)
56{
57 if (hasArgument(op.arg(), argument_name))
58 return findArgumentByName(op.arg(), argument_name).s();
59 return default_value;
60}
61
62} // namespace mir_caffe2
const ::caffe2::Argument & findArgumentByName(RepArgument args, const std::string &name)
int getSingleArgument(const ::caffe2::OperatorDef &op, const std::string &argument_name, const int default_value)
bool hasArgument(RepArgument args, const std::string &name)
const ::google::protobuf::RepeatedPtrField<::caffe2::Argument > & RepArgument