Code Monkey home page Code Monkey logo

fashion-mnist-tensorflow's Introduction

Experimentation of CNN with Fashion MNIST Dataset

Prequisites

  • Tensorflow 1.12
  • Keras
  • Python 3.x

Dataset

Fashion-MNIST is dataset of Zalando's article images—consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. Zalando intends Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits.

How to Use

  1. Open this repository notebook
  2. Run each step by pressing "play" button or CTRL + ENTER
  3. Change the parameters in "Parameters Section"

Run the Models

  1. Go to section running models
  2. Select model that want to evaluate
  3. Run evaluate

Training Steps

Importing required modules

import tensorflow as tf
from tensorflow import keras
from sklearn.model_selection import StratifiedShuffleSplit
from keras import backend as k

import numpy as np
import matplotlib.pyplot as plt

Load Datasets

(imageTrain, labelTrain), (imageTest, labelTest) = tf.keras.datasets.fashion_mnist.load_data()

Make array of labels and split training data into validation data

labels = {0 : "T-shirt/top", 1: "Trouser", 2: "Pullover", 3: "Dress", 4: "Coat", 5: "Sandal", 6: "Shirt", 7: "Sneaker", 8: "Bag", 9: "Ankle Boot"}

imageTrain = np.expand_dims(imageTrain, -1)
imageTest = np.expand_dims(imageTest, -1)

sss = StratifiedShuffleSplit(n_splits=5, random_state=0, test_size=1/6)
trainIndex, validIndex = next(sss.split(imageTrain, labelTrain))
imageValid, labelValid = imageTrain[validIndex], labelTrain[validIndex]
imageTrain, labelTrain = imageTrain[trainIndex], labelTrain[trainIndex]

Perform Mean Subtraction and Normalization of Datasets (a)

  • Scaling down range of input value into between 0 and 1 instead of 0 - 255
imageTrain = imageTrain / 255
imageValid = imageValid / 255
imageTest = imageTest / 255
  • Mean Substraction of data
meanSubt = np.mean(imageTrain)

imageTrain = imageTrain - meanSubt
imageValid = imageValid - meanSubt
imageTest = imageTest - meanSubt
  • Normalization
stdDev = np.std(imageTrain)

imageTrain = imageTrain / stdDev
imageValid = imageValid / stdDev
imageTest = imageTest / stdDev

Mean subtraction and normalization using image training data to make sure it's same across all datasets that we use. This process necessary because we want to make our data sparse before we train.

Choosing Initializer (b)

We experiment with two weight initialization: He initialization and Xavier Initialization

We can see the result in below table:

Xavier Initializer He Initializer
Accuracy 0.9663 0.9675
Loss 0.0891 0.0863
Validation Accuracy 0.9194 0.9184
Validation Loss 0.284 0.2929
Test Accuracy 0.9138 0.9159
Test Loss 0.3143 0.3164

Experimentation with network configuration (c)

32 Filter + 2 Layers 64 Filter + 2 Layers
Accuracy 0.9663 0.9675
Loss 0.0891 0.0863
Validation Accuracy 0.9194 0.9184
Validation Loss 0.284 0.2929
Test Accuracy 0.9138 0.9159
Test Loss 0.3143 0.3164

Experimentation with gradient optimization techniques (d)

Experimentation with activation functions (e)

Experimentation with regularization techniques (f)

fashion-mnist-tensorflow's People

Contributors

ivokun avatar

Watchers

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