image_list.py 872 Bytes
Newer Older
1
2
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
eellison's avatar
eellison committed
3
4
from torch.jit.annotations import List, Tuple
from torch import Tensor
5
6


7
@torch.jit.script
8
9
10
11
12
13
14
15
16
class ImageList(object):
    """
    Structure that holds a list of images (of possibly
    varying sizes) as a single tensor.
    This works by padding the images to the same size,
    and storing in a field the original sizes of each image
    """

    def __init__(self, tensors, image_sizes):
eellison's avatar
eellison committed
17
        # type: (Tensor, List[Tuple[int, int]])
18
19
20
21
22
23
24
25
        """
        Arguments:
            tensors (tensor)
            image_sizes (list[tuple[int, int]])
        """
        self.tensors = tensors
        self.image_sizes = image_sizes

eellison's avatar
eellison committed
26
27
28
    def to(self, device):
        # type: (Device) # noqa
        cast_tensor = self.tensors.to(device)
29
        return ImageList(cast_tensor, self.image_sizes)