-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Add decode uint16 PNG images support for tf.image.decode_image. #18628
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7bd2c1
Add decode uint16 images support for tf.image.decode_image.
b2d8792
Decode to a tensor with dtype.
b2a5d44
Add testcase for decode_image.
5d7bd17
Add float32 testcase for decode_image.
6704c8e
Fix build error
eee0aeb
Regenerate the tensorflow.image.pbtxt
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3746,5 +3746,88 @@ def testSobelEdges5x3x4x2(self): | |
self.assertAllClose(expected_batch, actual_sobel) | ||
|
||
|
||
class DecodeImageTest(test_util.TensorFlowTestCase): | ||
|
||
def testJpegUint16(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/jpeg/testdata" | ||
jpeg0 = io_ops.read_file(os.path.join(base, "jpeg_merge_test1.jpg")) | ||
image0 = image_ops.decode_image(jpeg0, dtype=dtypes.uint16) | ||
image1 = image_ops.convert_image_dtype(image_ops.decode_jpeg(jpeg0), | ||
dtypes.uint16) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
|
||
def testPngUint16(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/png/testdata" | ||
png0 = io_ops.read_file(os.path.join(base, "lena_rgba.png")) | ||
image0 = image_ops.decode_image(png0, dtype=dtypes.uint16) | ||
image1 = image_ops.convert_image_dtype( | ||
image_ops.decode_png(png0, dtype=dtypes.uint16), dtypes.uint16) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
|
||
def testGifUint16(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/gif/testdata" | ||
gif0 = io_ops.read_file(os.path.join(base, "scan.gif")) | ||
image0 = image_ops.decode_image(gif0, dtype=dtypes.uint16) | ||
image1 = image_ops.convert_image_dtype(image_ops.decode_gif(gif0), | ||
dtypes.uint16) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
|
||
def testBmpUint16(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/bmp/testdata" | ||
bmp0 = io_ops.read_file(os.path.join(base, "lena.bmp")) | ||
image0 = image_ops.decode_image(bmp0, dtype=dtypes.uint16) | ||
image1 = image_ops.convert_image_dtype(image_ops.decode_bmp(bmp0), | ||
dtypes.uint16) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
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. Can you also test the float32 case? I think then we're happy. |
||
|
||
def testJpegFloat32(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/jpeg/testdata" | ||
jpeg0 = io_ops.read_file(os.path.join(base, "jpeg_merge_test1.jpg")) | ||
image0 = image_ops.decode_image(jpeg0, dtype=dtypes.float32) | ||
image1 = image_ops.convert_image_dtype(image_ops.decode_jpeg(jpeg0), | ||
dtypes.float32) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
|
||
def testPngFloat32(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/png/testdata" | ||
png0 = io_ops.read_file(os.path.join(base, "lena_rgba.png")) | ||
image0 = image_ops.decode_image(png0, dtype=dtypes.float32) | ||
image1 = image_ops.convert_image_dtype( | ||
image_ops.decode_png(png0, dtype=dtypes.uint16), dtypes.float32) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
|
||
def testGifFloat32(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/gif/testdata" | ||
gif0 = io_ops.read_file(os.path.join(base, "scan.gif")) | ||
image0 = image_ops.decode_image(gif0, dtype=dtypes.float32) | ||
image1 = image_ops.convert_image_dtype(image_ops.decode_gif(gif0), | ||
dtypes.float32) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
|
||
def testBmpFloat32(self): | ||
with self.test_session(use_gpu=True) as sess: | ||
base = "tensorflow/core/lib/bmp/testdata" | ||
bmp0 = io_ops.read_file(os.path.join(base, "lena.bmp")) | ||
image0 = image_ops.decode_image(bmp0, dtype=dtypes.float32) | ||
image1 = image_ops.convert_image_dtype(image_ops.decode_bmp(bmp0), | ||
dtypes.float32) | ||
image0, image1 = sess.run([image0, image1]) | ||
self.assertAllEqual(image0, image1) | ||
|
||
|
||
if __name__ == "__main__": | ||
googletest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can probably remove
convert_image_dtype
calls from each of these helper functions and instead do it once at the end so that this function will now support types other thanuint8
anduint16
for all image formats.