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

Implementing SKFF with Tensorflow #31

Open
IwakuraRein opened this issue Mar 9, 2022 · 0 comments
Open

Implementing SKFF with Tensorflow #31

IwakuraRein opened this issue Mar 9, 2022 · 0 comments

Comments

@IwakuraRein
Copy link

Hi. I tried to implement SKFF with tf 1.15:

def SKFF(self, inputs:list, reduction=8, name='SKFF'):
    with tf.variable_scope(name):
        ch_n=inputs[0].shape[3]
        num=len(inputs)
        d=max(ch_n//reduction, 4)
        
        inputs=tf.stack(inputs, 0)
        fea=tf.reduce_sum(inputs, 0)
        fea=tf.reduce_mean(fea, [1, 2], keep_dims=True)
        fea=self.conv_layer(fea, d, 1, name='du')
        fea=tf.keras.layers.PReLU()(fea)
        
        vecs=[self.conv_layer(fea, ch_n, 1, name=str(no)) for no in range(num)]
        vec=tf.concat(vecs,axis=1)
        weight=tf.nn.softmax(vec, axis=1)
        weight=tf.transpose(weight, (1, 0, 2, 3))
        weight=tf.expand_dims(weight, 2)
        out = inputs*weight
        out=tf.reduce_sum(out, 0)
        return out

Then I used timeline to profile my network. I noticed that there were lots of transpose operations (i.e., convert data from NHWC to NCHW) so the inference speed was actually slower than direct contact different scales.

Is there any way I can optimize the TensorFlow codes? Thanks.

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

1 participant