|
1 | 1 | # Copyright (c) Facebook, Inc. and its affiliates.
|
2 | 2 | from __future__ import division
|
3 |
| -from typing import Any, Dict, List, Optional, Tuple |
4 | 3 | import torch
|
5 | 4 | from torch import device
|
6 | 5 | from torch.nn import functional as F
|
7 | 6 |
|
8 | 7 | from detectron2.layers.wrappers import move_device_like, shapes_to_tensor
|
| 8 | +from detectron2.structures.torch_version_utils import torch_version_at_least |
| 9 | + |
| 10 | +from typing import Any, Dict, List, Optional, Tuple |
9 | 11 |
|
10 | 12 |
|
11 | 13 | class ImageList:
|
@@ -111,7 +113,12 @@ def from_tensors(
|
111 | 113 | # This seems slightly (2%) faster.
|
112 | 114 | # TODO: check whether it's faster for multiple images as well
|
113 | 115 | image_size = image_sizes[0]
|
114 |
| - padding_size = [0, max_size[-1] - image_size[1], 0, max_size[-2] - image_size[0]] |
| 116 | + u0 = max_size[-1] - image_size[1] |
| 117 | + u1 = max_size[-2] - image_size[0] |
| 118 | + padding_size = [0, u0, 0, u1] |
| 119 | + if torch_version_at_least("2.6.0") and torch.compiler.is_compiling(): |
| 120 | + torch._check(u0.item() >= 0) |
| 121 | + torch._check(u1.item() >= 0) |
115 | 122 | batched_imgs = F.pad(tensors[0], padding_size, value=pad_value).unsqueeze_(0)
|
116 | 123 | else:
|
117 | 124 | # max_size can be a tensor in tracing mode, therefore convert to list
|
|
0 commit comments