Git Product home page Git Product logo

implementation-of-transfer-learning's Introduction

EX04--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:

237872257-0c867e5a-02f9-4e55-b90e-0f50b649c456

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    : Gunaseelan G
### Register number : 212221230031
import tensorflow as tf 
from tensorflow.keras.datasets import cifar10
from tensorflow.keras.applications import VGG19 
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Dropout
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import ReduceLROnPlateau
import pandas as pd
from sklearn.metrics import classification_report,confusion_matrix
import numpy as np

(x_train, y_train), (x_test, y_test) = cifar10.load_data ()
x_train = x_train.astype ("float32") / 255.0
x_test = x_test.astype ("float32") / 255.0
base_model = VGG19 (include_top = False, 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 (512, activation = 'relu'))
model.add(Dropout (0.5))
model.add(Dense (10, activation= 'softmax'))

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

learning_rate_reduction = ReduceLROnPlateau (monitor = 'val_accuracy')
model.fit(x_train, y_train, batch_size=64, epochs=15, validation_data=(x_test, y_test), callbacks=[learning_rate_reduction])
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
out1

Accuracy, Validation Accuracy Vs Iteration

out2

Classification Report:

out3

Confusion Matrix:

out4

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

guru-guna 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.