ImageScaler: (https://github.com/onnx/onnx/blob/master/docs/Operators.md)
Scale and bias the input image. Bias values are stored in the same ordering as the image pixel format.
Attributes
bias : list of floats
Bias applied to each channel, same size as C.
scale : float
(float, default 1.0) the scale to apply.
In our current implementation framework of ONNX, we would like to handle like this:
class Scale(OnnxOpConverter):
@classmethod
def _impl_v1(cls, inputs, attr, params):
scale = float(attr.get('scale', 1.0))
scaled_sym = inputs[0] * scale
Then how do we handle lists of bias values? We can not use scaled_sym + attr.get(‘bias’), because attr.get(‘bias’) is type of tuple, which is not symbol or number type. We also can not use _sym.Variable(attr.get(‘bias’)), because we can not create here, all Symbol Variable should be all created in the:
for i in graph.input:
# from onnx v0.2, GraphProto.input has type ValueInfoProto,
# and the name is 'i.name'
i_name = self._parse_value_proto(i)
if i_name in self._params:
# i is a param instead of input
name_param = 'param_{}'.format(self._num_param)
self._num_param += 1
self._params[name_param] = self._params.pop(i_name)
self._nodes[name_param] = _sym.Variable(
name=name_param, shape=self._params[name_param].shape)
self._renames[i_name] = name_param
else:
name_input = 'input_{}'.format(self._num_input)
self._num_input += 1
self._nodes[name_input] = _sym.Variable(name=name_input)
self._renames[i_name] = name_input
# construct nodes, nodes are stored as directed acyclic graph
Many thanks in advance.