def get_catsdogs_loader(imgs_dir):
    classes = ['cat', 'dog']
    (class_to_idx, idx_to_class) = meta.get_key_int_maps(classes)

    def get_targs_from_fpaths(fpaths):
        targs = []
        for fpath in fpaths:
            classname = fpath.split('/')[(- 1)].split('.')[0]
            targs.append(class_to_idx[classname])
        return targs
    normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    trainTransform = transforms.Compose([transforms.RandomSizedCrop(224), transforms.RandomHorizontalFlip(), transforms.ToTensor(), normalize])
    testTransform = transforms.Compose([transforms.Scale(256), transforms.CenterCrop(224), transforms.ToTensor(), normalize])
    fpaths = glob.glob((imgs_dir + '*.jpg'))
    random.shuffle(fpaths)
    trn_fpaths = fpaths[:20000]
    val_fpaths = fpaths[20000:]
    trn_targs = get_targs_from_fpaths(trn_fpaths)
    val_targs = get_targs_from_fpaths(val_fpaths)
    img_reader = 'pil'
    trn_dataset = FileDataset(trn_fpaths, img_reader, trn_targs, trainTransform)
    val_dataset = FileDataset(val_fpaths, img_reader, val_targs, testTransform)
    trn_loader = torch.utils.data.DataLoader(trn_dataset, batch_size=64, shuffle=True, num_workers=4)
    val_loader = torch.utils.data.DataLoader(val_dataset, batch_size=64, shuffle=False, num_workers=2)
    return (trn_loader, val_loader, classes)
def get_catsdogs_loader(imgs_dir):
    classes = ['cat', 'dog']
    (class_to_idx, idx_to_class) = meta.get_key_int_maps(classes)

    def get_targs_from_fpaths(fpaths):
        targs = []
        for fpath in fpaths:
            classname = fpath.split('/')[(- 1)].split('.')[0]
            targs.append(class_to_idx[classname])
        return targs
    normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    trainTransform = transforms.Compose([transforms.RandomSizedCrop(224), transforms.RandomHorizontalFlip(), transforms.ToTensor(), normalize])
    testTransform = transforms.Compose([transforms.Scale(256), transforms.CenterCrop(224), transforms.ToTensor(), normalize])
    fpaths = glob.glob((imgs_dir + '*.jpg'))
    random.shuffle(fpaths)
    trn_fpaths = fpaths[:20000]
    val_fpaths = fpaths[20000:]
    trn_targs = get_targs_from_fpaths(trn_fpaths)
    val_targs = get_targs_from_fpaths(val_fpaths)
    img_reader = 'pil'
    trn_dataset = FileDataset(trn_fpaths, img_reader, trn_targs, trainTransform)
    val_dataset = FileDataset(val_fpaths, img_reader, val_targs, testTransform)
    trn_loader = torch.utils.data.DataLoader(trn_dataset, batch_size=64, shuffle=True, num_workers=4)
    val_loader = torch.utils.data.DataLoader(val_dataset, batch_size=64, shuffle=False, num_workers=2)
    return (trn_loader, val_loader, classes)