image_list.py 887 Bytes
Newer Older
1
2
3
4
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
from __future__ import division

import torch
eellison's avatar
eellison committed
5
6
from torch.jit.annotations import List, Tuple
from torch import Tensor
7
8
9
10
11
12
13
14
15
16
17


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
18
        # type: (Tensor, List[Tuple[int, int]])
19
20
21
22
23
24
25
26
        """
        Arguments:
            tensors (tensor)
            image_sizes (list[tuple[int, int]])
        """
        self.tensors = tensors
        self.image_sizes = image_sizes

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