Search code examples
pythonnumpycoremlcoremltools

Coreml: How to add two tensors on slices?


I have two tensors: a.shape = [1, 3, 80, 80, 2] and b.shape = [1, 3, 80, 80, 19] and I only want to add b[..., 0:2] + a using the coreml model builder.

Something like this

b[..., 0:2] = (b[..., 0:2] * 2. - 0.5 + a)

Solution

  • Slice b into two parts, modify the 0:2 slice, then concatenate this back with the other slice of b into a (1, 3, 80, 80, 19) tensor.