text_plain_output_4.png application_vnd.jupyter.stderr_output_3.png application_vnd.jupyter.stderr_output_5.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png
from tqdm import tqdm

import cv2

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import os

import os

import warnings

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import cv2
import os
from random import shuffle
from tqdm import tqdm
from PIL import Image
import warnings
warnings.filterwarnings('ignore')
import os

train_cat = '../input/training_set/training_set/cats'
train_dog = '../input/training_set/training_set/dogs'
test_cat = '../input/test_set/test_set/cats'
test_dog = '../input/test_set/test_set/dogs'
image_size = 128

for image in tqdm(os.listdir(train_cat)):
    path = os.path.join(train_cat, image)
    img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
    try:
        img = cv2.resize(img, (image_size, image_size)).flatten()
    except:
        pass
    np_img = np.asarray(img)
for image2 in tqdm(os.listdir(train_dog)):
    path = os.path.join(train_dog, image2)
    img2 = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
    try:
        img2 = cv2.resize(img2, (image_size, image_size)).flatten()
    except:
        pass
    np_img2 = np.asarray(img2)
plt.axis('off')
plt.axis('off')

def train_data():
    train_data_cat = []
    train_data_dog = []
    for image1 in tqdm(os.listdir(train_cat)):
        path = os.path.join(train_cat, image)
        img1 = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
        try:
            img1 = cv2.resize(img1, (image_size, image_size))
        except:
            pass
        train_data_cat.append(img1)
    for image2 in tqdm(os.listdir(train_dog)):
        path = os.path.join(train_dog, image)
        img2 = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
        try:
            img2 = cv2.resize(img2, (image_size, image_size))
        except:
            pass
        train_data_dog.append(img2)
    train_data = np.concatenate((np.asarray(train_data_cat).reshape(4001, -1), np.asarray(train_data_dog).reshape(4001, -1)), axis=1)
    return train_data

def test_data():
    test_data_cat = []
    test_data_dog = []
    for image1 in tqdm(os.listdir(test_cat)):
        path = os.path.join(test_cat, image1)
        img1 = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
        try:
            img1 = cv2.resize(img1, (image_size, image_size))
        except:
            pass
        test_data_cat.append(img1)
    for image2 in tqdm(os.listdir(test_dog)):
        path = os.path.join(test_dog, image2)
        img2 = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
        try:
            img2 = cv2.resize(img2, (image_size, image_size))
        except:
            pass
        test_data_dog.append(img2)
    test_data = np.concatenate((np.asarray(test_data_cat).reshape(1001, -1), np.asarray(test_data_dog).reshape(1001, -1)), axis=1)
    return test_data

train_data = train_data()
test_data = test_data()