Updated March 16, 2023
Introduction to Keras Pre-trained Models
Keras pre-trained models is an image classification model which was used in the python application. Keras will contain ten pre-trained models for the image classification which were trained on the data which was pretrained. Imagenet is nothing but a large collection of the data image which contains 1000 categories of images. The pretrained models can classify the image which falls into the image which contains 1000 categories.
Key Takeaways
- The keras pre-trained model is nothing but the saved network which was trained by using a large dataset or the large-scale task classification.
- We can use a pretrained model or we can use transfer learning for customizing the model of the specified task. The intuition behind transfer is image classification.
Overview of Keras Pre-trained Models
Basically, there are two ways to create the pretrained models in keras i.e. one is the functional API model and another is the sequential model. The sequential model contains the linear stack layer, we can simply add the layers into the sequential model by calling the method name as add. Another model is nothing but the functional API which was used to create complex models which contain multiple inputs and outputs.
Tensor flow is a highly used library for machine learning, it contains keras built-in support. We can easily call the functions which were related to the keras module. The vision of computers is an interesting branch of ML. The dataset of image net is a turning point for the researchers of computer vision. Image net is nothing but the benchmark of image classification and testing accuracy for deep learning models.
Keras Pre-trained Models
There are multiple pretrained models. The vgg16 is a pre-trained model, it is trained by using imagenet. Below is the example of keras pre-trained vgg16 model as follows:
Code:
keras.applications.vgg16.VGG16 (
include_top = True,
weights = 'imagenet',
input_tensor = None,
input_shape = None,
pooling = None,
classes = 1000
)
Output:
Another pre-trained model of keras is mobilenetv2. This model is trained by using imagenet. The below example shows the mobilenetv2 model as follows. In the below example, the alpha will control the network. If the value is below 1, then it will decrease the number of filters. If the value is above 1 then it will increase the number of filters in every layer.
Code:
keras.applications.mobilenet_v2.MobileNetV2 (
input_shape = None,
alpha = 2.0,
include_top = True,
weights = 'pretrained',
input_tensor = None,
pooling = None,
classes = 2000
)
Output:
Another pretrained model of keras is inceptionresnetv2. This model is trained by using imagenet. The below example shows the load of the inceptionresnetv2 model as follows. This model is built by using the data format of channels first or channels last.
Code:
keras.applications.inception_resnet_v2.InceptionResNetV2 (
include_top = True,
weights = 'pretrained',
input_tensor = None,
input_shape = None,
pooling = None,
classes = 3000)
Output:
Another pretrained model of keras is inceptionv3. It is trained by using imagenet. Below is the syntax of the inceptionv3 pretrained model as follows.
Code:
keras.applications.inception_v3.InceptionV3 (
include_top = True,
weights = 'pretrained',
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000)
Output:
Keras Pre-trained Model Functions
Below is the function of keras pretrained. Below is the function of resnet50 as follows:
Code:
tf.keras.applications.ResNet50(
include_top = True,
weights = "pretrained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 3000,
**kwargs
)
Output:
Another function of the keras pretrained model is vgg19. The default input size of vgg19 is 299*299. Below is the example of vgg19 function model as follows.
Code:
tf.keras.applications.VGG19(
include_top = True,
weights = "pre-trained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000,
classifier_activation = "model",
)
Output:
Another function of the keras pretrained model is resnet50v2 as follows. The below example shows resnet50v2 function as follows.
Code:
tf.keras.applications.ResNet50V2(
include_top = True,
weights = "pre-trained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000,
classifier_activation = "model")
Output:
Another function of the keras pretrained model is resnet101 as follows. The below example shows resnet101 function as follows.
Code:
tf.keras.applications.ResNet101 (
include_top = True,
weights = "pre-trained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000,
classifier_activation = "model")
Output:
Another function of the keras pretrained model is resnet152 as follows. The below example shows resnet152 function as follows.
Code:
tf.keras.applications.ResNet152 (
include_top = True,
weights = "pre-trained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000,
classifier_activation = "model")
Output:
Keras Pre-trained Model Benefits
Below are the keras pretrained model benefits as follows. Pre-trained model contains the benefits which define the keras model.
- The keras pre-trained model will require less time for training the model, it has been trained by using the different tasks.
- The keras model is trained by using different tasks, this model is defined by using the different tasks.
- The keras model is used in the task by using the smaller data sets which were already defined in a larger dataset.
- By using the keras pretrained model we can transfer the weights into the new task. The new task is created by using pretrained models.
- In Keras’s pretrained model we can take the pre-trained model by using dataset for performing classification.
- The keras pretrained model is a set of classification tasks that was optimized in a different parameter.
- The keras pretrained model is used in a transfer learning model which was showing the benefits of pretrained models.
- The list of keras pretrained modules is calling into the deep learning model which represents keras application.
- Keras pretrained model excepts specific kinds of input preprocessing for the resnet models.
Keras Image Classification Models
Keras application is the deep learning model which was available with the pretrained weights. This module is used in fine-tuning and prediction. Weights are downloaded automatically by using the instantiating model.
Below are the image classification models available in keras as follows:
- Xception
- Vgg16
- Vgg19
- ResNet50
- Inceptionv3
- InceptionResNetV2
- MobileNetv2
- DenseNet
- NasNet
- MobileNet
All the architecture of keras is compatible with the backbends. The below example shows classify the imagenet classes with ResNet50 as follows.
Code:
tf.keras.applications.ResNet50 (
include_top = True,
weights = "pre-trained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000,
classifier_activation = "model")
Output:
The below example shows extract features from the vgg16 as follows
Code:
tf.keras.applications.vgg16 (
include_top = True,
weights = "pre-trained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000,
classifier_activation = "model")
Output:
The below example shows extract features from the vgg19 as follows.
Code:
tf.keras.applications.vgg19 (
include_top = True,
weights = "pre-trained",
input_tensor = None,
input_shape = None,
pooling = None,
classes = 2000,
classifier_activation = "model")
Output:
FAQ
Given below are the FAQs mentioned:
Q1. What is the use of keras pretrained model?
Answer: Pretrained model is nothing but the saved network which was trained by using a larger dataset that was defined in the keras model.
Q2. What is the use of vgg16 model in keras pretrained models?
Answer: The vgg16 model is trained by using imagenet. This model weights and other parameters in that model.
Q3. What is the use of vgg19 model in keras pretrained models?
Answer: The vgg19 model is trained by using imagenet. This model is the same as vgg16 model which was defined in the pretrained model.
Conclusion
Tensor flow is a highly used library for machine learning, it contains keras built-in support. Keras pre-trained models is an image classification model which was used in the python application. Keras will contain ten pre-trained models for the image classification which were trained on the data which was pretrained.
Recommended Articles
This is a guide to Keras Pre-trained Models. Here we discuss the introduction, keras Pre-trained model functions, benefits, and image classification, models. You may also have a look at the following articles to learn more –