• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("//tensorflow/core/platform:rules_cc.bzl", "cc_library")
2load("@bazel_skylib//rules:build_test.bzl", "build_test")
3load(
4    "//tensorflow:tensorflow.bzl",
5    "if_android",
6    "if_cuda_or_rocm",
7    "tf_cc_test",
8    "tf_cc_tests",
9    "tf_copts",
10)
11load(
12    "//tensorflow/core/platform:build_config_root.bzl",
13    "tf_cuda_tests_tags",
14)
15
16# buildifier: disable=same-origin-load
17load("//tensorflow:tensorflow.bzl", "filegroup")
18
19# buildifier: disable=same-origin-load
20load("//tensorflow:tensorflow.bzl", "tf_cuda_cc_test")
21
22# buildifier: disable=same-origin-load
23load("//tensorflow:tensorflow.bzl", "tf_kernel_library")
24
25# TODO(rmlarsen): Remove ASAP.
26package_group(
27    name = "friends",
28    packages = [
29        "//tensorflow/...",
30        "//tensorflow_text/...",
31    ],
32)
33
34package(
35    default_visibility = [
36        ":friends",
37        "//tensorflow:__subpackages__",
38        "//tensorflow:internal",
39    ],
40    licenses = ["notice"],  # Apache 2.0
41)
42
43# Export a few files for use on Android.
44exports_files([
45    "adjust_contrast_op.cc",
46    "adjust_contrast_op.h",
47    "adjust_hue_op.cc",
48    "adjust_hue_op.h",
49    "adjust_saturation_op.cc",
50    "adjust_saturation_op.h",
51    "crop_and_resize_op.cc",
52    "crop_and_resize_op.h",
53    "extract_image_patches_op.cc",
54    "extract_image_patches_op.h",
55    "image_ops.h",
56    "image_ops.cc",
57    "mirror_pad_op.cc",
58    "mirror_pad_op.h",
59    "mirror_pad_op_cpu_impl.h",
60    "mirror_pad_op_cpu_impl_1.cc",
61    "mirror_pad_op_cpu_impl_2.cc",
62    "mirror_pad_op_cpu_impl_3.cc",
63    "mirror_pad_op_cpu_impl_4.cc",
64    "mirror_pad_op_cpu_impl_5.cc",
65    "non_max_suppression_op.cc",
66    "non_max_suppression_op.h",
67    "resize_bicubic_op.cc",
68    "resize_bilinear_op.cc",
69    "resize_bilinear_op.h",
70    "resize_nearest_neighbor_op.cc",
71    "resize_nearest_neighbor_op.h",
72    "sample_distorted_bounding_box_op.cc",
73    "decode_image_op.cc",
74    "encode_jpeg_op.cc",
75    "encode_png_op.cc",
76])
77
78# Private support libraries ---------------------------------------------------
79cc_library(
80    name = "sampling_kernels",
81    srcs = ["sampling_kernels.cc"],
82    hdrs = ["sampling_kernels.h"],
83    visibility = ["//visibility:private"],
84    deps = ["//tensorflow/core:lib"],
85)
86
87tf_cc_test(
88    name = "sampling_kernels_test",
89    srcs = ["sampling_kernels_test.cc"],
90    deps = [
91        ":sampling_kernels",
92        "//tensorflow/core:test",
93        "//tensorflow/core:test_main",
94        "//tensorflow/core:testlib",
95        "@com_google_absl//absl/strings",
96    ],
97)
98
99# Public support libraries ----------------------------------------------------<
100cc_library(
101    name = "image",
102    visibility = ["//visibility:public"],
103    deps = [
104        ":adjust_contrast_op",
105        ":adjust_hue_op",
106        ":adjust_saturation_op",
107        ":attention_ops",
108        ":colorspace_op",
109        ":crop_and_resize_op",
110        ":decode_image_op",
111        ":draw_bounding_box_op",
112        ":encode_jpeg_op",
113        ":encode_png_op",
114        ":extract_image_patches_op",
115        ":extract_jpeg_shape_op",
116        ":extract_volume_patches_op",
117        ":generate_box_proposals_op",
118        ":image_ops",
119        ":mirror_pad_op",
120        ":non_max_suppression_op",
121        ":random_crop_op",
122        ":resize_area_op",
123        ":resize_bicubic_op",
124        ":resize_bilinear_op",
125        ":resize_nearest_neighbor_op",
126        ":sample_distorted_bounding_box_op",
127        ":scale_and_translate_op",
128    ],
129)
130
131IMAGE_DEPS = [
132    "//third_party/eigen3",
133    "//tensorflow/core:framework",
134    "//tensorflow/core:gif_internal",
135    "//tensorflow/core:jpeg_internal",
136    "//tensorflow/core:lib",
137    "//tensorflow/core:lib_internal",
138    "//tensorflow/core/lib/png:png_io",
139    "//tensorflow/core:protos_all_cc",
140    "//tensorflow/core/framework:bounds_check",
141    "//tensorflow/core/kernels:eigen_helpers",
142    "//tensorflow/core/util/tensor_bundle",
143    "//tensorflow/core/util:image_resizer_state",
144]
145
146IMAGE_TEST_DEPS = [
147    "//tensorflow/core/kernels:ops_testutil",
148    "//tensorflow/core/kernels:ops_util",
149    "//tensorflow/core:core_cpu",
150    "//tensorflow/core:framework",
151    "//tensorflow/core:lib",
152    "//tensorflow/core:lib_internal",
153    "//tensorflow/core:protos_all_cc",
154    "//tensorflow/core:test",
155    "//tensorflow/core:test_main",
156    "//tensorflow/core:testlib",
157]
158
159tf_kernel_library(
160    name = "adjust_contrast_op",
161    prefix = "adjust_contrast_op",
162    deps = IMAGE_DEPS,
163)
164
165cc_library(
166    name = "adjust_hsv_gpu_lib",
167    hdrs = ["adjust_hsv_gpu.cu.h"],
168    deps = ["//tensorflow/core:framework"],
169)
170
171tf_kernel_library(
172    name = "adjust_hue_op",
173    prefix = "adjust_hue_op",
174    deps = IMAGE_DEPS + [":adjust_hsv_gpu_lib"],
175)
176
177tf_kernel_library(
178    name = "adjust_saturation_op",
179    prefix = "adjust_saturation_op",
180    deps = IMAGE_DEPS + [":adjust_hsv_gpu_lib"],
181)
182
183tf_kernel_library(
184    name = "attention_ops",
185    prefix = "attention_ops",
186    deps = IMAGE_DEPS,
187)
188
189tf_kernel_library(
190    name = "colorspace_op",
191    prefix = "colorspace_op",
192    deps = IMAGE_DEPS,
193)
194
195tf_kernel_library(
196    name = "crop_and_resize_op",
197    prefix = "crop_and_resize_op",
198    deps = IMAGE_DEPS + ["//tensorflow/core:framework_internal"],
199)
200
201tf_kernel_library(
202    name = "decode_image_op",
203    prefix = "decode_image_op",
204    deps = IMAGE_DEPS + ["@com_google_absl//absl/strings"],
205)
206
207tf_kernel_library(
208    name = "draw_bounding_box_op",
209    prefix = "draw_bounding_box_op",
210    deps = IMAGE_DEPS,
211)
212
213tf_kernel_library(
214    name = "encode_jpeg_op",
215    prefix = "encode_jpeg_op",
216    deps = IMAGE_DEPS,
217)
218
219tf_kernel_library(
220    name = "encode_png_op",
221    prefix = "encode_png_op",
222    deps = IMAGE_DEPS,
223)
224
225tf_kernel_library(
226    name = "extract_jpeg_shape_op",
227    prefix = "extract_jpeg_shape_op",
228    deps = IMAGE_DEPS,
229)
230
231tf_kernel_library(
232    name = "extract_image_patches_op",
233    prefix = "extract_image_patches_op",
234    deps = [
235        "//tensorflow/core/kernels:ops_util",
236    ] + IMAGE_DEPS,
237)
238
239tf_kernel_library(
240    name = "extract_volume_patches_op",
241    prefix = "extract_volume_patches_op",
242    deps = [
243        "//tensorflow/core:framework",
244        "//tensorflow/core:lib",
245        "//tensorflow/core/kernels:eigen_helpers",
246        "//tensorflow/core/kernels:ops_util",
247        "//third_party/eigen3",
248    ],
249)
250
251tf_kernel_library(
252    name = "generate_box_proposals_op",
253    gpu_srcs = ["generate_box_proposals_op.cu.cc"],
254    deps = ["//tensorflow/core/kernels:gpu_prim_hdrs"] + if_cuda_or_rocm([
255        ":non_max_suppression_op_gpu",
256    ]),
257)
258
259tf_kernel_library(
260    name = "non_max_suppression_op",
261    prefix = "non_max_suppression_op",
262    deps = IMAGE_DEPS + ["//tensorflow/core/kernels:gpu_prim_hdrs"],
263)
264
265tf_kernel_library(
266    name = "scale_and_translate_op",
267    prefix = "scale_and_translate_op",
268    deps = IMAGE_DEPS + [":sampling_kernels"],
269)
270
271tf_kernel_library(
272    name = "random_crop_op",
273    prefix = "random_crop_op",
274    deps = IMAGE_DEPS,
275)
276
277tf_kernel_library(
278    name = "resize_area_op",
279    prefix = "resize_area_op",
280    deps = IMAGE_DEPS,
281)
282
283tf_kernel_library(
284    name = "resize_bicubic_op",
285    prefix = "resize_bicubic_op",
286    deps = IMAGE_DEPS,
287)
288
289tf_kernel_library(
290    name = "resize_bilinear_op",
291    prefix = "resize_bilinear_op",
292    deps = IMAGE_DEPS + ["//tensorflow/core/kernels:cast_op"],
293)
294
295tf_kernel_library(
296    name = "resize_nearest_neighbor_op",
297    prefix = "resize_nearest_neighbor_op",
298    deps = IMAGE_DEPS,
299)
300
301tf_kernel_library(
302    name = "sample_distorted_bounding_box_op",
303    prefix = "sample_distorted_bounding_box_op",
304    deps = IMAGE_DEPS + ["//tensorflow/core/kernels:stateless_random_ops"],
305)
306
307tf_kernel_library(
308    name = "image_ops",
309    prefix = "image_ops",
310    deps = IMAGE_DEPS,
311)
312
313tf_kernel_library(
314    name = "mirror_pad_op",
315    prefix = "mirror_pad_op",
316    deps = IMAGE_DEPS,
317)
318
319# Tests ------------------------
320
321tf_cc_tests(
322    name = "bonus_tests",
323    srcs = [
324        "adjust_contrast_op_test.cc",
325        "colorspace_op_test.cc",
326        "crop_and_resize_op_test.cc",
327        "mirror_pad_op_test.cc",
328        "non_max_suppression_op_test.cc",
329        "resize_area_op_test.cc",
330        "resize_bicubic_op_test.cc",
331        "scale_and_translate_op_test.cc",
332    ],
333    linkopts = select({
334        "//tensorflow:macos": ["-headerpad_max_install_names"],
335        "//conditions:default": [],
336    }),
337    deps = [
338        ":image",
339        ":sampling_kernels",
340        ":mirror_pad_op",
341    ] + IMAGE_TEST_DEPS,
342)
343
344tf_cc_test(
345    name = "non_max_suppression_op_benchmark_test",
346    srcs = ["non_max_suppression_op_benchmark_test.cc"],
347    deps = [
348        ":image",
349    ] + IMAGE_TEST_DEPS,
350)
351
352tf_cuda_cc_test(
353    name = "resize_ops_test",
354    srcs = [
355        "resize_bilinear_op_test.cc",
356        "resize_nearest_neighbor_op_test.cc",
357    ],
358    tags = [
359        "no_cuda_asan",  # TODO(b/171334997): re-enable
360        "no_cuda_on_cpu_tap",
361    ],
362    deps = [
363        ":image",
364        ":sampling_kernels",
365    ] + IMAGE_TEST_DEPS,
366)
367
368tf_cuda_cc_test(
369    name = "adjust_contrast_op_benchmark_test",
370    srcs = ["adjust_contrast_op_benchmark_test.cc"],
371    deps = [
372        ":image",
373    ] + IMAGE_TEST_DEPS,
374)
375
376tf_cuda_cc_test(
377    name = "crop_and_resize_op_benchmark_test",
378    srcs = ["crop_and_resize_op_benchmark_test.cc"],
379    deps = [
380        ":image",
381    ] + IMAGE_TEST_DEPS,
382)
383
384tf_cuda_cc_test(
385    name = "mirror_pad_op_benchmark_test",
386    srcs = ["mirror_pad_op_benchmark_test.cc"],
387    deps = [
388        ":mirror_pad_op",
389    ] + IMAGE_TEST_DEPS,
390)
391
392tf_cuda_cc_test(
393    name = "non_max_suppression_op_gpu_test",
394    srcs = ["non_max_suppression_op_gpu_test.cc"],
395    tags = tf_cuda_tests_tags() + [
396        "no_cuda_asan",  # TODO(b/171263349): re-enable.
397        "no_cuda_on_cpu_tap",
398    ],
399    deps = [
400        ":image",
401        "@com_google_absl//absl/strings",
402    ] + IMAGE_TEST_DEPS,
403)
404
405tf_cuda_cc_test(
406    name = "resize_benchmark_test",
407    srcs = ["resize_op_benchmark_test.cc"],
408    deps = [
409        ":image",
410    ] + IMAGE_TEST_DEPS,
411)
412
413tf_cc_test(
414    name = "encode_jpeg_op_test",
415    size = "small",
416    srcs = ["encode_jpeg_op_test.cc"],
417    deps = [
418        ":encode_jpeg_op",
419    ] + IMAGE_TEST_DEPS,
420)
421
422cc_library(
423    name = "android_tensorflow_image_op",
424    srcs = if_android(["decode_image_op.cc"]),
425    copts = tf_copts(),
426    linkopts = ["-ldl"],
427    visibility = ["//visibility:public"],
428    deps = [
429        "//tensorflow/core:portable_gif_internal",
430        "//tensorflow/core:portable_jpeg_internal",
431        "//tensorflow/core:portable_tensorflow_lib_lite",
432        "//tensorflow/core/lib/png:png_io",
433    ],
434    alwayslink = 1,
435)
436
437build_test(
438    name = "android_tensorflow_image_op_build_test",
439    targets = [":android_tensorflow_image_op"],
440)
441
442# A file group which contains all operators which are known to work on mobile.
443filegroup(
444    name = "android_all_op_kernels",
445    srcs = glob(
446        [
447            "*.cc",
448            "*.h",
449        ],
450        exclude = [
451            "*test.cc",
452            "*test.h",
453            "*_test_*",
454            "decode_image_op.*",
455            "encode_png_op.*",
456            "encode_jpeg_op.*",
457            "extract_jpeg_shape_op.*",
458            "decode_jpeg_op.*",
459            "decode_and_crop_jpeg_op.*",
460            "decode_gif_op.*",
461        ],
462    ),
463    visibility = ["//tensorflow:__subpackages__"],
464)
465
466filegroup(
467    name = "android_all_ops_textual_hdrs",
468    srcs = ["mirror_pad_op.h"],
469    visibility = ["//visibility:public"],
470)
471