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

The ge_layer implementation is not exactly the same as that in the paper #1

Open
zding047 opened this issue Nov 18, 2022 · 1 comment

Comments

@zding047
Copy link

zding047 commented Nov 18, 2022

In the paper, when stride=2, the left branch (Figure 5 (c)) has two depth-wise layers. Their output channels are the same, which is expand_ratio * C. But in the codes, due to the chain rule, the second layer's output has expand_ratio * expand_ratio * C channels.

Also, the expansion is with respect to the input dimension, instead of the output dimension.

image

bisenetv2-tf2/model.py

Lines 14 to 37 in e018b3b

def ge_layer(x_in, c, e=6, stride=1):
x = layers.Conv2D(filters=c, kernel_size=(3,3), padding='same')(x_in)
x = layers.BatchNormalization()(x)
x = layers.Activation('relu')(x)
if stride == 2:
x = layers.DepthwiseConv2D(depth_multiplier=e, kernel_size=(3,3), strides=2, padding='same')(x)
x = layers.BatchNormalization()(x)
y = layers.DepthwiseConv2D(depth_multiplier=e, kernel_size=(3,3), strides=2, padding='same')(x_in)
y = layers.BatchNormalization()(y)
y = layers.Conv2D(filters=c, kernel_size=(1,1), padding='same')(y)
y = layers.BatchNormalization()(y)
else:
y = x_in
x = layers.DepthwiseConv2D(depth_multiplier=e, kernel_size=(3,3), padding='same')(x)
x = layers.BatchNormalization()(x)
x = layers.Conv2D(filters=c, kernel_size=(1,1), padding='same')(x)
x = layers.BatchNormalization()(x)
x = layers.Add()([x, y])
x = layers.Activation('relu')(x)
return x

markus-k added a commit that referenced this issue Nov 18, 2022
@markus-k
Copy link
Owner

Thank you for reporting the issue! I have to admit that I'm quite out of the loop regarding ML, as this was part of my studies. I have created a pull request that should fix the double expension, feel free to have a look.

Also, the expansion is with respect to the input dimension, instead of the output dimension.
I'm not entirely sure what you mean by that, and how I'd go about fixing that. I'd be happy to accept a pull request :)

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

No branches or pull requests

2 participants