-
Notifications
You must be signed in to change notification settings - Fork 615
Solarize_ops for Tensorflow Addons #1340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9ff2b1e
33273e4
988eb7d
0e475ad
cbfb727
7793f7b
90986d5
0885286
4b2973f
5c9931f
8e7624b
2042507
aca2720
86195a5
5558e9d
275cc9d
7166693
9b814e8
68ee0b6
9e7bc9c
dde7772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
licenses(["notice"]) # Apache 2.0 | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
package(default_visibility=["//visibility:public"]) | ||
|
||
py_library( | ||
name = "image", | ||
srcs = ([ | ||
"__init__.py", | ||
"dense_image_warp.py", | ||
"distance_transform.py", | ||
"distort_image_ops.py", | ||
"filters.py", | ||
"transform_ops.py", | ||
"translate_ops.py", | ||
"utils.py", | ||
"sparse_image_warp.py", | ||
"interpolate_spline.py", | ||
"connected_components.py", | ||
"resampler_ops.py", | ||
"compose_ops.py", | ||
]), | ||
|
||
name="image", | ||
srcs=( | ||
[ | ||
"__init__.py", | ||
"dense_image_warp.py", | ||
"distance_transform.py", | ||
"distort_image_ops.py", | ||
"filters.py", | ||
"transform_ops.py", | ||
"translate_ops.py", | ||
"utils.py", | ||
"sparse_image_warp.py", | ||
"interpolate_spline.py", | ||
"connected_components.py", | ||
"resampler_ops.py", | ||
"solarize_ops.py", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
]), | ||
data = [ | ||
|
||
":sparse_image_warp_test_data", | ||
"//tensorflow_addons/custom_ops/image:_distort_image_ops.so", | ||
"//tensorflow_addons/custom_ops/image:_image_ops.so", | ||
|
@@ -29,141 +32,104 @@ py_library( | |
) | ||
|
||
filegroup( | ||
name = "sparse_image_warp_test_data", | ||
srcs = glob(["test_data/*.png"]), | ||
name="sparse_image_warp_test_data", srcs=glob(["test_data/*.png"]), | ||
) | ||
|
||
py_test( | ||
name = "dense_image_warp_test", | ||
size = "small", | ||
srcs = [ | ||
"dense_image_warp_test.py", | ||
], | ||
main = "dense_image_warp_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="dense_image_warp_test", | ||
size="small", | ||
srcs=["dense_image_warp_test.py",], | ||
main="dense_image_warp_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "distance_transform_ops_test", | ||
size = "small", | ||
srcs = [ | ||
"distance_transform_test.py", | ||
], | ||
main = "distance_transform_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="distance_transform_ops_test", | ||
size="small", | ||
srcs=["distance_transform_test.py",], | ||
main="distance_transform_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "distort_image_ops_test", | ||
size = "small", | ||
srcs = [ | ||
"distort_image_ops_test.py", | ||
], | ||
main = "distort_image_ops_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="distort_image_ops_test", | ||
size="small", | ||
srcs=["distort_image_ops_test.py",], | ||
main="distort_image_ops_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "filters_test", | ||
size = "medium", | ||
srcs = [ | ||
"filters_test.py", | ||
], | ||
flaky = True, | ||
main = "filters_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="filters_test", | ||
size="medium", | ||
srcs=["filters_test.py",], | ||
flaky=True, | ||
main="filters_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "transform_ops_test", | ||
size = "medium", | ||
srcs = [ | ||
"transform_ops_test.py", | ||
], | ||
main = "transform_ops_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="transform_ops_test", | ||
size="medium", | ||
srcs=["transform_ops_test.py",], | ||
main="transform_ops_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "translate_ops_test", | ||
size = "medium", | ||
srcs = [ | ||
"translate_ops_test.py", | ||
], | ||
main = "translate_ops_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="translate_ops_test", | ||
size="medium", | ||
srcs=["translate_ops_test.py",], | ||
main="translate_ops_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "utils_test", | ||
size = "small", | ||
srcs = [ | ||
"utils_test.py", | ||
], | ||
main = "utils_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="utils_test", | ||
size="small", | ||
srcs=["utils_test.py",], | ||
main="utils_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "sparse_image_warp_test", | ||
size = "medium", | ||
srcs = [ | ||
"sparse_image_warp_test.py", | ||
], | ||
main = "sparse_image_warp_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="sparse_image_warp_test", | ||
size="medium", | ||
srcs=["sparse_image_warp_test.py",], | ||
main="sparse_image_warp_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "interpolate_spline_test", | ||
size = "medium", | ||
srcs = [ | ||
"interpolate_spline_test.py", | ||
], | ||
main = "interpolate_spline_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="interpolate_spline_test", | ||
size="medium", | ||
srcs=["interpolate_spline_test.py",], | ||
main="interpolate_spline_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "connected_components_test", | ||
size = "medium", | ||
srcs = [ | ||
"connected_components_test.py", | ||
], | ||
main = "connected_components_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="connected_components_test", | ||
size="medium", | ||
srcs=["connected_components_test.py",], | ||
main="connected_components_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name = "resampler_ops_test", | ||
size = "medium", | ||
srcs = [ | ||
"resampler_ops_test.py", | ||
], | ||
main = "resampler_ops_test.py", | ||
deps = [ | ||
":image", | ||
], | ||
name="resampler_ops_test", | ||
size="medium", | ||
srcs=["resampler_ops_test.py",], | ||
main="resampler_ops_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
name="solarize_ops_test", | ||
size="medium", | ||
srcs=["solarize_ops_test.py",], | ||
main="solarize_ops_test.py", | ||
deps=[":image",], | ||
) | ||
|
||
py_test( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" This module is used to invert all pixel values above a threshold | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
which simply means segmentation. """ | ||
|
||
import tensorflow as tf | ||
|
||
|
||
def solarize(image, threshold=128): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing type. |
||
"""Method to solarize the image | ||
image: input image | ||
threshold: threshold value to solarize the image | ||
""" | ||
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use proper indents. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at other source files to see how docstrings are written. |
||
# For each pixel in the image, select the pixel | ||
# if the value is less than the threshold. | ||
# Otherwise, subtract 255 from the pixel. | ||
return tf.where(image < threshold, image, 255 - image) | ||
|
||
|
||
def solarize_add(image, addition=0, threshold=128): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing type info. |
||
"""Method to add solarize to the image | ||
image: input image | ||
addition: addition amount to add in image | ||
threshold: threshold value to solarize the image | ||
""" | ||
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent properly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at other source files to see how docstrings are written. |
||
# For each pixel in the image less than threshold | ||
# we add 'addition' amount to it and then clip the | ||
# pixel value to be between 0 and 255. The value | ||
# of 'addition' is between -128 and 128. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a check to ensure |
||
added_image = tf.cast(image, tf.int64) + addition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the cast to |
||
added_image = tf.cast(tf.clip_by_value(added_image, 0, 255), tf.uint8) | ||
return tf.where(image < threshold, added_image, image) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Test of solarize_ops""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing LICENSE. |
||
import sys | ||
import pytest | ||
import tensorflow as tf | ||
from tensorflow_addons.image import solarize_ops | ||
from tensorflow_addons.utils import test_utils | ||
from absl.testing import parameterized | ||
|
||
|
||
@test_utils.run_all_in_graph_and_eager_modes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #1328 |
||
class SolarizeOPSTest(tf.test.TestCase, parameterized.TestCase): | ||
"""SolarizeOPSTest class to test the solarize images""" | ||
|
||
def test_solarize(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test for |
||
if tf.executing_eagerly(): | ||
image2 = tf.constant( | ||
[ | ||
[255, 255, 255, 255], | ||
[255, 255, 255, 255], | ||
[255, 255, 255, 255], | ||
[255, 255, 255, 255], | ||
], | ||
dtype=tf.uint8, | ||
) | ||
threshold = 10 | ||
solarize_img = solarize_ops.solarize(image2, threshold) | ||
self.assertAllEqual(tf.shape(solarize_img), tf.shape(image2)) | ||
|
||
if __name__ == "__main__": | ||
sys.exit(pytest.main([__file__])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how the
BUILD
is formatted. Please look at Development tips to know how to auto-format your code.If you're on Windows, you can use docker to do the same.