Skip to content

Add Cropping layers support#1309

Merged
JanFSchulte merged 4 commits into
fastmachinelearning:mainfrom
HamzaEzzRa:cropping
Jun 27, 2025
Merged

Add Cropping layers support#1309
JanFSchulte merged 4 commits into
fastmachinelearning:mainfrom
HamzaEzzRa:cropping

Conversation

@HamzaEzzRa

Copy link
Copy Markdown
Contributor

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

  • 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

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

@HamzaEzzRa

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

@jmitrevs jmitrevs added the please test Trigger testing by creating local PR branch label Jun 12, 2025

@JanFSchulte JanFSchulte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test error are unrelated to this PR. Looks good to me.

@JanFSchulte

Copy link
Copy Markdown
Contributor

@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

Copy link
Copy Markdown
Contributor

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 JanFSchulte merged commit 71bf4ae into fastmachinelearning:main Jun 27, 2025
7 of 9 checks passed
calad0i pushed a commit to calad0i/hls4ml that referenced this pull request Jul 2, 2025
* added Cropping1D and Cropping2D keras layers support

* removed .bak templates files

* added cropping layers tests for vivado and vitis

* [pre-commit.ci] auto fixes from pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
vloncar pushed a commit that referenced this pull request Jul 3, 2025
…1191)

* skip oneapi test if icpx doesnt exist

* bit-exact-possible multidim softmax

* softmax fix

softmax fix

fix softmax parsing issue

ckpt

softmax fix

fix table size after overriding inv_inp_t

* move softmax attr to fpga backend, post rebase fix

* add keras v3 object parser

* add keras v3 layer handlers

* einsumdense and einsum

* add einsum templates

* bit-exact-possible multidim softmax

* symbolic bitwidth infer util

* add qinterval test

* keras v2-v3 reshape fn compability patch

* hgq2 layer handlers

* add bit-exact enforcement pass

* fix softmax accum fractional bits derivation

* add qeinsum test

* env update

* remove hgq v1 rewire behavier (superseded)

* fix del method in config class

* distributed arithmetic impl

* distributed arithmetic impl w/ conv

* distributed arithmetic templates

* prevent pointwise override for DA strategy

* add test for DA

* update proj conf

* disable delay_constraint in da4ml

* add hgq2 mha test

* update ci template

* require da4ml version

* pre-commit fix

* proper skip qeinsum test when condition not met

* softmax and activation fix

* hgq2 api change, prevent zero bw activation crash syn

* qinterval and bn bit-exactness fix

* fix einsum ax expansion and 0d output handling

* fix merge templates

* converter and bit-exact pass for ops layers

* use pointwise 2d for conv2d due to unknown flow changing

* fix einsum dense da impl corner case

* qinterval type fix

* fix corner case in qkeras converted proxy

* support mha def in (q,v) format

* update da4ml binding syntax

* update da4ml binding syntax x2

* use fixedvararr obj for da codegen

* more general build_lib script

* bring back hgq proxy embedded properties excl. pecision

* fix streaming conv1/2d da regression

* streaming template support for DA fix

* allow non-po-2 avg pooling

* ignore batch dim in parse_data_format

* keras v3 native pooling layer parser

* globalpooling handler fix

* unary lut bw derivation update

* keras 3.10 api change

* namespace fix for pointwise conv

* use constexpr for dim def

* conv pf handling

* keras v3 api change

* quality-of-life changes

* kv3 parser update

* shut up!

* post-rebase import conflicts

* remaining post-rebase fix

* bit-exactness corner case

* quantizer shrink corner case fix (sign bit)

* allow 0 bit activation...

* template and test fix

* intel/ac_types/ac_int.hpp:156:30: error: unsigned _BitInt must have a bit size of at least 1

* static_cast<typename ExtractPipeType<res_pipe>::value_type::value_type>

* doc leftover

* comment

* style

* [pre-commit.ci] auto fixes from pre-commit hooks

* model opt pass fix and avg pool fix

* squashed cosmetic and minor changes

* multi graph dimname fix

* Add Cropping layers support (#1309)

* added Cropping1D and Cropping2D keras layers support

* removed .bak templates files

* added cropping layers tests for vivado and vitis

* [pre-commit.ci] auto fixes from pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* bump da4ml version

* bit-exact algorithm minor change

---------

Co-authored-by: Jan-Frederik Schulte <jschulte@cern.ch>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hamza Ezzaoui Rahali <hamzaezzaouirahali@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

please test Trigger testing by creating local PR branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants