jatinchowdhury18 / RTNeural

Real-time neural network inferencing
BSD 3-Clause "New" or "Revised" License
582 stars 58 forks source link

Streaming Conv 2D and Batchnorm 2D implementations #89

Closed DamRsn closed 1 year ago

DamRsn commented 1 year ago

Hi Jatin,

I have implemented two new layers, 2d streaming convolution and 2d batch normalization, for a project that I am currently working on for the Neural Audio Plugin Competition. These layers are designed specifically for neural networks that process frequency domain data or similar. When those layers are used, the model runs on every frame, which contains a certain number of frequency bins, instead of every individual sample.

At the moment, I have only implemented these layers using the Eigen backend.

Please find below some details of the implementation. Let me know what you think!

The chosen streaming approach works by performing all necessary calculations involving a frame as soon as it is acquired, and then storing the obtained results in the layer states. These states are utilized to generate the accurate output.

codecov-commenter commented 1 year ago

Codecov Report

Merging #89 (5ece924) into main (c521243) will decrease coverage by 0.52%. The diff coverage is 91.20%.

@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
- Coverage   96.06%   95.55%   -0.52%     
==========================================
  Files          36       42       +6     
  Lines        2872     3237     +365     
==========================================
+ Hits         2759     3093     +334     
- Misses        113      144      +31     
Impacted Files Coverage Δ
RTNeural/batchnorm/batchnorm_eigen.tpp 100.00% <ø> (ø)
RTNeural/model_loader.h 81.62% <72.94%> (-3.12%) :arrow_down:
RTNeural/batchnorm/batchnorm2d_eigen.h 86.95% <86.95%> (ø)
...Neural/conv1d_stateless/conv1d_stateless_eigen.tpp 94.28% <94.28%> (ø)
RTNeural/ModelT.h 90.32% <96.15%> (+1.61%) :arrow_up:
RTNeural/conv1d_stateless/conv1d_stateless_eigen.h 96.15% <96.15%> (ø)
RTNeural/conv2d/conv2d_eigen.h 97.67% <97.67%> (ø)
RTNeural/Model.h 100.00% <100.00%> (ø)
RTNeural/batchnorm/batchnorm2d_eigen.tpp 100.00% <100.00%> (ø)
RTNeural/batchnorm/batchnorm_eigen.h 75.00% <100.00%> (+1.66%) :arrow_up:
... and 4 more

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

jatinchowdhury18 commented 1 year ago

Thanks for the PR, at a glance these changes look great! Since there's a lot of changes here, it's going to take me a minute to review them thoroughly, but I just wanted to let you know that I am looking at it.

Supporting only an Eigen implementation is fine for now, but in order to stay compatible with the other backends, it would probably make sense to add some #if RTNEURAL_USE_EIGEN gaurds to the "main" headers (e.g. batchnorm2d.h), and for the relevant tests. That should also help the CI jobs to pass.

DamRsn commented 1 year ago

Cool thanks!

I've just added a few #if RTNEURAL_USE_EIGEN so that other backend can compile