(batch)
return tensor, targets
Fast batch collation. Based on version from
       NVIDIA Apex: https://github.com/NVIDIA/apex.
Fast batch collation. Based on version from
       NVIDIA Apex: https://github.com/NVIDIA/apex.
Fast batch collation . Based on version from NVIDIA Apex : https : // github . com / NVIDIA / apex .
def fast_collate(batch):
    """Fast batch collation. Based on version from
       NVIDIA Apex: https://github.com/NVIDIA/apex."""
    imgs = [img[0] for img in batch]
    targets = torch.tensor([target[1] for target in batch], dtype=torch.int64)
    w = imgs[0].size[0]
    h = imgs[0].size[1]
    tensor = torch.zeros((len(imgs), 3, h, w), dtype=torch.uint8)
    for i, img in enumerate(imgs):
        nump_array = np.asarray(img, dtype=np.uint8)
        if (nump_array.ndim < 3):
            nump_array = np.expand_dims(nump_array, axis=-1)
        nump_array = np.rollaxis(nump_array, 2)
        tensor[i] += torch.from_numpy(nump_array)
    return tensor, targets
def fast_collate ( batch ) : imgs = [ img [ 0 ] for img in batch ] targets = torch . tensor ( [ target [ 1 ] for target in batch ] , dtype = torch . int64 ) w = imgs [ 0 ] . size [ 0 ] h = imgs [ 0 ] . size [ 1 ] tensor = torch . zeros ( ( len ( imgs ) , 3 , h , w ) , dtype = torch . uint8 ) for i , img in enumerate ( imgs ) : nump_array = np . asarray ( img , dtype = np . uint8 ) if ( nump_array . ndim < 3 ) : nump_array = np . expand_dims ( nump_array , axis = - 1 ) nump_array = np . rollaxis ( nump_array , 2 ) tensor [ i ] += torch . from_numpy ( nump_array ) return tensor , targets