# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in 

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

from subprocess import check_output
#print(check_output(["ls", "../input"]).decode("utf8"))

# Any results you write to the current directory are saved as output.
TRAIN_DIR = "../input/train/"
TEST_DIR = "../input/test/"

ROW = 64
COL = 64
CHANNEL = 3

import os, random, cv2
train_image = [TRAIN_DIR+i for i in os.listdir(TRAIN_DIR)]
test_image = [TEST_DIR+i for i in os.listdir(TEST_DIR)]

train_cat = [TRAIN_DIR+i for i in os.listdir(TRAIN_DIR) if 'cat' in i]
train_dog = [TRAIN_DIR+i for i in os.listdir(TRAIN_DIR) if 'dog' in i]

train_images = train_dog[:1000] + train_cat[:1000]
random.shuffle(train_images)
test_images = test_image[:25]

def read_image(file_path):
    img = cv2.imread(file_path, cv2.IMREAD_COLOR)
    return cv2.resize(img, (ROW,COL), interpolation = cv2.INTER_CUBIC)
    
def prep_data(images):
    count = len(images)
    data = np.ndarray((count, CHANNEL, ROW, COL), dtype = np.uint8)
    
    for i, image_file in enumerate(images):
        image = read_image(image_file)
        data[i] = image.T
        #if i%250 == 0: print(i)
    return data

train = prep_data(train_images)
test = prep_data(test_images)

#print("Train shape: {}".format(train.shape))
#print("Test shape: {}".format(test.shape))

labels = []
for i in train_images:
    if 'dog' in i:
        labels.append(1)
    else:
        labels.append(0)

import seaborn as sns
sns.countplot(labels)
sns.plt.title('Cats and Dogs')

































