In this article, you will learn how to load and create image train and test dataset from custom data as an input for Deep learning models. You will learn to load the dataset using.

  • Open CV2
  • PIL

The dataset used here is Intel Image Classification from Kaggle.

Intel Image classification dataset is already split into train, test, and Val, and we will only use the training dataset to learn how to load the dataset using different libraries.

Typical steps for loading custom dataset for Deep Learning Models

  1. Open the image file. The format of the file can be JPEG, PNG, BMP, etc.
  2. Resize the image to match the input size for the Input layer of the Deep Learning model.
  3. Convert the image pixels to float datatype.
  4. Normalize the image to have pixel values scaled down between 0 and 1 from 0 to 255.
  5. Image data for Deep Learning models should be either a numpy array or a tensor object.

The folder structure of the custom image data

Image for post

Each class is a folder containing images for that particular class.

Loading image data using CV2

Importing required libraries

import pandas as pd
import numpy as np
import os
import tensorflow as tf
import cv2
from tensorflow import keras
from tensorflow.keras import layers, Dense, Input, InputLayer, Flatten
from tensorflow.keras.models import Sequential, Model
from  matplotlib import pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline

#deep-learning #machine-learning #image-processing #python #opencv

Loading Custom Image Dataset for Deep Learning Models: Part 1
16.95 GEEK