Keras is a popular Python library used for building and training deep learning models. One common challenge in deep learning is accessing suitable datasets for model development. To address this, Keras includes a built-in module using:
keras.datasets
It provides several well-known datasets ready for use. Below are some widely used datasets which suitable for tasks like image classification, sentiment analysis and regression. These datasets are preprocessed and ready to use, making them ideal for training and evaluating deep learning models.
1. MNIST: Handwritten Digit Classification
The MNIST dataset is one of the most widely used benchmarks for image classification tasks. It consists of grayscale images of handwritten digits from 0 to 9. It includes:
- Training Set: 60,000 images
- Test Set: 10,000 images
- Image Size: 28x28 pixels
python
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
Returns:
- x_train, x_test: An unsigned integer(0-255) array of grayscale image data with shape (num_samples, 28, 28).
- y_train, y_test: An unsigned integer(0-255) array of digit labels (integers in range 0-9) with shape (num_samples,).
2. Fashion-MNIST: Classification of Clothing Categories
Fashion-MNIST is a modern alternative to the original MNIST dataset and serves as a drop-in replacement for benchmarking image classification models. It contains grayscale images of various clothing items, making it more challenging and relevant for real-world applications. It has:
- Training Set: 60,000 images
- Test Set: 10,000 images
- Image Size: 28x28 pixels
- Number of Classes: 10 fashion categories
Label | Description |
---|
0 | T-shirt/top |
1 | Trouser |
2 | Pullover |
3 | Dress |
4 | Coat |
5 | Sandal |
6 | Shirt |
7 | Sneaker |
8 | Bag |
9 | Ankle boot |
python
from keras.datasets import fashion_mnist
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
Returns:
- x_train, x_test: An unsigned integer(0-255) array of grayscale image data with shape (num_samples, 28, 28).
- y_train, y_test: An unsigned integer(0-255) array of digit labels (integers in range 0-9) with shape (num_samples,).
3. CIFAR-10
CIFAR-10 is a widely used dataset for benchmarking image classification models. It consists of color images grouped into 10 distinct categories making it suitable for evaluating performance on multi-class classification tasks involving real-world objects.
- Training Set: 50,000 images (32x32 pixels, RGB)
- Test Set: 10,000 images
- Training Batches: 5 batches of 10,000 images each
- Test Batch: 10,000 images, with 1,000 randomly selected from each class
Label | Description |
---|
0 | Airplane |
1 | Automobile |
2 | Bird |
3 | Cat |
4 | Deer |
5 | Dog |
6 | Frog |
7 | Horse |
8 | Ship |
9 | Truck |
The dataset is well-balanced across classes. Each training class contains exactly 5,000 images, although the individual training batches vary slightly in class distribution.
python
from keras.datasets import cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
Returns:
- x_train, x_test: An unsigned integer(0-255) array of RGB image data with shape (num_samples, 3, 32, 32) or (num_samples, 32, 32, 3) based on the image_data_format backend setting of either channels_first or channels_last respectively. The value "3" in the shape refers to the 3 RGB channels.
- y_train, y_test: An unsigned integer(0-255) array of category labels (integers in range 0-9) with shape (num_samples, 1).
4. CIFAR-100: Fine-Grained Image Classification
CIFAR-100 is an advanced version of the CIFAR-10 dataset, designed for more fine-grained image classification tasks. Like CIFAR-10, it contains 32x32 color images but with a total of 100 distinct classes each grouped into broader categories called superclasses.
- Total Classes: 100 fine labels grouped into 20 superclasses (coarse labels)
- Training Set: 50,000 images (500 per class)
- Test Set: 10,000 images (100 per class)
- Image Format: RGB, 32x32 pixels
Each image is annotated with:
- A fine label representing the specific class like “maple tree”
- A coarse label representing the superclass it belongs to like “trees”
python
from keras.datasets import cifar100
(x_train, y_train), (x_test, y_test) = cifar100.load_data(label_mode='fine')
Returns:
- x_train, x_test: Arrays of RGB images with shape (num_samples, 32, 32, 3) for channels_last or (num_samples, 3, 32, 32) for channels_first (based on backend configuration).
- y_train, y_test: Arrays of integer labels ranging from 0 to 99, with shape (num_samples, 1).
Arguments:
- label_mode: "fine" or "coarse".
5. Boston Housing Prices: Regression on Real Estate Data
The Boston Housing dataset is a classic benchmark for regression tasks in machine learning. It was originally sourced from the StatLib library at Carnegie Mellon University and contains information collected in the 1970s about housing of Boston.
- Problem Type: Regression
- Features: 13 numerical attributes (e.g., crime rate, number of rooms, property tax rate)
- Target: Median value of owner-occupied homes (in $1000s)
- Training Set: 404 samples
- Test Set: 102 samples
This dataset is useful for predicting continuous values based on multiple numerical features.
python
from keras.datasets import boston_housing
(x_train, y_train), (x_test, y_test) = boston_housing.load_data()
Returns:
- x_train, x_test: NumPy arrays of shape (num_samples, 13), representing the input features.
- y_train, y_test: NumPy arrays of shape (num_samples,), representing the target house prices.
Arguments:
- seed: Integer used to shuffle the data before splitting into training and test sets.
- test_split: Float value representing the proportion of the dataset to allocate for testing.
6. IMDB Movie Reviews: Sentiment Classification
The IMDB dataset is a well-known benchmark for binary sentiment analysis, where the goal is to classify movie reviews as either positive or negative. It consists of 25,000 preprocessed reviews for training and 25,000 for testing each labeled with sentiment polarity.
- Problem Type: Binary Classification
- Data Format: Reviews are encoded as sequences of word indices where each index corresponds to a word ranked by frequency in the dataset. For example, the word mapped to index
5
is the 5th most common word. - Vocabulary Control: The dataset allows limiting the vocabulary size to include only the top
N
most frequent words, enabling efficient and compact modeling.
python
from keras.datasets import imdb
(x_train, y_train), (x_test, y_test) = imdb.load_data()
Returns:
- x_train, x_test: Lists of sequences, where each sequence is a list of integers (word indices).
- y_train, y_test: Lists of integer labels (1 = positive, 0 = negative).
Arguments:
- num_words: Limit the vocabulary to the top num_words most frequent words. Less frequent words are replaced with oov_char.
- skip_top: Skip the top N most frequent words, often stopwords.
- maxlen: Maximum allowed length for sequences. Longer ones are truncated.
- seed: For reproducible shuffling.
- start_char: Token marking the beginning of a sequence (default is 1).
- oov_char: Token used to replace words removed due to num_words or skip_top limits.
- index_from: Shift word indices by a specified offset (useful when reserving special tokens like padding).
7. Reuters Newswire Topics: Multiclass Text Classification
The Reuters dataset is a classic benchmark for multiclass text classification. It contains 11,228 newswire articles collected by Reuters, each labeled with 46 distinct topics. This dataset is well-suited for evaluating models on text categorization tasks involving multiple classes.
- Problem Type: Multiclass Classification
- Number of Classes: 46 unique news topics
- Data Format: Each article is preprocessed and represented as a sequence of integers where each integer corresponds to a word index based on frequency (similar to the IMDB dataset).
python
from keras.datasets import reuters
(x_train, y_train), (x_test, y_test) = reuters.load_data()
Returns:
x_train
, x_test
: Lists of sequences, where each sequence is a list of word indices (integers).y_train
, y_test
: Lists of integer labels (ranging from 0 to 45), each representing a topic.
Arguments:
- num_words: Limit vocabulary to the top num_words most frequent words.
- skip_top: Skip the top N most frequent words to avoid overly common terms.
- maxlen: Maximum allowed sequence length. Longer sequences will be truncated.
- seed: Controls random shuffling for reproducibility.
- start_char: Token marking the beginning of a sequence (default is 1).
- oov_char: Token used to replace out-of-vocabulary words.
- index_from: Index offset to start actual word indexing (useful when reserving special tokens).
Choosing the Right Dataset
Choosing the right dataset is important when experimenting with different architectures. The keras.datasets offers a variety of datasets suited to different machine learning tasks such as image classification, sentiment analysis and regression. The table below summarizes these datasets and their ideal use cases:
Dataset | Task Type | Domain | Number of Classes | Input Shape |
---|
MNIST | Classification | Image (grayscale) | 10 | (28, 28) |
---|
Fashion-MNIST | Classification | Image (grayscale) | 10 | (28, 28) |
---|
CIFAR-10 | Classification | Image (RGB) | 10 | (32, 32, 3) |
---|
CIFAR-100 | Fine-grained Classification | Image (RGB) | 100 | (32, 32, 3) |
---|
IMDB | Sentiment Analysis (Binary) | Text | 2 | Variable Length |
---|
Reuters | Topic Classification | Text | 46 | Variable Length |
---|
Boston Housing | Regression | Tabular (numeric) | — | (13,) |
---|
The keras.datasets module provides a set of standardized datasets for prototyping and benchmarking in deep learning. By offering preprocessed data across various domains, it helps developers focus on model building rather than data preparation.
Similar Reads
Deep Learning Tutorial Deep Learning is a subset of Artificial Intelligence (AI) that helps machines to learn from large datasets using multi-layered neural networks. It automatically finds patterns and makes predictions and eliminates the need for manual feature extraction. Deep Learning tutorial covers the basics to adv
5 min read
Deep Learning Basics
Introduction to Deep LearningDeep Learning is transforming the way machines understand, learn and interact with complex data. Deep learning mimics neural networks of the human brain, it enables computers to autonomously uncover patterns and make informed decisions from vast amounts of unstructured data. How Deep Learning Works?
7 min read
Artificial intelligence vs Machine Learning vs Deep LearningNowadays many misconceptions are there related to the words machine learning, deep learning, and artificial intelligence (AI), most people think all these things are the same whenever they hear the word AI, they directly relate that word to machine learning or vice versa, well yes, these things are
4 min read
Deep Learning Examples: Practical Applications in Real LifeDeep learning is a branch of artificial intelligence (AI) that uses algorithms inspired by how the human brain works. It helps computers learn from large amounts of data and make smart decisions. Deep learning is behind many technologies we use every day like voice assistants and medical tools.This
3 min read
Challenges in Deep LearningDeep learning, a branch of artificial intelligence, uses neural networks to analyze and learn from large datasets. It powers advancements in image recognition, natural language processing, and autonomous systems. Despite its impressive capabilities, deep learning is not without its challenges. It in
7 min read
Why Deep Learning is ImportantDeep learning has emerged as one of the most transformative technologies of our time, revolutionizing numerous fields from computer vision to natural language processing. Its significance extends far beyond just improving predictive accuracy; it has reshaped entire industries and opened up new possi
5 min read
Neural Networks Basics
What is a Neural Network?Neural networks are machine learning models that mimic the complex functions of the human brain. These models consist of interconnected nodes or neurons that process data, learn patterns and enable tasks such as pattern recognition and decision-making.In this article, we will explore the fundamental
11 min read
Types of Neural NetworksNeural networks are computational models that mimic the way biological neural networks in the human brain process information. They consist of layers of neurons that transform the input data into meaningful outputs through a series of mathematical operations. In this article, we are going to explore
7 min read
Layers in Artificial Neural Networks (ANN)In Artificial Neural Networks (ANNs), data flows from the input layer to the output layer through one or more hidden layers. Each layer consists of neurons that receive input, process it, and pass the output to the next layer. The layers work together to extract features, transform data, and make pr
4 min read
Activation functions in Neural NetworksWhile building a neural network, one key decision is selecting the Activation Function for both the hidden layer and the output layer. It is a mathematical function applied to the output of a neuron. It introduces non-linearity into the model, allowing the network to learn and represent complex patt
8 min read
Feedforward Neural NetworkFeedforward Neural Network (FNN) is a type of artificial neural network in which information flows in a single direction i.e from the input layer through hidden layers to the output layer without loops or feedback. It is mainly used for pattern recognition tasks like image and speech classification.
6 min read
Backpropagation in Neural NetworkBack Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Deep Learning Models
Deep Learning Frameworks
TensorFlow TutorialTensorFlow is an open-source machine-learning framework developed by Google. It is written in Python, making it accessible and easy to understand. It is designed to build and train machine learning (ML) and deep learning models. It is highly scalable for both research and production.It supports CPUs
2 min read
Keras TutorialKeras high-level neural networks APIs that provide easy and efficient design and training of deep learning models. It is built on top of powerful frameworks like TensorFlow, making it both highly flexible and accessible. Keras has a simple and user-friendly interface, making it ideal for both beginn
3 min read
PyTorch TutorialPyTorch is an open-source deep learning framework designed to simplify the process of building neural networks and machine learning models. With its dynamic computation graph, PyTorch allows developers to modify the networkâs behavior in real-time, making it an excellent choice for both beginners an
7 min read
Caffe : Deep Learning FrameworkCaffe (Convolutional Architecture for Fast Feature Embedding) is an open-source deep learning framework developed by the Berkeley Vision and Learning Center (BVLC) to assist developers in creating, training, testing, and deploying deep neural networks. It provides a valuable medium for enhancing com
8 min read
Apache MXNet: The Scalable and Flexible Deep Learning FrameworkIn the ever-evolving landscape of artificial intelligence and deep learning, selecting the right framework for building and deploying models is crucial for performance, scalability, and ease of development. Apache MXNet, an open-source deep learning framework, stands out by offering flexibility, sca
6 min read
Theano in PythonTheano is a Python library that allows us to evaluate mathematical operations including multi-dimensional arrays efficiently. It is mostly used in building Deep Learning Projects. Theano works way faster on the Graphics Processing Unit (GPU) rather than on the CPU. This article will help you to unde
4 min read
Model Evaluation
Deep Learning Projects