Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is SeparableConv2D slower than Conv2D?

I've been experimenting with different types of convolution layers, to check their computational speeds. my code, in the beginning, was as follows.

def conv_block_A(layer):
    block = tf.keras.layers.Conv2D(filters=128, kernel_size=3, strides=1, padding='same')(layer)
    block = tf.keras.layers.Conv2D(filters=196, kernel_size=3, strides=1, padding='same')(block)
    block = tf.keras.layers.Conv2D(filters=128, kernel_size=3, strides=1, padding='same')(block)
    block = tf.keras.layers.BatchNormalization(momentum=0.8)(block)
    block = tf.keras.layers.LeakyReLU(alpha=0.2)(block)

    return block

after going through a few blogs, I changed my code as

def conv_block_A(layer):
    block = tf.keras.layers.SeparableConv2D(filters=128, kernel_size=3, strides=1, padding='same')(layer)
    block = tf.keras.layers.SeparableConv2D(filters=196, kernel_size=3, strides=1, padding='same')(block)
    block = tf.keras.layers.SeparableConv2D(filters=128, kernel_size=3, strides=1, padding='same')(block)
    block = tf.keras.layers.BatchNormalization(momentum=0.8)(block)
    block = tf.keras.layers.LeakyReLU(alpha=0.2)(block)

    return block

the training process became twice as fast on CPUs, but, the training has become very slow on Tesla T4. what could be the reason?

like image 367
explr_1298 Avatar asked Jun 28 '26 20:06

explr_1298


1 Answers

It's a known issue with GPU's it was fixed in #33836. Also, you should update your GPU driver. As a rule of thumbs speedup by doing separable convolution is more noticeable with large kernel sizes because of the overhead involving doing two convolutions might be larger than the speedups.

like image 123
cosine Avatar answered Jul 01 '26 10:07

cosine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!