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

Use ImageProjectiveTransformV3 for TF >= 2.4.0 #2293

Merged

Conversation

WindQAQ
Copy link
Member

@WindQAQ WindQAQ commented Dec 15, 2020

Description

Support fill_value and nearest fill_mode with ImageProjectiveTransformV3.

Type of change

Checklist:

  • I've properly formatted my code according to the guidelines
    • By running Black + Flake8
    • By running pre-commit hooks
  • This PR addresses an already submitted issue for TensorFlow Addons
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • This PR contains modifications to C++ custom-ops

How Has This Been Tested?

Test new features.

@bot-of-gabrieldemarmiesse

@sayoojbk @mels630

You are owners of some files modified in this pull request.
Would you kindly review the changes whenever you have the time to?
Thank you very much.

@@ -37,6 +37,7 @@ def transform(
transforms: TensorLike,
interpolation: str = "NEAREST",
fill_mode: str = "CONSTANT",
fill_value: TensorLike = 0.0,
Copy link
Member Author

@WindQAQ WindQAQ Dec 15, 2020

Choose a reason for hiding this comment

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

I have no idea where should we put the new argument. Should we maintain backward compatibility so we have to put it in the end of args? @seanpmorgan WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Yes this looks like the best position

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@WindQAQ WindQAQ changed the title Image/use image projective transform v3 Use image projective transform v3 Dec 15, 2020
@WindQAQ
Copy link
Member Author

WindQAQ commented Dec 15, 2020

@seanpmorgan Hi Sean, this is only for TF2.4. Our nightly version will pin to both TF2.3 and TF2.4, right?

@seanpmorgan
Copy link
Member

@seanpmorgan Hi Sean, this is only for TF2.4. Our nightly version will pin to both TF2.3 and TF2.4, right?

Trying to expand our python compatibility to be 2.3+. The wheel will be built against TF2.4 so custom-ops will need TF2.4, but everything else would be great to keep compatibility.

Raising a NotImplementedError for <=2.4 is an option

@bhack
Copy link
Contributor

bhack commented Dec 15, 2020

Tracking many TF core issues and PRs my opinion Is that currently TF has a quite strict policy to not backport not only features but also bug fixes from nightly/master. Patch releases are sparse and for security fixes only.

So I think that we need to start to support and promote only the last official TF release.

@WindQAQ
Copy link
Member Author

WindQAQ commented Dec 15, 2020

Trying to expand our python compatibility to be 2.3+. The wheel will be built against TF2.4 so custom-ops will need TF2.4, but everything else would be great to keep compatibility.

Raising a NotImplementedError for <=2.4 is an option

I can do a warning for TF<2.4 that fill_value is not supported and is always 0.

Tracking many TF core issues and PRs my opinion Is that currently TF has a quite strict policy to not backport not only features but also bug fixes from nightly/master. Patch releases are sparse and for security fixes only.

So I think that we need to start to support and promote only the last official TF release.

I am more with this proposal though, there is always a loop from "I want the new feature" -> "Please use latest TF" -> "codes does not work in latest TF" -> "Fallback to older TF" -> "I want the new feature" XD

@bhack
Copy link
Contributor

bhack commented Dec 15, 2020

I am more with this proposal though, there is always a loop from "I want the new feature" -> "Please use latest TF" -> "codes does not work in latest TF" -> "Fallback to older TF" -> "I want the new feature" XD

Often it Is more like:
There Is a bug -> It Is fixed in the last version, or in nightly/master -> please use the last official or nightly wheels.

@WindQAQ WindQAQ changed the title Use image projective transform v3 Use ImageProjectiveTransformV3 for TF >= 2.4.0 Dec 15, 2020
)
else:
fill_mode = fill_mode.upper()
# TODO(WindQAQ): Get rid of the check once we drop TensorFlow < 2.4 support.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we automatically/programmatically fail with https://github.com/tensorflow/addons/blob/master/setup.py#L79?
What do you think? I suppose that this kind of things will stay forever in the code 😉

Copy link
Member

Choose a reason for hiding this comment

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

Eh, we can clean up the codebase as our compatibility matrix moves. See #2294

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but It could be easier if we are failing in different points in the sourfe when we move the minimal version or the single version we support. Do you understand what I meant?

Copy link
Contributor

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

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

Thanks I need this so much! Was going crazy over the inconsistency between the different fill options for geometric transformations :D.

The only thing I am not so sure about is whether the nearest fill option actually does work.

There should probably be tests for the "nearest" and "bilinear" interpolation modes of transform as well. Currently, the interpolation argument is untested.

The test_bilinear and test_uint8 tests in transform_ops_test.py apply to rotate only, which does make use of transform internally, but I don't think this relation should be assumed by the test case.

tensorflow_addons/image/transform_ops.py Outdated Show resolved Hide resolved
tensorflow_addons/image/transform_ops.py Show resolved Hide resolved
tensorflow_addons/image/translate_ops.py Outdated Show resolved Hide resolved
tensorflow_addons/image/translate_ops.py Show resolved Hide resolved
@fsx950223
Copy link
Member

@WindQAQ
Copy link
Member Author

WindQAQ commented Dec 16, 2020

The function should be transfered to official repo? There is a similar function https://github.com/tensorflow/tensorflow/blob/2a7d45c6800a99e4158526e25ec128ddd90e37f7/tensorflow/python/keras/layers/preprocessing/image_preprocessing.py#L625.

They do not make it public. In fact, they migrate it to KPL without informing us early this year 😭 So we are just doing a fork of private API now.

bhack added a commit to bhack/tensorflow that referenced this pull request Dec 16, 2020
@bhack
Copy link
Contributor

bhack commented Dec 16, 2020

They do not make it public. In fact, they migrate it to KPL without informing us early this year sob So we are just doing a fork of private API now.

Lets see 😉 ... tensorflow/tensorflow#45742

@seanpmorgan
Copy link
Member

They do not make it public. In fact, they migrate it to KPL without informing us early this year sob So we are just doing a fork of private API now.

Lets see 😉 ... tensorflow/tensorflow#45742

Agree with the PR, though I don't want to have to wait for a response prior to 0.12 release.

@bhack
Copy link
Contributor

bhack commented Dec 16, 2020

Agree with the PR, though I don't want to have to wait for a response prior to 0.12 release.

It is impossible to achieve this for 0.12 cause this will got in TF 2.5 but you can bypass the policy and depend on a private API for this case, as you want.

@seanpmorgan
Copy link
Member

Agree with the PR, though I don't want to have to wait for a response prior to 0.12 release.

It is impossible to achieve this for 0.12 cause this will got in TF 2.5 but you can bypass the policy and depend on a private API for this case, as you want.

Understand the TF core PR wouldn't be until TF2.5, but what do you mean depend on a private API and bypass the policy? There is no private API in this PR right?

@bhack
Copy link
Contributor

bhack commented Dec 16, 2020

Agree with the PR, though I don't want to have to wait for a response prior to 0.12 release.

It is impossible to achieve this for 0.12 cause this will got in TF 2.5 but you can bypass the policy and depend on a private API for this case, as you want.

Understand the TF core PR wouldn't be until TF2.5, but what do you mean depend on a private API and bypass the policy? There is no private API in this PR right?

I meant as an alternative to maintain a (function) fork.

interpolation: str = "NEAREST",
fill_mode: str = "CONSTANT",
interpolation: str = "nearest",
fill_mode: str = "constant",
Copy link
Member Author

@WindQAQ WindQAQ Dec 16, 2020

Choose a reason for hiding this comment

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

This will not break the compatibility as we always uppercase it when passing into raw ops. Just to canonicalize the documentation and arguments.

@aaronmondal
Copy link
Contributor

@WindQAQ Thanks for changing to lowercase. So much prettier :). Would you like me to file a PR for the missing testcases in interpolation?

@WindQAQ
Copy link
Member Author

WindQAQ commented Dec 17, 2020

@WindQAQ Thanks for changing to lowercase. So much prettier :). Would you like me to file a PR for the missing testcases in interpolation?

It's more than welcome to do that!

Copy link
Member

@seanpmorgan seanpmorgan left a comment

Choose a reason for hiding this comment

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

LGTM Thanks! Thanks @aaronmondal for the review!

@seanpmorgan seanpmorgan merged commit 3ca3010 into tensorflow:master Dec 17, 2020
@bhack
Copy link
Contributor

bhack commented Dec 17, 2020

Agree with the PR, though I don't want to have to wait for a response prior to 0.12 release.

It is impossible to achieve this for 0.12 cause this will got in TF 2.5 but you can bypass the policy and depend on a private API for this case, as you want.

Understand the TF core PR wouldn't be until TF2.5, but what do you mean depend on a private API and bypass the policy? There is no private API in this PR right?

I meant as an alternative to maintain a (function) fork.

It seems that we need to maintain the fork but if the new policy Is to maintain the public API surface minimal isn't better to handle private API occasional breakage instead of maintain fork in multiple points in the source code?

jrruijli pushed a commit to jrruijli/addons that referenced this pull request Dec 23, 2020
* Use ImageProjectiveTransformV3
* Mark unsupported things for TF<2.4.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants