ONLINE SUMMER TRAINING Online Courses Free Tutorials 
 Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
0 like 0 dislike
708 views
in AI-ML-Data Science Projects by (151 points)

In this project we will build a convolution neural network(CNN) in keras with python on CIFAR-10 dataset. First we will explore our Dataset, then we will train our neural network using python and Keras.



GOEDUHUB's Online Courses @ Udemy



Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

5.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon

6.

Complete Python Programming from scratch with Projects Apply Coupon

2 Answers

0 like 0 dislike
by (151 points)
selected by
 
Best answer

Steps for Image Classification on CIFAR-10:

1. Load the dataset from keras dataset module.

  1. from keras.datasets import cifar10

  2. import matplotlib.pyplot as plt

  3. (train_X,train_Y),(test_X,test_Y)=cifar10.load_data()

Output:

2. Plot some images from the dataset to visualize the dataset.

  1. n=6

  2. plt.figure(figsize=(20,10))

  3. for i in range(n):

  4. plt.subplot(330+1+i)

  5. plt.imshow(train_X[i])

  6. plt.show()

Output:

3. Import the required layers and modules to create our CNN architecture.

  1. from keras.models import Sequential

  2. from keras.layers import Dense

  3. from keras.layers import Dropout

  4. from keras.layers import Flatten

  5. from keras.constraints import maxnorm

  6. from keras.optimizers import SGD

  7. from keras.layers.convolutional import Conv2D

  8. from keras.layers.convolutional import MaxPooling2D

  9. from keras.utils import np_utils

4.  Converting the pixel values of the dataset to float type and then normalising the dataset.

  1. train_x=train_X.astype('float32')

  2. test_X=test_X.astype('float32')

  3. train_X=train_X/255.0

  4. test_X=test_X/255.0

5. Now performing encoding for target classes.

  1. train_Y = np_utils.to_categorical(train_Y)

  2. test_Y = np_utils.to_categorical(test_Y)

  3. num_classes = test_Y.shape[1]

6. Creating Sequential model and then adding layers.

  1. model = Sequential()

  2. model.add(Conv2D(32,(3,3),input_shape=(32,32,3),

  3. padding = 'same' ,activation = 'relu',

  4. kernel_constraint = maxnorm(3)))

  5. model.add(Dropout(0.2))

  6. model.add(Conv2D(32,(3,3),activation = 'relu' ,padding = 'same' ,kernel_constraint = maxnorm(3)))

  7. model.add(MaxPooling2D(pool_size=(2,2)))

  8. model.add(Flatten())

  9. model.add(Dense(512,activation - 'relu' ,kernel_constraint=maxnorm(3)))

  10. model.add(Dropout(0.5))

  11. model.add(Dense(num_classes, activation = 'softmax'))

7. Configure the optimizer and compile the model.

  1. sgd=SGD(lr=0.01,momentum=0.9,decay=(0.01/25),nesterov=Fals)

  2. model.compile(loss='categorical_crossentropy',optimizer=sgd,

  3. metrics=['accuracy'])

8. View the model summary for better understanding of model architecture.

  1. model.summary()

Output:

9.  Train the model.

  1.  model.fit(train_X,train_Y, validation_data=(test_X,test_Y),

  2. epochs=10,batch_size=32)

Output:

10. Calculate the accuracy on testing data.

  1. _,acc=model.evaluate(test_X,test_Y)

  2. print(acc*100)

Output:

0 like 0 dislike
by (151 points)

About CIFAR-10 Dataset:

This dataset consists of 60,000 images divided into 10 target classes, with each category containing 6000 images of shape 32*32. 

The 10 different classes of this dataset are:

  1. Airplane
  2. Car
  3. Bird
  4. Cat
  5. Deer
  6. Dog
  7. Frog
  8. Horse
  9. Ship
  10. Truck

CIFAR-10 dataset is already available in the datasets module of Keras. We do not need to download it; we can directly import it from keras.datasets.

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

0 like 0 dislike
1 answer 666 views

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...