Skip to content
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS
Close
Beyond Knowledge Innovation

Beyond Knowledge Innovation

Where Data Unveils Possibilities

  • Home
  • AI & ML Insights
  • Machine Learning
    • Supervised Learning
      • Introduction
      • Regression
      • Classification
    • Unsupervised Learning
      • Introduction
      • Clustering
      • Association
      • Dimensionality Reduction
    • Reinforcement Learning
    • Generative AI
  • Knowledge Base
    • Introduction To Python
    • Introduction To Data
    • Introduction to EDA
  • References
HomeImplementationNeural NetworksBuilding a CNN model for Fashion MNIST dataset
Neural Networks

Building a CNN model for Fashion MNIST dataset

June 2, 2024June 2, 2024CEO 458 views
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D

import random
random.seed(1)
np.random.seed(1)
tf.random.set_seed(1)

(X_train, y_train), (X_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()

# checking unique labels
np.unique(y_train)

# reshaping to one channel color
X_train = X_train.reshape(X_train.shape[0], 28, 28, 1)
X_test = X_test.reshape(X_test.shape[0], 28, 28, 1)

# normalizing 
X_train_normalized = X_train.astype('float32')/255.0
X_test_normalized = X_test.astype('float32')/255.0

#encoding label classes
y_train_encoded = tf.keras.utils.to_categorical(y_train)
y_test_encoded = tf.keras.utils.to_categorical(y_test)

#building CNN model
model = Sequential(
    [
        Conv2D(64, kernel_size=(3,3), input_shape=(28, 28, 1), activation='relu', padding='same'),
        MaxPooling2D(pool_size=(2, 2), padding='same'),
        Flatten(),
        Dense(100, activation='relu'),
        Dense(10, activation='softmax')
    ]
)

# checking trainable parameters
model.summary()

#compiling model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# fitting with 5 epochs
model.fit(X_train_normalized, y_train_encoded, epochs=5)

# checking training set accuracy
model.evaluate(X_train_normalized, y_train_encoded)

# checking test set accuracy
model.evaluate(X_test_normalized, y_test_encoded)
cnn, convolutional, deep learning, mnist, multi-class

Post navigation

Previous Post
Previous post: Keras library wrapper classes 
Next Post
Next post: Delete a folder in Google Colab

You Might Also Like

No image
What is Deep Learning
May 9, 2024 Comments Off on What is Deep Learning
No image
MNIST dataset in artificial neural network
May 5, 2024 Comments Off on MNIST dataset in artificial neural network
  • Recent
  • Popular
  • Random
  • No image
    2 years ago Low-Rank Factorization
  • No image
    2 years ago Perturbation Test for a Regression Model
  • No image
    2 years ago Calibration Curve for Classification Models
  • No image
    March 15, 20240Single linkage hierarchical clustering
  • No image
    April 17, 20240XGBoost (eXtreme Gradient Boosting)
  • No image
    April 17, 20240Gradient Boosting
  • No image
    June 20, 2024Delete a folder in Google Colab
  • No image
    March 11, 2024What is Jaccard Distance
  • No image
    March 8, 2024Post-pruning Decision Tree with Cost Complexity Parameter…
  • Implementation (55)
    • EDA (4)
    • Neural Networks (10)
    • Supervised Learning (26)
      • Classification (17)
      • Linear Regression (8)
    • Unsupervised Learning (11)
      • Clustering (8)
      • Dimensionality Reduction (3)
  • Knowledge Base (44)
    • Python (27)
    • Statistics (6)
May 2026
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031
« Oct    

We are on

FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS

Subscribe

© 2026 Beyond Knowledge Innovation
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS