Spatial Pyramid Pooling, based on PR #560 (author: kloudkl)