Hi. i’m a novice in pytorch.
I really want to train cat&dog images with CNN
But it isn’t do well…
I think, my image loading mothod is not good.
def imlist(fpath):
    flist = os.listdir(fpath)
    return flist

def traindata(impath,flist):
    train = []
    length = len(flist)
    for i in range(length):
        path = impath + flist[i]
        im = pilimg.open(path)
        im = im.resize((32,32))
        im = np.array(im)
        im = np.reshape(im,(1,3,32,32))
        im = torch.FloatTensor(im)
        if 'dog' in flist[i]:
            train.append((im,torch.LongTensor([1])))
        if 'cat' in flist[i]:
            train.append((im,torch.LongTensor([0])))
    return train

fpath is a folder path which has train images and function imlist return a list which has file name of train image.


How can I load images???


and How can I resize images to use cnn ??


Does torch cnn use image format [batch size, channel size, img size, img size]?


help me ! .
Thank you.