Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #57672
I've added wrap padding as an option to the pad function. Much of the code I carried over from the
MirrorPad
op. The main difference between the two implementations is theToInputCoord
function:https://github.com/mattbahr/tensorflow/blob/4833ab97fc7cbdabef6be49d621084930800c4a8/tensorflow/core/kernels/wrap_pad_op.h#L273-L284
tensorflow/tensorflow/core/kernels/image/mirror_pad_op.h
Lines 284 to 295 in 3abf81f
An alternative to this solution could be to update the
MirrorPad
op to handle WRAP mode on top of REFLECT and SYMMETRIC. This would eliminate the duplicated code and not require the maintenance of a brand new op, but I wasn't sure if that might be increasing the scope of that op beyond what it should be.This implementation works as is on CPU and GPU. I haven't gotten to TPU or XLA yet.
See the NumPy documentation for how padding should work in wrap mode: https://numpy.org/doc/stable/reference/generated/numpy.pad.html