Code Monkey home page Code Monkey logo

implementation-of-transfer-learning's Introduction

Implementation-of-Transfer-Learning

Aim

To Implement Transfer Learning for CIFAR-10 dataset classification using VGG-19 architecture.

Problem Statement and Dataset

The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images.

The dataset is divided into five training batches and one test batch, each with 10000 images. The test batch contains exactly 1000 randomly-selected images from each class. The training batches contain the remaining images in random order, but some training batches may contain more images from one class than another. Between them, the training batches contain exactly 5000 images from each class.

Here are the classes in the dataset, as well as 10 random images from each:

VGG19 is a variant of the VGG model which in short consists of 19 layers (16 convolution layers, 3 Fully connected layer, 5 MaxPool layers and 1 SoftMax layer).

Now we have use transfer learning with the help of VGG-19 architecture and use it to classify the CIFAR-10 Dataset

DESIGN STEPS

STEP 1:

Import tensorflow and preprocessing libraries

STEP 2:

Load CIFAR-10 Dataset & use Image Data Generator to increse the size of dataset

STEP 3:

Import the VGG-19 as base model & add Dense layers to it

STEP 4:

Compile and fit the model

Step 5:

Predict for custom inputs using this model

PROGRAM

Developed By: Shafeeq Ahamed. S

Register No: 212221230092

Libraries

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report,confusion_matrix

from keras import Sequential
from keras.layers import Flatten,Dense,BatchNormalization,Activation,Dropout
from tensorflow.keras import utils
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import ReduceLROnPlateau

from tensorflow.keras.preprocessing.image import ImageDataGenerator

from keras.datasets import cifar10
from tensorflow.keras.applications import VGG19

Loading Dataset & One Hot Encoding Outputs

(x_train,y_train),(x_test,y_test)=cifar10.load_data()

y_train_onehot = utils.to_categorical(y_train,10)
y_test_onehot = utils.to_categorical(y_test,10)

Import VGG-19 model & add dense layers

base_model = VGG19(include_top=False, weights = "imagenet",
                   input_shape = (32,32,3))

for layer in base_model.layers:
  layer.trainable = False

model = Sequential()
model.add(base_model)
model.add(Flatten())
model.add(Dense(250,activation=("relu")))
model.add(Dropout(0.2))
model.add(Dense(100,activation=("relu")))
model.add(Dropout(0.35))
model.add(Dense(10,activation=("softmax")))
model.summary()

model.compile(optimizer=Adam(learning_rate=0.001), 
              loss='sparse_categorical_crossentropy', 
              metrics=['accuracy'])

learning_rate_reduction = ReduceLROnPlateau(monitor='val_accuracy',patience=3,
                                            verbose=1,factor=0.5,min_lr=0.00001)

model.fit(x_train, y_train, batch_size=500, epochs=10, validation_data=(x_test, y_test), 
          callbacks=[learning_rate_reduction])

Metrics

metrics = pd.DataFrame(model.history.history)

metrics[['loss','val_loss']].plot()
metrics[['accuracy','val_accuracy']].plot()

x_test_predictions = np.argmax(model.predict(x_test), axis=1)

print(confusion_matrix(y_test,x_test_predictions))
print(classification_report(y_test,x_test_predictions))

OUTPUT

Training Loss, Validation Loss Vs Iteration Plot

Training Loss, Validation Loss Vs Iteration Accuracy, Validation Accuracy Vs Iteration
image image

|

Classification Report

Confusion Matrix

Conculsion

  • We got an Accuracy of 60% with this model.There could be several reasons for not achieving higher accuracy. Here are a few possible explanations:

Dataset compatibility:

  • VGG19 was originally designed and trained on the ImageNet dataset, which consists of high-resolution images.
  • In contrast, the CIFAR10 dataset contains low-resolution images (32x32 pixels).
  • The difference in image sizes and content can affect the transferability of the learned features.
  • Pretrained models like VGG19 might not be the most suitable choice for CIFAR10 due to this disparity in data characteristics.

Inadequate training data:

  • If the CIFAR10 dataset is relatively small, it may not provide enough diverse examples for the model to learn robust representations.
  • Deep learning models, such as VGG19, typically require large amounts of data to generalize well.
  • In such cases, you could consider exploring other architectures that are specifically designed for smaller datasets, or you might want to look into techniques like data augmentation or transfer learning from models pretrained on similar datasets.

Model capacity:

  • VGG19 is a deep and computationally expensive model with a large number of parameters.
  • If you are limited by computational resources or working with a smaller dataset, the model's capacity might be excessive for the task at hand.
  • In such cases, using a smaller model architecture or exploring other lightweight architectures like MobileNet or SqueezeNet could be more suitable and provide better accuracy.

RESULT

Thus, transfer Learning for CIFAR-10 dataset classification using VGG-19 architecture is successfully implemented.

implementation-of-transfer-learning's People

Contributors

shafeeqahameds avatar etjabajasphin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.