ARM-software / ComputeLibrary

The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
MIT License
2.76k stars 767 forks source link

Space-to-depth bug #1003

Closed puneetmatharu closed 1 year ago

puneetmatharu commented 1 year ago

Problem description

I'm working with a fork of the ACL library and I'm currently looking into adding space-to-depth support for a use-case that I have. Whilst looking into what was already there, I noticed a bug in the output shape calculation.

Issue

There appears to be a bug in the calculation of the output shape:

https://github.com/ARM-software/ComputeLibrary/blob/aabef6c0584f06f4c0f4b61fb787d80374240619/arm_compute/core/utils/misc/ShapeCalculator.h#L1162-L1176

cf. Tensorflow docs here. In short, the space-to-depth transformation should result in a reduction in the height and weight and an increase in the number of channels -- the opposite of what the code above says.

Solution

I believe lines 1171-1173 should be changed to:

output_shape.set(idx_width, input->tensor_shape()[idx_width] / block_shape);
output_shape.set(idx_height, input->tensor_shape()[idx_height] / block_shape);
output_shape.set(idx_depth, input->tensor_shape()[idx_depth] * (block_shape * block_shape));
morgolock commented 1 year ago

Hi @puneetmatharu

Thanks for raising this. We have fixed the problem with this patch https://review.mlplatform.org/c/ml/ComputeLibrary/+/8668

puneetmatharu commented 1 year ago

Excellent, thanks for sorting that out! I'll close the issue now.