human
I am working on the file "Fall2017/.ipynb_checkpoints/DataLoading-checkpoint.ipynb".
The first task is:
This little helper function will call our "unpickling" function to unpickle the data and return the unpicked data back to us.In datasets where there is only images, you can use PIL.Image. Armed with this let's write a dataloader for PyTorch.
DataLoading in PyTorch
Dataloading in PyTorch is a two step process. First, you need define a custom class which is subclassed from a data.Dataset class in torch.utils.data. This class takes in arguments which tell PyTorch about the location of the dataset, any "transforms" that you need to make before the dataset is loading.
First lets import the relevant modules. The data module which contains the useful functions for dataloading is contained in torch.utils.data. We also need a utility called glob to get all our batches in a list. The dataset is split into 5 different parts and we need to have them all together so we can use the entire training set:
Can you write Python code for it?

=====
Give me a the Python code you requested?
assistant
#Here is the Python code you requested.

import torch 
import torch.utils.data as data 
import glob
from PIL import Image
import numpy as np

class CIFARLoader(data.Dataset):
    """
    CIFAR-10 Loader: Loads the CIFAR-10 data according to an index value 
    and returns the data and the labels. 
    
    args:
    root: Root of the data directory.
    
    Optional args:
    transforms: The transforms you wish to apply to the data.
    target_transforms: The transforms you wish to apply to the labels.
    
    """
    def __init__(self, root,transform=None, target_transform=None):
        self.root = root 
        self.transform = transform 
        self.target_transform = target_transform
        patt = os.path.join(self.root, 'data_batch_*') # create the pattern we want to search for.
        self.batches = sorted(glob.glob(patt))
        self.train_data = []
        self.train_labels = [] 
        
        
        for batch in self.batches:
            entry = {} 
            entry = load_data(batch)
            self.train_data.append(entry[b'data'])
            self.train_labels += entry[b'labels']
        #############################################
        # We need to "concatenate" all the different #
        # training samples into one big array. For   #
        # doing that we're going to use a numpy      # 
        # function called "concatenate".             # 
        ##############################################
        self.train_data = np.concatenate(self.train_data) 
        self.train_data = self.train_data.reshape((50000, 3, 32,32))
        self.train_data = self.train_data.transpose((0,2,3,1)) # pay attention to this step!
        
        
    
    def __getitem__(self, index):
        image = self.train_data[index]
        label = self.train_labels[index]
        
        if self.transform is not None:
            image = self.transform(image)
        if self.target_transform is not None:
            label = self.target_transform(label)
        print(image.size())
        return image, label
    
    def __len__(self):
   ...