Skip to content

Add a tf.contrib.image.translate function - #12306

Merged
gunan merged 14 commits into
tensorflow:masterfrom
ringw:translate
Oct 10, 2017
Merged

gunan merged 14 commits into
tensorflow:masterfrom
ringw:translate

Conversation

@ringw

@ringw ringw commented Aug 15, 2017

Copy link
Copy Markdown
Contributor

Opening as a replacement for #10748. Made a small simplification. @sampepose

@ringw ringw self-assigned this Aug 15, 2017
@ringw
ringw requested a review from vrv August 15, 2017 21:12
@mention-bot

Copy link
Copy Markdown

@ringw, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jart, @tensorflower-gardener and @drpngx to be potential reviewers.

@googlebot

Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

axis=1)


def translations_to_projective_transforms(translations):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

does this need to be public, or can it be an hidden?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We already expose angles_to_projective_transforms so that users can compose transformation matrices, so my plan was to make similar public methods for any transformation.

@ringw
ringw requested a review from ebrevdo August 15, 2017 21:28

@vrv vrv left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Letting eugene look at the rest of this.

@sampepose

Copy link
Copy Markdown

Thanks, @ringw! Sorry I haven't gotten a chance to finish off that PR. Lgtm

@ahundt

ahundt commented Sep 10, 2017

Copy link
Copy Markdown
Contributor

@sampepose I think you need to sign the CLA before this can be merged. Otherwise it will be stuck forever. :-)

@sampepose

sampepose commented Sep 10, 2017 via email

Copy link
Copy Markdown

return output


def translate(images, translations, interpolation="NEAREST"):

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.

name= arg on any function that creates new ops., use it inside a "with name_scope(...):" before creating any ops. here, elsewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added name= args and tf.name_scope(name) throughout.

"""
translation_or_translations = ops.convert_to_tensor(
translations, name="translations", dtype=dtypes.float32)
if len(translation_or_translations.get_shape()) == 1:

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.

what if .get_shape() returns TensorShape(None)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is an issue throughout, but it's really useful to do this validation eagerly and be able to return a tensor with the correct shape (HW, HWC, or NHWC). Added docstrings indicating which arguments need a static shape with a known rank.

@ringw

ringw commented Sep 13, 2017

Copy link
Copy Markdown
Contributor Author

@ahundt @sampepose The googlebot comment says "The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.", so hopefully the CLA is OK?

Indicate in the docstrings when the static shape of the arguments must
have a known rank.
@ahundt

ahundt commented Sep 13, 2017

Copy link
Copy Markdown
Contributor

Oh I see you're right, I had only looked at the cla: no label.

@drpngx

drpngx commented Sep 17, 2017

Copy link
Copy Markdown
Contributor

@ringw we really need that CLA. Could you double check? Usually, it's a problem with the email address, or commits getting co-mingled the PR. Thanks.

@ringw

ringw commented Sep 21, 2017

Copy link
Copy Markdown
Contributor Author

@drpngx The only details I see about the CLA are: "The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request."

@sampepose confirmed in this pull request that he's OK with contributing his commit. Are there any further steps necessary? Sam's commit has [email protected] which appears to be his email on his profile, and my commits have [email protected]. I don't see any other commits that got co-mingled.

@drpngx

drpngx commented Sep 21, 2017

Copy link
Copy Markdown
Contributor

@sampepose Please leave a comment that you're OK with it, and then we can override and merge.

However, we need an OK from @ebrevdo first. Thanks.

@ringw

ringw commented Sep 21, 2017

Copy link
Copy Markdown
Contributor Author

Sam already replied with "LGTM".

@drpngx

drpngx commented Sep 21, 2017

Copy link
Copy Markdown
Contributor

@ringw I saw that, I just want a clear comment.

@sampepose

sampepose commented Sep 21, 2017 via email

Copy link
Copy Markdown

@sb2nov

sb2nov commented Sep 25, 2017

Copy link
Copy Markdown
Contributor

@drpngx is this okay to merge ?

@drpngx

drpngx commented Sep 26, 2017

Copy link
Copy Markdown
Contributor

I think we'd still like an approval from @ebrevdo. Once that is done, @gunan, @martinwicke or @jhseu can override the CLA flag and merge.

[24, 19, 14, 9, 4]]])

def test_translate(self):
with self.test_session():

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.

Move the new session inside the loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.



def rotate(images, angles, interpolation="NEAREST"):
def rotate(images, angles, interpolation="NEAREST", name="rotate"):

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.

name=None and use the default second argument to name_scope below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done throughout.

image_or_images = ops.convert_to_tensor(images)
if image_or_images.dtype.base_dtype not in _IMAGE_DTYPES:
raise TypeError("Invalid dtype %s." % image_or_images.dtype)
if len(image_or_images.get_shape()) == 2:

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.

Check that shape.ndims is not none first

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done throughout.

(num_rows, num_columns) (HW). The rank must be statically known (the
shape is not `TensorShape(None)`.
translations: A vector representing [dx, dy] or (if images has rank 4)
a vector of length num_images, with a [dx, dy] vector for each image in

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.

You mean a matrix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Raises:
TypeError: If `image` is an invalid type.
"""
with ops.name_scope(name):

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.

name, "translate"):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done throughout.

with ops.name_scope(name):
angle_or_angles = ops.convert_to_tensor(
angles, name="angles", dtype=dtypes.float32)
if len(angle_or_angles.get_shape()) == 0: # pylint: disable=g-explicit-length-test

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.

Check ndims first

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

else:
raise TypeError("Translations should have rank 1 or 2.")
num_translations = array_ops.shape(translations)[0]
return array_ops.concat(

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.

Explain what you're doing here. Match dtype to image dtype?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, this just processes the translation matrices, which are always float32. Added a comment to clarify this, and describe the translation matrix.

@sb2nov sb2nov added the stat:awaiting response Status - Awaiting response from author label Sep 26, 2017
@ringw

ringw commented Oct 4, 2017

Copy link
Copy Markdown
Contributor Author

Ping @ebrevdo

@ringw

ringw commented Oct 10, 2017

Copy link
Copy Markdown
Contributor Author

@drpngx @gunan Could we go ahead and override the CLA flag and merge? Thanks!

@gunan
gunan merged commit 90121d5 into tensorflow:master Oct 10, 2017
@gunan

gunan commented Oct 10, 2017

Copy link
Copy Markdown
Contributor

Sorry for the delay, merged.

@ringw
ringw deleted the translate branch October 10, 2017 18:51
@ringw

ringw commented Oct 10, 2017

Copy link
Copy Markdown
Contributor Author

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: no stat:awaiting response Status - Awaiting response from author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants