Skip to content

Commit

Permalink
TF change antialias to true (#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixT2K authored Nov 20, 2023
1 parent e645ead commit 419ea05
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion doctr/models/preprocessor/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def __call__(self, x: Union[tf.Tensor, np.ndarray, List[Union[tf.Tensor, np.ndar
x = tf.image.convert_image_dtype(x, dtype=tf.float32)
# Resizing
if (x.shape[1], x.shape[2]) != self.resize.output_size:
x = tf.image.resize(x, self.resize.output_size, method=self.resize.method)
x = tf.image.resize(
x, self.resize.output_size, method=self.resize.method, antialias=self.resize.antialias
)

batches = [x]

Expand Down
3 changes: 2 additions & 1 deletion doctr/transforms/modules/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(
self.method = method
self.preserve_aspect_ratio = preserve_aspect_ratio
self.symmetric_pad = symmetric_pad
self.antialias = True

if isinstance(self.output_size, int):
self.wanted_size = (self.output_size, self.output_size)
Expand All @@ -106,7 +107,7 @@ def __call__(
) -> Union[tf.Tensor, Tuple[tf.Tensor, np.ndarray]]:
input_dtype = img.dtype

img = tf.image.resize(img, self.wanted_size, self.method, self.preserve_aspect_ratio)
img = tf.image.resize(img, self.wanted_size, self.method, self.preserve_aspect_ratio, self.antialias)
# It will produce an un-padded resized image, with a side shorter than wanted if we preserve aspect ratio
raw_shape = img.shape[:2]
if self.preserve_aspect_ratio:
Expand Down
2 changes: 1 addition & 1 deletion tests/tensorflow/test_models_preprocessor_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def test_preprocessor(batch_size, output_size, input_tensor, expected_batches, e
assert all(isinstance(b, tf.Tensor) for b in out)
assert all(b.dtype == tf.float32 for b in out)
assert all(b.shape[1:3] == output_size for b in out)
assert all(tf.math.reduce_all(b == expected_value) for b in out)
assert all(tf.math.reduce_all(tf.math.abs(b - expected_value) < 1e-6) for b in out)
assert len(repr(processor).split("\n")) == 4
4 changes: 2 additions & 2 deletions tests/tensorflow/test_transforms_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_resize():
input_t = tf.cast(tf.fill([64, 64, 3], 1), dtype=tf.float32)
out = transfo(input_t)

assert tf.reduce_all(out == 1)
assert tf.math.reduce_all(tf.math.abs(out - 1) < 1e-6)
assert out.shape[:2] == output_size
assert repr(transfo) == f"Resize(output_size={output_size}, method='bilinear')"

Expand All @@ -24,7 +24,7 @@ def test_resize():

assert not tf.reduce_all(out == 1)
# Asymetric padding
assert tf.reduce_all(out[-1] == 0) and tf.reduce_all(out[0] == 1)
assert tf.reduce_all(out[-1] == 0) and tf.math.reduce_all(tf.math.abs(out[0] - 1) < 1e-6)
assert out.shape[:2] == output_size

# Symetric padding
Expand Down

0 comments on commit 419ea05

Please sign in to comment.