Coder Social home page Coder Social logo

haluksumen / image_classification_intel Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 5.36 MB

Categorical Image Classification using Tensorflow/Keras on Intel Image Dataset

Jupyter Notebook 100.00%
image-classification convolutional-neural-networks tensorflow keras deep-learning exploratory-data-analysis data-visualization cnn-classification callbacks inception-resnet-v2

image_classification_intel's Introduction

Intel_Image_Classification

Exploratory Data Analysis + Data Visualization + Deep Learning Modelling

1 - Abstract

In this project I made Exploratory Data Analysis, Data Visualisation and lastly Modelling. Intel Image Dataset contains 25 images in 3 different sets. Each example is 150x150 image and associated with 6 labels(targets). After examining the dataset I used ImageDataGenerator for example rescaling images and increasing the artifical training and test datasets. In modelling part, with a InceptionResNetV2 and several other layers implemented. Model trained with 10 Epochs for training the data. Also for long epochs time I implemented callback for time saving. Overally, model gives 0.9023 accuracy. Furthermore with hyperparameter tuning model can give higher accuracy or using GPU for training it will reduce time and number of epochs can be increased.

2 - Data

Intel Image Dataset contains 25,000 examples,train set of 14,000 test set of 3,000 examples and validation set of 7,000 . Each example is a 150x150 image, associated with a label from 6 labels.

Each training and test example is assigned to one of the following labels:

  • 0 Buildings
  • 1 Forest
  • 2 Glacier
  • 3 Mountain
  • 4 Sea
  • 5 Street

Train Dataset Example

Test Dataset Example

3 - Exploratory Data Analysis

Firstly, I checked data, which came three different dataset which are train, test and validation. Later I checked distribution of labels in datasets moreover I see all the classes(labels) equally distributed. So luckily I dont need to do Oversampling or Undersampling.

Number of images in Train Directory:

  • Buildings: 2191
  • Street: 2382
  • Mountain: 2512
  • Glacier: 2404
  • Sea: 2274
  • Forest: 2271

4 - Data Preprocessing

For preparing datasets to the model I used ImageDataGenerator for rescaling which is 1/255.0. Also I defined batch size 128, and for creating artifical images I used rotating that takes maximum 60 degree rotation. In the below code every parameters are visible with explanation.

train_datagen = ImageDataGenerator(
        rescale=1/255.0,            #multiply the data by the value provided
        featurewise_center=True,    #create generator that centers pixel values
        rotation_range=60,          #maximum 60 degree random rotation
        width_shift_range=0.2,      #fraction of total width, if < 1, or pixels if >= 1.
        height_shift_range=0.2,     #fraction of total height, if < 1, or pixels if >= 1.
        shear_range=0.2,            #image disortion in axis
        fill_mode='nearest')        #fill the color with nearest neighborhood for example, aaaaaaaa|abcd|dddddddd

train_generator = train_datagen.flow_from_directory(
        train_path,
        shuffle=True,              #shuffling the order of the image that is being yielded
        target_size=(150,150),     #size of image
        batch_size=128,            #size of the batches of data 
        class_mode='categorical'   #predicting more than two classes so we will use categorical
    )

5 - Modelling

I used pretrained InceptionResNetV2 model. The InceptionResNetV2 model is already trained more than 1 million images. Then I added these parameters over the pre-trained model.

x = tf.keras.layers.Dropout(0.2)(last_output)
x = tf.keras.layers.Dense(units=128, activation='relu')(x)
x = tf.keras.layers.Dropout(0.2)(x)
x = tf.keras.layers.Dense(units=128, activation='relu')(x)
x = tf.keras.layers.Dropout(0.2)(x)
x = tf.keras.layers.Dense(units=6, activation='softmax')(x)

Finally I am compiling model according these parameters, I used RMSprop class and I gave learning rate 0.0002 and momentum 0.9( A scalar or a scalar Tensor).

model.compile(
        optimizer = tf.keras.optimizers.RMSprop(learning_rate=0.0002, momentum=0.9, centered=True), 
        loss = ['categorical_crossentropy'], 
        metrics = ['accuracy']
    )

Additionally, because of higher epochs time I decided to implement Early Stopping class, which is stopping training when it doesnt improve anymore or extremly low.

    tf.keras.callbacks.EarlyStopping(
        monitor='val_loss',          #which quantity will monitor
        min_delta=0.001,             #minimum change in the monitored quantity to qualify as an improvement
        patience=5,                  #number of epochs with no improvement after which training will be stopped
        verbose=1,                   #verbosity mode
        mode='auto',                 #the direction is automatically inferred from the name of the monitored quantity.
        baseline=None,               #baseline value for the monitored quantity
        restore_best_weights=True)]  #whether to restore model weights from the epoch with the best value of the monitored quantity

6 - Result & Future Work

As a result, my model gives overally good results which is the result of InceptionResNetV2 model.

Accuracy of the Model

Loss of the Model

Test Loss is 0.2682

Test Accuracy is 0.9023

For higher accuracy hyperparameter tuning can be implemented or using GPU for training it will reduce training time and with this time saving epochs number can be increased.

image_classification_intel's People

Contributors

haluksumen avatar

Stargazers

 avatar  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.