hls4ml icon indicating copy to clipboard operation
hls4ml copied to clipboard

Add Cropping layers support

Open HamzaEzzRa opened this issue 7 months ago • 2 comments

Description

This PR adds support for Keras' Cropping1D and Cropping2D layers with Vivado and Vitis backend in both io_parallel and io_stream modes.

The implementation is straightforward and follows a similar style to zero-padding implementations. I added tests for Vivado and Vitis backends.

I have yet to run this on a board, but implementation was successful targeting a ZCU102, using Vivado 2019.1. Although this type of layer has a fairly niche usage, I still found a use case for it, and it could benefit the community.

Linked Issue: #1308

Type of change

  • [x] New feature (non-breaking change which adds functionality)

Tests

I added unit tests in test/pytest/test_cropping.py

Test Configuration:

  • io_type: ["io_stream", "io_parallel"]
  • backend: ["Vivado", "Vitis"]
  • model_type: ["1d", "2d"]

Checklist

  • [x] I have read the guidelines for contributing.
  • [x] I have commented my code, particularly in hard-to-understand areas.
  • [ ] I have made corresponding changes to the documentation.
  • [x] My changes generate no new warnings.
  • [x] I have installed and run pre-commit on the files I edited or added.
  • [x] I have added tests that prove my fix is effective or that my feature works.

HamzaEzzRa avatar Jun 10 '25 00:06 HamzaEzzRa

pre-commit.ci autofix

HamzaEzzRa avatar Jun 10 '25 00:06 HamzaEzzRa

@calad0i Do you think this needs to be included explicitly also in the keras v3 parser, or should we let the fallback take care of it?

JanFSchulte avatar Jun 26 '25 18:06 JanFSchulte

As discussed in today's dev meeting, we are merging this PR now with the understanding that it might be good to generalize in the future as to not have separate implementations for 1D and 2D cases, as well as adding a dedicated layer handler to the keras v3 parser.

JanFSchulte avatar Jun 27 '25 16:06 JanFSchulte