Building a Streamlit app to identify Indian Food — Part II (Importing EfficientNet-V2 in Keras)

Pradeep Adhokshaja
2 min readNov 12, 2022

--

Streamlit Logo

In the previous post, we took some time to get the data for Indian Food images and augment it with different transformations. In this part of the article series, we will try to import the pre-trained EfficientNet-V2 model, which is trained on the ImageNet data set.

EfficientNet -V2

Efficient-V2 is a family of state-of-the-art (released by Google Researchers in 2021) convolutional neural networks that have faster training speeds and better parameter efficiency.

The EfficientNet-V2 includes combinations of convolutional blocks namely, the MBConv blocks and the Fused MBConv blocks that both use squeeze and excitation layers. MBConv block uses a depth-wise 3x3 convolutional layer while Fused MBConv block uses a 3x3 convolutional layer. More about the architecture can be found here

MBConv Block and Fused — MBConv Blocks taken from the EfficientNet-V2 paper

The complete architecture is as follows.

EfficientNet-V2 Architecture.

Keras Pre-trained Models

Instead of building complex state-of-the-art networks from scratch, you can download pre-trained state-of-the-art models directly from the keras applications library. This saves a lot of time from building a neural network from scratch and training them for hours/days.

We import an EfficientNetV2 base model and change the last layer to reflect 85 classes. The code snippet that does this is as follows:

import tensorflow as tf
from tensorflow import keras
base_model = tf.keras.applications.efficientnet_v2.EfficientNetV2B0(


weights = 'imagenet',

include_preprocessing = False,
include_top=False
)
avg = keras.layers.GlobalMaxPool2D()(base_model.output)output = keras.layers.Dense(85,activation='softmax')(avg)model = keras.Model(inputs = base_model.input,outputs = output)

The above code snippet has weights based on the 1000 class ImageNet data set. We need to fine-tune these weights so that we can use this network to correctly classify each image as one of 85 classes of Indian Food.

Next Steps

In the next leg of this series of articles, I will talk about the fine-tuning process that enables us to successfully classify Indian Food images. The next article can be found here.

--

--

Pradeep Adhokshaja
Pradeep Adhokshaja

Written by Pradeep Adhokshaja

Data Scientist @Philips. Passionate about ML,Statistics & hiking. If you like to buy me a coffee, you can use this link https://ko-fi.com/pradeepadhokshaja

No responses yet