In [2]:
import cv2
import os
import numpy as np
%matplotlib inline
from matplotlib import pyplot as plt

In [11]:
xs=[]
ys=[]

#dog
for f in os.listdir("dog"):
    if f.endswith(".jpg"):
        img=cv2.imread(os.path.join("dog", f),0)
        h,w = img.shape
        # cropping
        if w<h:
            margin=(h-w)//2
            croped=img[ margin:-margin, :]
        else:
            margin=(w-h)//2
            croped=img[ :, margin:-margin]
        #resizing
        resized=cv2.resize(croped, (28,28))
        x=np.reshape(resized, newshape=(784))
        xs.append(x)
        ys.append([0,1])
#cat

batch=[ np.array(xs,dtype=float)/255.0, np.array(ys,dtype=float)]

In [12]:
batch


Out[12]:
[array([[ 0.69803922,  0.70980392,  0.74117647, ...,  0.34509804,
          0.4627451 ,  0.4       ],
        [ 0.91764706,  0.88627451,  0.85098039, ...,  0.2       ,
          0.13333333,  0.18431373],
        [ 0.05098039,  0.00784314,  0.00784314, ...,  0.09803922,
          0.00784314,  0.22745098],
        ..., 
        [ 0.49803922,  0.42745098,  0.46666667, ...,  0.41176471,
          0.38039216,  0.41960784],
        [ 0.14901961,  0.59215686,  0.59607843, ...,  0.70196078,
          0.70588235,  0.70196078],
        [ 0.56470588,  0.88627451,  0.73333333, ...,  0.69019608,
          0.81568627,  0.49803922]]), array([[ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.],
        [ 0.,  1.]])]

In [ ]: