Skip to content

Commit 3c32778

Browse files
committed
Resize input image only for special batch inference case.
1 parent e7906df commit 3c32778

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

efficientdet/model_inspect.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ def saved_model_inference(self, image_path_pattern, output_dir, **kwargs):
169169
for i in range(num_batches):
170170
batch_files = all_files[i * batch_size: (i + 1) * batch_size]
171171
height, width = self.model_config.image_size
172-
raw_images = [np.array(Image.open(f).resize((width, height)))
173-
for f in batch_files]
172+
images = [Image.open(f) for f in batch_files]
173+
if len(set([m.size for m in images])) > 1:
174+
# Resize only if images in the same batch have different sizes.
175+
images = [m.resize(height, width) for f in images]
176+
raw_images = [np.array(m) for m in images]
174177
size_before_pad = len(raw_images)
175178
if size_before_pad < batch_size:
176179
padding_size = batch_size - size_before_pad

0 commit comments

Comments
 (0)