import torch


def collate_imagewise(batch):
    """ 
    data: is a list of tuples with (images, labels, targets) 
    returns: tuple of stacked tensors of images and labels
        and a list for targets
    """
    images = []
    labels = []
    annotations = []
    for i in range(len(batch)):
        images += batch[i][0]
        labels += batch[i][1]
        annotations += batch[i][2]
    images = torch.stack(images)
    labels = torch.stack(labels)

    return images, labels, annotations