def _convert_reduce_sum(converter: ONNXConverter, onnx_op: INodeProto): x = converter.get_variable(onnx_op.input[0]) attrs = attribute_dict(onnx_op) axes = attrs["axes"].ints keepdims = (attrs["keepdims"].i if "keepdims" in attrs else 1) == 1 for a in axes: x, = Sum(None, axis=x.order.axes[a])(x) if not keepdims: x = x.squeeze(axis=[x.order.axes[i] for i in axes]) converter.set_variable(onnx_op.output[0], x)
def _convert_sum(converter: ChainerConverter, c_op: "chainer.functions.Sum"): x = converter.get_variable(c_op.inputs[0]) for axis in list(x.order.axes) if c_op.axis is None else [ x.order.axes[i] for i in c_op.axis ]: x, = Sum(None, axis=axis)(x) # chainer.functions.sum supported "keepdims" parameter since v1.24 if chainer.__version__ >= "1.24" and c_op.keepdims and x.ndim > 1: pass else: x = x.squeeze(axis) converter.set_variable(c_op.outputs[0](), x)
def sum_handler(converter: TensorFlowConverter, tf_op: "tf.Operation"): x = converter.get_variable(tf_op.inputs[0]) axis = converter.get_variable(tf_op.inputs[1]) assert isinstance( axis, ConstantVariable ), "[TensorFlowConverter] Operation 'Sum' with dynamic axis is not supported yet." for axis in [ x.order.axes[i] for i in axis.data.astype(int).flatten().tolist() ]: x, = Sum(None, axis=axis)(x) if not tf_op.get_attr("keep_dims") and x.ndim > 1: x = x.squeeze(axis) converter.set_variable(tf_op.outputs[0], x)