ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleOneHot.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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
18
20
21#include <loco.h>
22#include <oops/UserExn.h>
23
24namespace luci
25{
26
28{
29 // Only 4 Input come refered from
30 if (!GraphBuilder::validate(args, 4))
31 return false;
32
33 const auto &inputs = args.op.inputs;
34 const auto *options = args.op.builtin_options.AsOneHotOptions();
35 const auto tensors = args.reader.tensors();
36 const auto indices = tensors.at(inputs.at(0));
37 const auto depth = tensors.at(inputs.at(1));
38 const auto on_value = tensors.at(inputs.at(2));
39 const auto off_value = tensors.at(inputs.at(3));
40 assert(indices != nullptr);
41 assert(depth != nullptr);
42 assert(on_value != nullptr);
43 assert(off_value != nullptr);
44
45 if (options->axis < -1 || options->axis > static_cast<int32_t>(wrap(indices->shape()).size()))
46 return false;
47 if (wrap(depth->shape()).size() != 0)
48 return false;
49 if (wrap(on_value->shape()).size() != 0)
50 return false;
51 if (wrap(off_value->shape()).size() != 0)
52 return false;
53 if (on_value->type() != off_value->type())
54 return false;
55
56 return true;
57}
58
59CircleNode *CircleOneHotGraphBuilder::build_node(const circle::OperatorT &op,
60 const std::vector<CircleNode *> &inputs,
61 loco::Graph *graph) const
62{
63 auto *node = graph->nodes()->create<CircleOneHot>();
64
65 node->indices(inputs.at(0));
66 node->depth(inputs.at(1));
67 node->on_value(inputs.at(2));
68 node->off_value(inputs.at(3));
69
70 const auto *options = op.builtin_options.AsOneHotOptions();
71 node->axis(options->axis);
72
73 return node;
74}
75
76} // namespace luci
A neural network graph.
Definition Graph.h:161
bool validate(const ValidateArgs &args) const final
ONEHOT in Circle.
loco::Node * indices(void) const
bool validate(const ValidateArgs &args, size_t input_cnt) const
VectorWrapper< T > wrap(const flatbuffers::Vector< T > *vec)