-
Notifications
You must be signed in to change notification settings - Fork 614
Speed up mean_filter2d with depthwise_conv2d #235
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea to accelerate the computation. Perhaps we could refactor test cases like https://github.com/tensorflow/tensorflow/blob/b14c390fc869b63fd2b1a4e6f4477ce410b9383e/tensorflow/python/kernel_tests/conv_ops_3d_test.py#L203
pad_left = (filter_width - 1) // 2 | ||
pad_right = filter_width - 1 - pad_left | ||
paddings = [[0, 0], [pad_top, pad_bottom], [pad_left, pad_right], [0, 0]] | ||
return tf.pad(image, paddings, mode=mode, constant_values=constant_values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an unit test for even shape, say (4, 4), and make sure the result is the same with scipy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we import scipy for test here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add a test case to check whether the output of explicitly zero padding is the same with the one of native "SAME" padding supported by depthwise_conv2d if we really do not want to compare the result produced by other packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, Tzu-Wei, perhaps we don't have to import scipy. Can we rename test_reflect_padding to test_reflect_padding_with_3x3_filter, and create an new test_reflect_padding_with_4x4_filter in the same way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, Facai, after a rough test, I found the padding method (or the anchor of even-sized kernel) of tensorflow seems different from the one of scipy. Here is the testing notbook. Take 4x4 filter for example. The explicit (zero) padding could yield the same result with implicit SAME padding supported by depthwise_conv2d. However, I have to adjust origin
argument in scipy's implement to (-1, -1) so that it could produce the same result. In this case, should we follow the scipy's implementation or match the implicit padding in tensorflow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW,
scipy's reflect padding => (c b a | a b c d | d c b)
TF's reflect padding => (d c b | a b c d | c b a)
TF's reflect padding = scipy's mirror padding
scipy's reflect padding = TF's symmetric padding
Seems that they have different meaning...
https://www.tensorflow.org/api_docs/python/tf/pad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, Tzu-Wei,
- If it's not easy to be compatible with scipy's implementation, we can give out all details about how we calculate it in the document.
- As for padding mode, I think
tf.pad
keeps consistent withnp.pad
. And similarity, we can either keep compatible with scipy, or write a detailed document.
Both are fine for me. cc @seanpmorgan Sean, what's your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure :-) In either way, it should be more docs there so let me write some details in this version first.
@Mainak431 Mainak, as the author, would you like to take a look? Thanks. |
@WindQAQ. I think we should only take 4D tensor. If anybody wants to process a single image. He/she should reshape the tensor to (1, image-shape). This pattern is followed in many tf operations that supports both single and batch processing. I think that trend should be followed here too. |
Yes. Image operations support this. But, many other operations i have come through does not support this. It seems there is no rule for the same. Ok. |
Can you please try your function with conv2d layer, activation layer, dropout and other basic layers by creating a small tf architecture. And ensure that it is working as expected even in the training of nn. A colab notebook will be helpful. As, the batch processing operation aims at direct usage of this in the nn architecture. Thanks. |
Ok, @facaiy What's your thought on this. I'd vote for that the input can be either 3-D or 4-D.
I'll run a toy model on MNIST dataset when I'm back to the office. |
Just out of curiosity, what happens to a 2D grayscale image. Batch of this kind of images will look like a 3D image. I think either this should be explicitly mentioned in the documentation. Or we should consider taking only 4D tensors. |
I think we have already mentioned this in the documentation :-) Users have to make sure that the last axis is the channel axis as the one in the core TF. addons/tensorflow_addons/image/filters.py Lines 58 to 60 in 51b18f6
|
Yes. But this thing that user have to set last axis as 1 for 2d grayscale
image is not explicitly mentioned. it will be useful for first time users.
I remember while i was using it for the first time, i ran into similar
errors and i had to stackoverflow it. Or, the other option is to take only
4D tensors. Whatever you think more suitable. Thanks.
…On Sun 5 May, 2019, 12:34 PM Tzu-Wei Sung, ***@***.***> wrote:
Just out of curiosity, what happens to a 2D grayscale image. Batch of this
kind of images will look like a 3D image. I think either this should be
explicitly mentioned in the documentation. Or we should consider taking
only 4D tensors.
I think we have already mentioned this in the documentation :-) Users have
to make sure that the last axis is the channel axis as the one in the core
TF.
https://github.com/tensorflow/addons/blob/51b18f626adce8724acfca713268bad8218c7fda/tensorflow_addons/image/filters.py#L58-L60
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#235 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AIRDMQWCERDH3FG7YJVGCSTPT2BGFANCNFSM4HKSEVWQ>
.
|
Sorry for the delay, @WindQAQ @Mainak431 I think we should keep consistency with tf.image: function works on either a single image (image is a 3-D Tensor), or a batch of images (image is a 4-D Tensor). |
@WindQAQ Tzu-Wei, could you update the PR when time allows :-) |
Thanks for reminding, facai. I'm currently workingon this :-) |
@facaiy, hi facai, I make some changes:
As for even-sized kernel test, should we use or import scipy for test here? Thanks for the suggestion! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to merge the PR, and then we can fix all unsolved comments, if any, in the following PRs.
You are owner of some files modified in this pull request. |
@gabrieldemarmiesse this doesn't happen often but wondering if you see any reason this happens? |
It's the first time I hear about it. Do you have other examples so I can see if there is a pattern? In the yaml, the only condition starting the bot is:
So that makes me quite perplex that something happens after a PR is closed. |
Sorry @seanpmorgan I've seriously no idea what causes this. If that happens too many time I'll take a much longer look. |
Closes #234. Will create another PR to clean up median_filter2d.