File tree 1 file changed +19
-1
lines changed 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 8
8
from detectron2 .layers .wrappers import move_device_like , shapes_to_tensor
9
9
10
10
11
+ try :
12
+ try :
13
+ from torch .compiler import is_compiling
14
+
15
+ except Exception :
16
+ # torch.compiler.is_compiling is not available in torch 1.10
17
+ from torch ._dynamo import is_compiling as is_compiling
18
+
19
+ except Exception :
20
+
21
+ def is_compiling () -> bool : # type: ignore[misc]
22
+ return False
23
+
11
24
class ImageList :
12
25
"""
13
26
Structure that holds a list of images (of possibly
@@ -111,7 +124,12 @@ def from_tensors(
111
124
# This seems slightly (2%) faster.
112
125
# TODO: check whether it's faster for multiple images as well
113
126
image_size = image_sizes [0 ]
114
- padding_size = [0 , max_size [- 1 ] - image_size [1 ], 0 , max_size [- 2 ] - image_size [0 ]]
127
+ u0 = max_size [- 1 ] - image_size [1 ]
128
+ u1 = max_size [- 2 ] - image_size [0 ]
129
+ padding_size = [0 , u0 , 0 , u1 ]
130
+ if is_compiling ():
131
+ torch ._check (u0 .item () >= 0 )
132
+ torch ._check (u1 .item () >= 0 )
115
133
batched_imgs = F .pad (tensors [0 ], padding_size , value = pad_value ).unsqueeze_ (0 )
116
134
else :
117
135
# max_size can be a tensor in tracing mode, therefore convert to list
You can’t perform that action at this time.
0 commit comments