GithubHelp home page GithubHelp logo

cnn-model-for-cifar-10-dataset's Introduction

Developing-CNN-Model-for-CIFAR-10-Dataset

AIM:

To develop a classification model for cifar10 data set using convolution neural network.

ALGORITHM:

STEP 1: Import the required packageas and import dataset using the give line: from tensorflow.keras.datasets import cifar10

STEP 2: Split the dataset into train and test data and scale their values for reducing the model complexity.

STEP 3: Use the onhot encoder to convert the output of train data and test data into categorical form.

STEP 4: Build a model with convolution layer, maxpool layer and flatten it. The build a fully contected layer.

STEP 5: Complie and fit the model. Train it and check with the test data.

STEP 6: Check the accuracy score and make amendments if required.

PROGRAM:

import numpy as np
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.datasets import cifar10
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.keras import utils
import pandas as pd
from sklearn.metrics import classification_report,confusion_matrix
from tensorflow.keras.preprocessing import image
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
X_train.shape
X_test.shape
single_image= X_train[0]
single_image.shape
print(y_train.shape)
print(X_train.min())
print(X_train.max())
X_train_scaled = X_train/255.0
X_test_scaled = X_test/255.0
print(X_train_scaled.min())
print(X_train_scaled.max())
print(y_train[0])
y_train_onehot = utils.to_categorical(y_train,10)
y_test_onehot = utils.to_categorical(y_test,10)
y_train_onehot.shape
X_train_scaled = X_train_scaled.reshape(-1,32,32,3) 
X_test_scaled = X_test_scaled.reshape(-1,32,32,3)
model = keras.Sequential()
model.add(layers.Input(shape=(32,32,3)))
model.add(layers.Conv2D(filters=28,kernel_size=(3,3),activation='relu',padding='same'))
model.add(layers.MaxPool2D(pool_size=(2,2)))
model.add(layers.Flatten())
model.add(layers.Dense(45,activation='relu'))
model.add(layers.Dense(88))
model.add(layers.Dense(120,activation='relu'))
model.add(layers.Dense(89,activation='relu'))
model.add(layers.Dense(71))
model.add(layers.Dense(63,activation='relu'))
model.add(layers.Dense(86))
model.add(layers.Dense(10,activation='softmax'))
model.summary()
model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics='accuracy')
model.fit(X_train_scaled ,y_train_onehot, epochs=7,
          batch_size=64,
          validation_data=(X_test_scaled,y_test_onehot))
metrics = pd.DataFrame(model.history.history)
metrics.head()
metrics[['accuracy','val_accuracy']].plot()
metrics[['loss','val_loss']].plot()
x_test_predictions = np.argmax(model.predict(X_test_scaled), axis=1)
print(metrics['accuracy'])
print(confusion_matrix(y_test,x_test_predictions))

OUTPUT:

Model summary:

image

Model accuracy vs val_accuracy:

image

Model loss vs val_loss:

image

Confusion matrix:

image

Classification report:

image

RESULT:

Thus we have created a classification model for Cifar10 dataset using the above given code.

cnn-model-for-cifar-10-dataset's People

Contributors

harshavardhini33 avatar

Watchers

 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.