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

Discussion about gated convolution and its input #423

Open
tbuikr opened this issue Mar 31, 2020 · 1 comment
Open

Discussion about gated convolution and its input #423

tbuikr opened this issue Mar 31, 2020 · 1 comment

Comments

@tbuikr
Copy link

@tbuikr tbuikr commented Mar 31, 2020

Hello all, I create the thread to discuss about the gated convolution and its input. Many questions in the repo. have been asked for the problem #405, #252.

First of all, the input of gated convolution are: uncompleted image img and its mask. In which, the mask defined as

for image inpainting, the input are composed of both regions with valid pixels/features outside holes and invalid pixels/features (in shallow layers) or synthesized pixels/features (in deep layers) in masked regions

in which M is the corresponding binary mask, 1 represents pixel in the location (y, x) is valid, 0 represents the pixel is invalid

However, the official code has some confusing, that is the reason why many questions has been asked. In the code,

mask = np.zeros((1, height, width, 1), np.float32)

mask[:, bbox[0]+h:bbox[0]+bbox[2]-h,

From these lines, we can see that the mask defined as pixels 0 for outside the box and 1 for inside the box. Hence, the paper has a typo, it should be

in which M is the corresponding binary mask, 0 represents pixel in the location (y, x) is valid, 1 represents the pixel is invalid

So, the above lines answered the question #405, #252

Secondly, the incompleted image x defined as

batch_incomplete = batch_pos*(1.-mask)

It shows that the incompleted input is obtained by multiply the original image and (1-mask). It means we want to keep the original pixels of the image outside of the mask and set to zero pixels inside of the mask

Now, we will concatenate the incompleted input x and mask to obtain BxHxWx(channel_x + channel+mask). For example, the channel of x is 3 (RGB) and the channel of the mask is 1 (binary image). We have the input for gated convolution is BxHxWx4. Now, we will feed it to the gated convolution.

x = tf.layers.conv2d(

     x = tf.layers.conv2d( x, cnum, ksize, stride, dilation_rate=rate, activation=None, padding=padding, name=name)
    x, y = tf.split(x, 2, 3)
    x = activation(x)
    y = tf.nn.sigmoid(y)
    x = x * y

We can see that the concatenation of incompleted input and mask (defined as x) will go to a conv2d. The output then splits into two components: x is for convolution result of incompleted x, and y is for convolution result of mask. Then y goes to the sigmoid function to normalize it to [0,1] and multiply with activation(x) to perform gating.

Thanks for reading, please correct if I was wrong!

@JiahuiYu
Copy link
Owner

@JiahuiYu JiahuiYu commented May 8, 2020

@tbuikr Thanks for your details information.

  1. Regarding mask (whether 0 or 1 to represent masked region), I think the paper is consistent in the paper (those equations) and the code is correct in the code. The paper and the coder may not be consistent. I will keep this issue open to inform others who has similar confusion.

  2. Sorry I did not get your question. I think your understanding is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.