Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion pytorch to coreml for element-wise maximum operation

I tried to convert a PyTorch model to coreml with the element-wise maximum operation based on coremltools.

With torch.max operation, I got

ValueError: node input.2 (max) got 2 input(s), expected [3]

With torch.maximum operation

RuntimeError: PyTorch convert function for op 'maximum' not implemented.

Any idea to solve this issue?

like image 903
Zhongbo Chen Avatar asked Aug 02 '26 03:08

Zhongbo Chen


1 Answers

I encountered the same issue in conversion with pytorch element-wise operation to coreml model, but solved it by adding support for torch.maximum and torch.minimum for the MIL converter with the torch frontend.

@register_torch_op
def maximum(context, node):
    inputs = _get_inputs(context, node)
    x = inputs[0]
    y = inputs[1]
    out = mb.maximum(x=x, y=y, name=node.name)
    context.add(out)
like image 87
mingfei Avatar answered Aug 03 '26 17:08

mingfei