Skip to content

Commit edb2fa6

Browse files
committed
CLN: use code_format.sh to format all files
1 parent 1bd2ba6 commit edb2fa6

28 files changed

+240
-277
lines changed

tensorflow_addons/custom_ops/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ py_library(
77
srcs = ["__init__.py"],
88
srcs_version = "PY2AND3",
99
deps = [
10-
"//tensorflow_addons/custom_ops/image:images_ops_py",
11-
"//tensorflow_addons/custom_ops/text:text_py",
12-
]
10+
"//tensorflow_addons/custom_ops/image:images_ops_py",
11+
"//tensorflow_addons/custom_ops/text:text_py",
12+
],
1313
)

tensorflow_addons/custom_ops/image/BUILD

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ licenses(["notice"]) # Apache 2.0
22

33
package(default_visibility = ["//visibility:public"])
44

5-
65
cc_binary(
76
name = "python/_image_ops.so",
87
srcs = [
98
"cc/kernels/image_projective_transform_op.cc",
109
"cc/kernels/image_projective_transform_op.h",
1110
"cc/ops/image_ops.cc",
1211
],
12+
copts = [
13+
"-pthread",
14+
"-std=c++11",
15+
"-D_GLIBCXX_USE_CXX11_ABI=0",
16+
],
1317
linkshared = 1,
1418
deps = [
1519
"@local_config_tf//:libtensorflow_framework",
1620
"@local_config_tf//:tf_header_lib",
1721
],
18-
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0"]
1922
)
2023

21-
2224
py_library(
2325
name = "images_ops_py",
2426
srcs = ([
@@ -27,23 +29,21 @@ py_library(
2729
"python/transform.py",
2830
]),
2931
data = [
30-
":python/_image_ops.so"
32+
":python/_image_ops.so",
3133
],
3234
srcs_version = "PY2AND3",
3335
)
3436

35-
3637
# TODO: use cuda_py_test later.
3738
py_test(
3839
name = "transform_ops_test",
3940
size = "small",
4041
srcs = [
41-
"python/transform_test.py"
42+
"python/transform_test.py",
4243
],
4344
main = "python/transform_test.py",
45+
srcs_version = "PY2AND3",
4446
deps = [
4547
":images_ops_py",
4648
],
47-
srcs_version = "PY2AND3",
4849
)
49-

tensorflow_addons/custom_ops/image/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
"""Image manipulation ops"""
15+
"""Image manipulation ops."""
1616
from __future__ import absolute_import
1717
from __future__ import division
1818
from __future__ import print_function

tensorflow_addons/custom_ops/image/cc/kernels/image_projective_transform_op.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ limitations under the License.
1919
#define EIGEN_USE_GPU
2020
#endif // GOOGLE_CUDA
2121

22+
#include "tensorflow_addons/custom_ops/image/cc/kernels/image_projective_transform_op.h"
2223
#include "tensorflow/core/framework/op_kernel.h"
2324
#include "tensorflow/core/framework/register_types.h"
2425
#include "tensorflow/core/framework/types.h"
2526
#include "tensorflow/core/platform/types.h"
26-
#include "tensorflow_addons/custom_ops/image/cc/kernels/image_projective_transform_op.h"
2727

2828
namespace tensorflow {
2929

@@ -73,12 +73,11 @@ class ImageProjectiveTransform : public OpKernel {
7373
const Tensor& transform_t = ctx->input(1);
7474
OP_REQUIRES(ctx, images_t.shape().dims() == 4,
7575
errors::InvalidArgument("Input images must have rank 4"));
76-
OP_REQUIRES(ctx,
77-
(TensorShapeUtils::IsMatrix(transform_t.shape()) &&
78-
(transform_t.dim_size(0) == images_t.dim_size(0) ||
79-
transform_t.dim_size(0) == 1) &&
80-
transform_t.dim_size(1) ==
81-
ProjectiveGenerator<Device, T>::kNumParameters),
76+
OP_REQUIRES(ctx, (TensorShapeUtils::IsMatrix(transform_t.shape()) &&
77+
(transform_t.dim_size(0) == images_t.dim_size(0) ||
78+
transform_t.dim_size(0) == 1) &&
79+
transform_t.dim_size(1) ==
80+
ProjectiveGenerator<Device, T>::kNumParameters),
8281
errors::InvalidArgument(
8382
"Input transform should be num_images x 8 or 1 x 8"));
8483

@@ -106,9 +105,8 @@ class ImageProjectiveTransform : public OpKernel {
106105

107106
Tensor* output_t;
108107
OP_REQUIRES_OK(ctx, ctx->allocate_output(
109-
0,
110-
TensorShape({images_t.dim_size(0), out_height,
111-
out_width, images_t.dim_size(3)}),
108+
0, TensorShape({images_t.dim_size(0), out_height,
109+
out_width, images_t.dim_size(3)}),
112110
&output_t));
113111
auto output = output_t->tensor<T, 4>();
114112
auto images = images_t.tensor<T, 4>();

tensorflow_addons/custom_ops/image/cc/kernels/image_projective_transform_op.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class ProjectiveGenerator {
4545
static const int kNumParameters = 8;
4646

4747
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
48-
ProjectiveGenerator(typename TTypes<T, 4>::ConstTensor input,
49-
typename TTypes<float>::ConstMatrix transforms,
50-
const Interpolation interpolation)
48+
ProjectiveGenerator(typename TTypes<T, 4>::ConstTensor input,
49+
typename TTypes<float>::ConstMatrix transforms,
50+
const Interpolation interpolation)
5151
: input_(input), transforms_(transforms), interpolation_(interpolation) {}
5252

5353
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T

tensorflow_addons/custom_ops/image/cc/kernels/image_projective_transform_op_gpu.cu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ limitations under the License.
1717

1818
#define EIGEN_USE_GPU
1919

20+
#include "tensorflow_addons/custom_ops/image/cc/kernels/image_projective_transform_op.h"
2021
#include "tensorflow/core/framework/register_types.h"
2122
#include "tensorflow/core/framework/types.h"
2223
#include "tensorflow/core/platform/types.h"
23-
#include "tensorflow_addons/custom_ops/image/cc/kernels/image_projective_transform_op.h"
2424

2525
namespace tensorflow {
2626

tensorflow_addons/custom_ops/image/python/transform.py

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
_image_ops_so = tf.load_op_library(
2626
resource_loader.get_path_to_datafile("_image_ops.so"))
2727

28-
_IMAGE_DTYPES = set([tf.dtypes.uint8, tf.dtypes.int32, tf.dtypes.int64,
29-
tf.dtypes.float16, tf.dtypes.float32, tf.dtypes.float64])
28+
_IMAGE_DTYPES = set([
29+
tf.dtypes.uint8, tf.dtypes.int32, tf.dtypes.int64, tf.dtypes.float16,
30+
tf.dtypes.float32, tf.dtypes.float64
31+
])
3032

3133
ops.RegisterShape("ImageProjectiveTransform")(common_shapes.call_cpp_shape_fn)
3234

@@ -66,13 +68,11 @@ def transform(images,
6668
Raises:
6769
TypeError: If `image` is an invalid type.
6870
ValueError: If output shape is not 1-D int32 Tensor.
69-
7071
"""
7172
with ops.name_scope(name, "transform"):
7273
image_or_images = ops.convert_to_tensor(images, name="images")
73-
transform_or_transforms = ops.convert_to_tensor(transforms,
74-
name="transforms",
75-
dtype=tf.dtypes.float32)
74+
transform_or_transforms = ops.convert_to_tensor(
75+
transforms, name="transforms", dtype=tf.dtypes.float32)
7676
if image_or_images.dtype.base_dtype not in _IMAGE_DTYPES:
7777
raise TypeError("Invalid dtype %s." % image_or_images.dtype)
7878
elif image_or_images.get_shape().ndims is None:
@@ -89,9 +89,8 @@ def transform(images,
8989
if output_shape is None:
9090
output_shape = tf.shape(images)[1:3]
9191

92-
output_shape = ops.convert_to_tensor(output_shape,
93-
tf.dtypes.int32,
94-
name="output_shape")
92+
output_shape = ops.convert_to_tensor(
93+
output_shape, tf.dtypes.int32, name="output_shape")
9594

9695
if not output_shape.get_shape().is_compatible_with([2]):
9796
raise ValueError(
@@ -134,15 +133,13 @@ def compose_transforms(*transforms):
134133
A composed transform tensor. When passed to `transform` op,
135134
equivalent to applying each of the given transforms to the image in
136135
order.
137-
138136
"""
139137
assert transforms, "transforms cannot be empty"
140138
with ops.name_scope("compose_transforms"):
141139
composed = flat_transforms_to_matrices(transforms[0])
142140
for tr in transforms[1:]:
143141
# Multiply batches of matrices.
144-
composed = tf.matmul(composed,
145-
flat_transforms_to_matrices(tr))
142+
composed = tf.matmul(composed, flat_transforms_to_matrices(tr))
146143
return matrices_to_flat_transforms(composed)
147144

148145

@@ -163,22 +160,18 @@ def flat_transforms_to_matrices(transforms):
163160
164161
Raises:
165162
ValueError: If `transforms` have an invalid shape.
166-
167163
"""
168164
with ops.name_scope("flat_transforms_to_matrices"):
169165
transforms = ops.convert_to_tensor(transforms, name="transforms")
170166
if transforms.shape.ndims not in (1, 2):
171-
raise ValueError("Transforms should be 1D or 2D, got: %s" %
172-
transforms)
167+
raise ValueError(
168+
"Transforms should be 1D or 2D, got: %s" % transforms)
173169
# Make the transform(s) 2D in case the input is a single transform.
174-
transforms = tf.reshape(transforms,
175-
tf.constant([-1, 8]))
170+
transforms = tf.reshape(transforms, tf.constant([-1, 8]))
176171
num_transforms = tf.shape(transforms)[0]
177172
# Add a column of ones for the implicit last entry in the matrix.
178173
return tf.reshape(
179-
tf.concat(
180-
[transforms, tf.ones([num_transforms, 1])],
181-
axis=1),
174+
tf.concat([transforms, tf.ones([num_transforms, 1])], axis=1),
182175
tf.constant([-1, 3, 3]))
183176

184177

@@ -200,17 +193,15 @@ def matrices_to_flat_transforms(transform_matrices):
200193
201194
Raises:
202195
ValueError: If `transform_matrices` have an invalid shape.
203-
204196
"""
205197
with ops.name_scope("matrices_to_flat_transforms"):
206-
transform_matrices = ops.convert_to_tensor(transform_matrices,
207-
name="transform_matrices")
198+
transform_matrices = ops.convert_to_tensor(
199+
transform_matrices, name="transform_matrices")
208200
if transform_matrices.shape.ndims not in (2, 3):
209-
raise ValueError("Matrices should be 2D or 3D, got: %s" %
210-
transform_matrices)
201+
raise ValueError(
202+
"Matrices should be 2D or 3D, got: %s" % transform_matrices)
211203
# Flatten each matrix.
212-
transforms = tf.reshape(transform_matrices,
213-
tf.constant([-1, 9]))
204+
transforms = tf.reshape(transform_matrices, tf.constant([-1, 9]))
214205
# Divide each matrix by the last entry (normally 1).
215206
transforms /= transforms[:, 8:9]
216207
return transforms[:, :8]
@@ -232,33 +223,35 @@ def angles_to_projective_transforms(angles,
232223
Returns:
233224
A tensor of shape (num_images, 8). Projective transforms which can be given
234225
to `transform` op.
235-
236226
"""
237227
with ops.name_scope(name, "angles_to_projective_transforms"):
238-
angle_or_angles = ops.convert_to_tensor(angles,
239-
name="angles",
240-
dtype=tf.dtypes.float32)
228+
angle_or_angles = ops.convert_to_tensor(
229+
angles, name="angles", dtype=tf.dtypes.float32)
241230
if len(angle_or_angles.get_shape()) == 0:
242231
angles = angle_or_angles[None]
243232
elif len(angle_or_angles.get_shape()) == 1:
244233
angles = angle_or_angles
245234
else:
246235
raise TypeError("Angles should have rank 0 or 1.")
247-
x_offset = ((image_width - 1) -
248-
(tf.math.cos(angles) * (image_width - 1) -
249-
tf.math.sin(angles) * (image_height - 1))) / 2.0
250-
y_offset = ((image_height - 1) -
251-
(tf.math.sin(angles) * (image_width - 1) +
252-
tf.math.cos(angles) * (image_height - 1))) / 2.0
236+
x_offset = (
237+
(image_width - 1) -
238+
(tf.math.cos(angles) * (image_width - 1) - tf.math.sin(angles) *
239+
(image_height - 1))) / 2.0
240+
y_offset = (
241+
(image_height - 1) -
242+
(tf.math.sin(angles) * (image_width - 1) + tf.math.cos(angles) *
243+
(image_height - 1))) / 2.0
253244
num_angles = tf.shape(angles)[0]
254245
return tf.concat(
255-
values=[tf.math.cos(angles)[:, None],
256-
-tf.math.sin(angles)[:, None],
257-
x_offset[:, None],
258-
tf.math.sin(angles)[:, None],
259-
tf.math.cos(angles)[:, None],
260-
y_offset[:, None],
261-
tf.zeros((num_angles, 2), tf.dtypes.float32),],
246+
values=[
247+
tf.math.cos(angles)[:, None],
248+
-tf.math.sin(angles)[:, None],
249+
x_offset[:, None],
250+
tf.math.sin(angles)[:, None],
251+
tf.math.cos(angles)[:, None],
252+
y_offset[:, None],
253+
tf.zeros((num_angles, 2), tf.dtypes.float32),
254+
],
262255
axis=1)
263256

264257

@@ -270,9 +263,8 @@ def _image_projective_transform_grad(op, grad):
270263
interpolation = op.get_attr("interpolation")
271264

272265
image_or_images = ops.convert_to_tensor(images, name="images")
273-
transform_or_transforms = ops.convert_to_tensor(transforms,
274-
name="transforms",
275-
dtype=tf.dtypes.float32)
266+
transform_or_transforms = ops.convert_to_tensor(
267+
transforms, name="transforms", dtype=tf.dtypes.float32)
276268

277269
if image_or_images.dtype.base_dtype not in _IMAGE_DTYPES:
278270
raise TypeError("Invalid dtype %s." % image_or_images.dtype)

0 commit comments

Comments
 (0)