text_plain_output_1.png image_output_1.png
import cv2

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import os

import numpy as np
import pandas as pd
import os
import cv2
import matplotlib.pyplot as plt
SIZE = 256
X_test = '../input/test-images'
Y_test = '../input/test-labels'
X_train = '../input/train-images'
Y_train = '../input/train-labels'
X_val = '../input/validation-images'
Y_val = '../input/validation-labels'

def load_dataset():
    xtrainlist, xtestlist, xvallist = ([], [], [])
    for image in os.listdir(X_train):
        path = os.path.join(X_train, image)
        img = cv2.imread(path)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        img = cv2.equalizeHist(img)
        xtrainlist.append(img)
    for image in os.listdir(X_test):
        path = os.path.join(X_test, image)
        img = cv2.imread(path)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        xtestlist.append(img)
    for image in os.listdir(X_val):
        path = os.path.join(X_val, image)
        img = cv2.imread(path)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        xvallist.append(img)
    x_train = np.array(xtrainlist)
    x_test = np.array(xtestlist)
    x_val = np.array(xvallist)
    classes_list = [b'messy', b'clean']
    classes = np.array(classes_list)
    return (x_train, x_test, x_val, classes)
x_train, x_test, x_val, classes = load_dataset()
x_train = np.expand_dims(x_train, axis=3)
x_test = np.expand_dims(x_test, axis=3)
x_val = np.expand_dims(x_val, axis=3)
x_train, x_test, x_val = (x_train / 255.0, x_test / 255.0, x_val / 255.0)

plt.imshow(x_train[300], cmap='gray')