43 class EmptyAccessor final :
public graph::ITensorAccessor
47 EmptyAccessor() =
default;
50 bool access_tensor(ITensor &tensor)
override 63 bool is_mutation_supported(Graph &g)
70 for(
const auto &utype : unsupported_node_types)
72 if(!g.nodes(utype).empty())
84 void remove_optimized_nodes(Graph &g)
88 for(
const auto &opt_type : optimized_node_types)
90 const std::vector<NodeID> opt_nodes_ids = g.nodes(opt_type);
91 for(
const auto &node_id : opt_nodes_ids)
93 INode *node = g.node(node_id);
96 Edge *input_edge = node->input_edge(0);
100 INode *producer = input_edge->producer();
101 const EdgeID producer_edge_id = input_edge->producer_idx();
108 g.remove_node(node->id());
111 for(
auto &driving_node : driving_nodes)
113 g.add_connection(producer->id(), producer_edge_id, driving_node.node_id, driving_node.index);
125 auto &tensors = g.tensors();
126 for(
auto &tensor : tensors)
128 if(tensor !=
nullptr)
135 tensor->desc().quant_info = QuantizationInfo(0.125f, -10);
155 template <
typename NT>
156 void convert_special_node(Graph &g, std::function<
bool(INode *, Tensor *)>
const &f)
158 const std::vector<NodeID> nodes_ids = g.nodes(NT::node_type);
159 for(
const auto &nodes_id : nodes_ids)
161 INode *node = arm_compute::utils::cast::polymorphic_downcast<NT *>(g.node(nodes_id));
164 Tensor *output_tensor = node->output(0);
167 f(node, output_tensor);
175 void convert_special_tensors(Graph &g)
177 auto softmax_func = [](INode * node,
Tensor * tensor)
182 tensor->desc().quant_info = QuantizationInfo(1.f / 256.f, 0);
186 tensor->desc().quant_info = QuantizationInfo(1.f / 256.f, -128);
191 auto act_func = [](INode * node,
Tensor * tensor)
193 auto *act_node = arm_compute::utils::cast::polymorphic_downcast<ActivationLayerNode *>(node);
198 tensor->desc().quant_info = QuantizationInfo(1.f / 128.f, 128);
202 tensor->desc().quant_info = QuantizationInfo(1.f / 256.f, 0);
209 tensor->desc().quant_info = QuantizationInfo(1.f / 128.f, 0);
213 tensor->desc().quant_info = QuantizationInfo(1.f / 256.f, -128);
219 convert_special_node<ActivationLayerNode>(g, act_func);
220 convert_special_node<SoftmaxLayerNode>(g, softmax_func);
229 void handle_nodes_with_bias(Graph &g)
237 for(
const auto &spc_type : special_node_types)
239 const std::vector<NodeID> scp_nodes_ids = g.nodes(spc_type);
240 for(
const auto &node_id : scp_nodes_ids)
242 INode *node = g.node(node_id);
245 Tensor *tensor = node->input(2);
246 if(tensor !=
nullptr)
252 auto params = node->common_node_params();
253 params.name = params.name.empty() ?
"" : params.name +
"Bias";
255 TensorDescriptor b_desc = node->input(1)->desc();
257 b_desc.shape = TensorShape(depth);
259 auto accessor = std::make_unique<EmptyAccessor>();
261 g.add_connection(b_nid, 0, node_id, 2);
270 : _mutate_type{ mutate_type }
276 return "SyntheticDataTypeMutator";
286 if(is_mutation_supported(g))
289 remove_optimized_nodes(g);
292 convert_tensors(g, _mutate_type);
293 convert_special_tensors(g);
296 handle_nodes_with_bias(g);
std::vector< NodeIdxPair > get_driving_nodes(const INode &node)
Get the list of driving nodes of a given node.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 S32 per channel
SyntheticDataTypeMutator(DataType mutate_type=DataType::QASYMM8)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
quantized, asymmetric fixed-point 8-bit number unsigned
MutationType type() const override
Returns mutation type.
MutationType
Mutation type.
#define ARM_COMPUTE_LOG_GRAPH_VERBOSE(x)
quantized, asymmetric fixed-point 8-bit number signed
static NodeID add_const_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor=nullptr)
Adds a Const node to the graph.
virtual void mutate(Graph &g) override
Walk the graph and perform a specific mutation.
DataType
Available data types.
const char * name() override
Returns mutator name.
size_t get_dimension_idx(DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get index of a tensor's given dimension depending on its layout.