Implementation and Easy way :Multi scale transfer learning keras-2020
Keras Framework will be basic structure for whole code,transfer learning .There are few deep learning model with more number of layers which are pretrained(already trained with Imagenet Dataset).Keras provide all model with easy one line code for import those model and work with your dataset.
Check the Video for Implementation walk through:
Check all the model below:
Models for image classification with weights trained on ImageNet:
In their respective webpage from keras doc,you can download and load in colab,those code are self-explanatory.
import keras
from keras.layers import *
from keras.models import *
from keras.preprocessing.image import *
Import the model you needed to work with,select from ABOVE MODEL FROM KERAS PAGE.
InceptionResNetV2_ms_1=keras.applications.xception.Xception(include_top=False, weights=’imagenet’,input_shape=(96,96,3))
InceptionResNetV2_ms_2=keras.applications.inception_v3.InceptionV3(include_top=False, weights=’imagenet’, input_shape=(96,96,3))
So,here i have imported two state-of-the-arts models for my multiscale model.And making the layers non-trainable and play with True also.
for layer in InceptionResNetV2_ms_1.layers:
layer.trainable = False
for layer in InceptionResNetV2_ms_2.layers:
layer.trainable = False
Adding the Global Average pool layer at end of two networks,
InceptionResNetV2_ms_1_out = InceptionResNetV2_ms_1.output
InceptionResNetV2_ms_1_final=GlobalAveragePooling2D()(InceptionResNetV2_ms_1_out)
InceptionResNetV2_ms_2_out = InceptionResNetV2_ms_2.output
InceptionResNetV2_ms_2_final=GlobalAveragePooling2D()(InceptionResNetV2_ms_2_out)
Merging the Both models’s input and output to make final mode with Classification layer.
merged_model = Concatenate()([InceptionResNetV2_ms_1_final, InceptionResNetV2_ms_2_final])
top_model= Dense(512,activation=’relu’)(merged_model)
top_model= Dense(10,activation=’softmax’)(top_model)
model=Model(inputs=[InceptionResNetV2_ms_1.input,InceptionResNetV2_ms_2.input],outputs=top_model)
model.summary()#execute the code ,check the summary.
Comple the model ,check for any layer errors or shape size error.
model.compile(loss=’categorical_crossentropy’, optimizer=’adam’, metrics=[‘accuracy’])
Using ImageDataGenerator,we gona load the images.But when to feed images to model we have to create function.
Above Image,to load the image we are creating the ImageDatagenerator with DataAgumentataion.
This function feed the images to Multi Scale CNN model.
Then,train the mutliscale model with .fit_generator
Check the Video for Implementation walk through: