"git@developer.sourcefind.cn:zhaoyu6/sglang.git" did not exist on "4c584fc6324b7326cf5fbe4ad248277bdf1c05e3"
image_list.py 905 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
@torch.jit.script
10
11
12
13
14
15
16
17
18
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
19
        # type: (Tensor, List[Tuple[int, int]])
20
21
22
23
24
25
26
27
        """
        Arguments:
            tensors (tensor)
            image_sizes (list[tuple[int, int]])
        """
        self.tensors = tensors
        self.image_sizes = image_sizes

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