I have created a custom dataloader for the KAIST pedestrian detection dataset. The following is the dataset:
class DataSet(Dataset):
    def __init__(self, csv_path, root_dir):
        self.to_tensor = transforms.ToTensor()
        self.data_info = pd.read_csv(csv_path)
        self.root_dir = root_dir
        self.image_arr = np.asarray(self.data_info.iloc[:, 0])
        self.label_arr = np.asarray(self.data_info.iloc[:, 18])
        self.data_len = len(self.data_info.index)

    def __getitem__(self, index):
        single_image_name = self.image_arr[index]
        img_as_img = Image.open(self.root_dir+single_image_name)
        img_as_tensor = self.to_tensor(img_as_img)
        single_image_label = self.label_arr[index]
        return (img_as_tensor, single_image_label)

    def __len__(self):
        return self.data_len

if __name__ == "__main__":
    # Call dataset
    trainset =  \
        DataSet(csv_path = 'train/images/annotations.csv',
               root_dir = 'train/images/')
    testset = \
        DataSet(csv_path = 'test/images/test_annotations.csv',
               root_dir = 'train/images/')

    trainloader = torch.utils.data.DataLoader(dataset=trainset,
                                                    batch_size=4,
                                                    shuffle=True)
    testloader = torch.utils.data.DataLoader(dataset=trainset,
                                                    batch_size=4,
                                                    shuffle=False)

classes = ('', 'person', 'cyclist','people', 'person?')

To view the image with its associated class I am using the following method:
import matplotlib.pyplot as plt
import numpy as np
import torchvision

# functions to show an image
def imshow(img):
    img = img      # unnormalize
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))
    plt.show()

# get some random training images
dataiter = iter(trainloader)
images, labels = dataiter.next()

# show images
imshow(torchvision.utils.make_grid(images))
# print labels
print(' '.join('%5s' % classes[labels[j]] for j in range(4)))

What I would like to do now is to add bounding boxes on the images for training. The values for the bounding boxes are stored in the csv in the following format:
bb_1,bb_2,bb_3,bb_4
19, 220, 27, 46
66, 210, 27, 49
…
…
…
I have followed a few examples online, but haven’t managed to get it working. Any advice would be greatly appreciated.