Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolate tensor operation (Inference Only) #1246

Merged
merged 9 commits into from
Mar 2, 2024
Merged

Interpolate tensor operation (Inference Only) #1246

merged 9 commits into from
Mar 2, 2024

Conversation

Nikaidou-Shinku
Copy link
Contributor

@Nikaidou-Shinku Nikaidou-Shinku commented Feb 3, 2024

Pull Request Template

Checklist

  • Confirmed that run-checks all script has been executed.
  • Made sure the book is up to date with changes in this PR.

Related Issues/PRs

Fixes #455

Changes

  • ✅: This feature is complete.
  • 🚧: I'm working on this feature.
  • ⚠️: This feature requires upstream support.
  • 🆘: I need help completing this feature.
Backend\Feature Nearest-neighbor Bilinear Bicubic Anti-aliasing
WGPU 🚧
Candle ⚠️ ⚠️ ⚠️
LibTorch 🚧
NdArray 🚧
Autodiff 🆘 🆘 🆘 🆘
Fusion 🚧

Notes

  • Candle currently only supports nearest-neighbor interpolation, and there is an issue about adding bilinear interpolation: Support for grid_sample huggingface/candle#1392.
  • I haven't learned much about ML, so I may need help from others with the Autodiff backend. If you are interested in these features, come and help implement them!
  • With interpolation support, we can implement ONNX's Resize operator in Burn, there is an issue about it: Addition of Resize operator #510. Maybe we can implement it in this PR, or in a new PR after this PR is merged.
  • If you have any other needs related to interpolation, welcome to discuss!

Testing

I will write new test cases to test these features, but currently the test cases are lacking because many features are not completed yet.

Completed

  • Nearest-neighbor interpolation for WGPU, Candle, LibTorch, NdArray and Fusion backends.
  • Bilinear interpolation for WGPU, LibTorch, NdArray and Fusion backends.
  • Bicubic interpolation for WGPU, LibTorch, NdArray and Fusion backends.

All these implementations give results consistent with PyTorch.

Not done

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: Patch coverage is 95.83333% with 26 lines in your changes are missing coverage. Please review.

Project coverage is 85.54%. Comparing base (9bf3f3f) to head (705b06a).

❗ Current head 705b06a differs from pull request most recent head 6b5a563. Consider uploading reports for the commit 6b5a563 to get more accurate results

Files Patch % Lines
crates/burn-tch/src/ops/module.rs 0.00% 12 Missing ⚠️
crates/burn-autodiff/src/ops/module.rs 0.00% 6 Missing ⚠️
crates/burn-ndarray/src/ops/interpolate.rs 97.04% 6 Missing ⚠️
crates/burn-candle/src/ops/module.rs 85.71% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1246    +/-   ##
========================================
  Coverage   85.54%   85.54%            
========================================
  Files         595      596     +1     
  Lines       68280    68121   -159     
========================================
- Hits        58409    58275   -134     
+ Misses       9871     9846    -25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ashdtu
Copy link
Contributor

ashdtu commented Feb 21, 2024

Hi @Nikaidou-Shinku Thanks for this great in-progress PR. I have some idea on how to implement the Autodiff for this operation and would like to help out on this. Let me know If there have been any new updates. Would be pushing my changes as well soon!

@Nikaidou-Shinku
Copy link
Contributor Author

I have some idea on how to implement the Autodiff for this operation and would like to help out on this.

Hello! I'm honestly at a loss as to how to implement autodiff, so it would be great if you could help!

Let me know If there have been any new updates.

I'm sorry that I'm a little busy during this time and may not be able to push this PR forward. But I will find a way to get it done before March, and I really hope to see this new feature in the next big version of Burn!

feat: bilinear interpolation for tch, ndarray and wgpu backend

fix: reduce test case size to avoid exceeding floating-point precision limits

feat: support nearest-neighbor interpolation for ndarray backend

feat: support nearest-neighbor interpolation for wgpu backend

feat: support fusion backend

fix: no-std support

build: upgrade dependencies
@Nikaidou-Shinku
Copy link
Contributor Author

Nikaidou-Shinku commented Feb 24, 2024

Sorry I may not have time to continue working on this PR at the moment, I would be grateful if someone could take over it, or maybe consider merging the already completed parts and keeping the rest as TODO.

I will list the current progress of this PR below.

Completed

  • Nearest-neighbor interpolation for WGPU, Candle, LibTorch, NdArray and Fusion backends.
  • Bilinear interpolation for WGPU, LibTorch, NdArray and Fusion backends.
  • Bicubic interpolation for WGPU, LibTorch, NdArray and Fusion backends.

All these implementations give results consistent with PyTorch.

Not done

  • Autodiff backend. (which means that training is currently unavailable)
  • Anti-aliasing for bilinear and bicubic interpolation.
  • Parameter align_corners for bilinear and bicubic interpolation. (for more information check here)
  • Mode nearest-exact. (see the link previous for details)
  • ONNX's Resize operator.
  • More test cases.
  • Documentation

#1393 has been filed to complete the remaining items

@Nikaidou-Shinku Nikaidou-Shinku marked this pull request as ready for review February 24, 2024 10:37
Copy link
Collaborator

@antimora antimora left a comment

Choose a reason for hiding this comment

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

@Nikaidou-Shinku , thank you so much for this contribution! This is a big step for the full feature. We can start working on the Resize ONNX op which was a major missing op for many image related ONNX could not be implemented.

It is very responsible of you to list of TODOs and what it is completed.

I am approving it so it could be merged. We can file all remaining TODOs into an issue.

@ashdtu , @louisfd Please reviewing it and let's merge it.

@antimora antimora requested a review from ashdtu February 24, 2024 16:47
@antimora antimora added the feature The feature request label Feb 24, 2024
Copy link
Contributor

@ashdtu ashdtu left a comment

Choose a reason for hiding this comment

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

No specific correction comments. I think this looks great. The test cases cover both upsample, downsample operation. overall, LGTM!


/// Interpolation options.
#[derive(new)]
pub struct InterpolateOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is great for future proofing. later on we can add other options like align corners here.

id % strides.2,
);

let y_in = (y_ratio * h as f64).floor() as usize;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think It's great that we are keeping this consistent with OpenCV version of this operation. Just as FYI, some methods may use ceil() or round() as well to find nearest coordinate so we may see Candle/Tch backend's implementation output slightly differ. But i think this makes sense.

@antimora antimora changed the title Interpolate operation Interpolate tensor operation (Inference Only) Mar 1, 2024
@antimora antimora merged commit 7d44f0b into tracel-ai:main Mar 2, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature The feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement interpolate function (inference only)
3 participants