Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Add tfrecord gzip compression - #125

Merged
jhseu merged 1 commit into
tensorflow:masterfrom
fhoering:fix-gzip-compression
Mar 27, 2019
Merged

jhseu merged 1 commit into
tensorflow:masterfrom
fhoering:fix-gzip-compression

Conversation

@fhoering

@fhoering fhoering commented Mar 26, 2019 •

Copy link
Copy Markdown
Contributor
  • added in TFRecordFileInputFormat & TFRecordFileOutputFormat
  • improved unit tests to handle both cases
  • didn't change TFRecordFileOutputFormatV1 (couldn't test and not used by SparkConnector)
  • the most risky is the readFully reimplementation, if you think this is too risky we can also remove it, it was essentially done for the unit test, I don't actually use the TFRecordFileInputFormat

Tested in Python with (ZLIB option is not supported)

import tensorflow as tf
specs = {
    'data': tf.VarLenFeature(dtype=tf.int64)
}
dataset = tf.data.TFRecordDataset(["tf-records/part-m-00000"], compression_type="")
dataset = dataset.map(
    lambda x: tf.parse_single_example(x, features=specs)
)
next_tfr = dataset.make_one_shot_iterator().get_next()
with tf.Session() as sess:
    try:
        for i in range(10):
            print(sess.run(next_tfr))
    except tf.errors.OutOfRangeError:
        pass
import tensorflow as tf
specs = {
    'data': tf.VarLenFeature(dtype=tf.int64)
}
dataset = tf.data.TFRecordDataset(["tf-records/part-m-00000.gz"], compression_type="GZIP")
dataset = dataset.map(
    lambda x: tf.parse_single_example(x, features=specs)
)
next_tfr = dataset.make_one_shot_iterator().get_next()
with tf.Session() as sess:
    try:
        for i in range(10):
            print(sess.run(next_tfr))
    except tf.errors.OutOfRangeError:
        pass

@googlebot

Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@jhseu

jhseu commented Mar 26, 2019

Copy link
Copy Markdown
Contributor

Mind handling the CLA?

@fhoering
fhoering force-pushed the fix-gzip-compression branch from a8393cc to 2cf060f Compare March 26, 2019 20:15
@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@fhoering
fhoering force-pushed the fix-gzip-compression branch 2 times, most recently from fac15ef to 6e8d2bc Compare March 26, 2019 20:23
@jhseu

jhseu commented Mar 26, 2019

Copy link
Copy Markdown
Contributor

Have you tested the contents of the TFRecords files? The test just seems to parse them only.

@fhoering
fhoering force-pushed the fix-gzip-compression branch 2 times, most recently from 45c9f85 to 47b6283 Compare March 27, 2019 10:01
@fhoering

fhoering commented Mar 27, 2019 •

Copy link
Copy Markdown
Contributor Author

I changed the test again to have tests for a fixed dataset.
I also compared the tf record content with what is read by the python code.

- added in TFRecordFileInputFormat & TFRecordFileOutputFormat
- improved unit tests to handle both cases
- didn't change TFRecordFileOutputFormatV1 (couldn't test and not used by SparkConnector)
@fhoering
fhoering force-pushed the fix-gzip-compression branch from 47b6283 to 00a3229 Compare March 27, 2019 10:41

@jhseu jhseu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jhseu
jhseu merged commit 4df0e17 into tensorflow:master Mar 27, 2019
fjkfwz pushed a commit to xiachufang/ecosystem that referenced this pull request Oct 12, 2019
- added in TFRecordFileInputFormat & TFRecordFileOutputFormat
- improved unit tests to handle both cases
- didn't change TFRecordFileOutputFormatV1 (couldn't test and not used by SparkConnector)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants