Skip to content
Advertisement

How to reproduce the Bottleneck Blocks in Mobilenet V3 with Keras API?

Using Keras API, I am trying to write the MobilenetV3 as explained in this article: https://arxiv.org/pdf/1905.02244.pdf with the architecture as described in this picture:

enter image description here

For that, I need to implement the bottloneck_blocks from the previous article https://arxiv.org/pdf/1801.04381.pdf. See image for architecture:

enter image description here

I managed to glue together the Initial and final Conv layers:

JavaScript

Where the bottleneck_block is given in the next snippet of code (modified from https://towardsdatascience.com/mobilenetv2-inverted-residuals-and-linear-bottlenecks-8a4362f4ffd5)

JavaScript

However, in bneck2 I get the following error:

JavaScript

I know the error means the dimension of the inputs and outputs are off, but I don’t know how to fix it to structure the network as the MobileNetV3.

What am I missing here?

For reference, here is source code in the tensorflow repo for the same network: https://github.com/tensorflow/models/blob/a174bf5b1db0e2c1e04697ff5aae5182bd1c60e7/research/slim/nets/mobilenet/mobilenet_v3.py#L130

Advertisement

Answer

The Solution is to modify the bottleneck_block as described in the V3 author’s repo:

JavaScript

The check in dimension and stride prevents the error I initially got when adding two nets that do not match the dimension

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement