24
24
from __future__ import print_function
25
25
26
26
import math
27
- import tensorflow . compat . v2 as tf
27
+ import tensorflow as tf
28
28
from typing import Any , Dict , Iterable , List , Optional , Text , Tuple , Union
29
29
30
30
from tensorflow .python .keras .layers .preprocessing import image_preprocessing as image_ops
@@ -75,8 +75,7 @@ def from_4d(image: tf.Tensor, ndims: int) -> tf.Tensor:
75
75
return tf .reshape (image , new_shape )
76
76
77
77
78
- def _convert_translation_to_transform (
79
- translations : Iterable [int ]) -> tf .Tensor :
78
+ def _convert_translation_to_transform (translations ) -> tf .Tensor :
80
79
"""Converts translations to a projective transform.
81
80
82
81
The translation matrix looks like this:
@@ -166,8 +165,7 @@ def _convert_angles_to_transform(
166
165
)
167
166
168
167
169
- def transform (image : tf .Tensor ,
170
- transforms : Iterable [float ]) -> tf .Tensor :
168
+ def transform (image : tf .Tensor , transforms ) -> tf .Tensor :
171
169
"""Prepares input data for `image_ops.transform`."""
172
170
original_ndims = tf .rank (image )
173
171
transforms = tf .convert_to_tensor (transforms , dtype = tf .float32 )
@@ -181,8 +179,7 @@ def transform(image: tf.Tensor,
181
179
return from_4d (image , original_ndims )
182
180
183
181
184
- def translate (image : tf .Tensor ,
185
- translations : Iterable [int ]) -> tf .Tensor :
182
+ def translate (image : tf .Tensor , translations ) -> tf .Tensor :
186
183
"""Translates image(s) by provided vectors.
187
184
188
185
Args:
@@ -577,7 +574,7 @@ def unwrap(image: tf.Tensor, replace: int) -> tf.Tensor:
577
574
return image
578
575
579
576
580
- def _randomly_negate_tensor (tensor : tf . Tensor ) -> tf . Tensor :
577
+ def _randomly_negate_tensor (tensor ) :
581
578
"""With 50% prob turn the tensor negative."""
582
579
should_flip = tf .cast (tf .floor (tf .random .uniform ([]) + 0.5 ), tf .bool )
583
580
final_tensor = tf .cond (should_flip , lambda : tensor , lambda : - tensor )
0 commit comments