Repository navigation
fix tfrecord compress on hdfs - #108
bigbear2017 wants to merge 1 commit into
Conversation
|
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. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
I signed it! |
|
CLAs look good, thanks! |
|
The underlying TFRecords file format supports compression, and I'm worried that the difference in format here will confuse users. Could we use that instead? |
please refer to this issue: Now, the compression doesn't work on spark or hadoop MR. If you write data local, it's OK. You can compress TF records. The compression is done by python not TF. To me, there is no confusion. With this PR, you can read compressed data generated by Spark or hadoop in python. This has been tested in our system. |
|
@bigbear2017 Do we have to add options to compress the TFRecord files ? |
|
@sahilbadyal |
|
@bigbear2017 Sorry for not asking the question right. I am using Pyspark |
|
Why is this this PR closed ? It has not been merged. |
| @@ -32,20 +32,29 @@ public class TFRecordFileOutputFormat extends FileOutputFormat<BytesWritable, Nu | |||
| @Override public RecordWriter<BytesWritable, NullWritable> getRecordWriter( | |||
There was a problem hiding this comment.
relevant imports are missing:
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.util.ReflectionUtils;
import java.io.DataOutputStream;
| FileSystem fs = file.getFileSystem(conf); | ||
| final DataOutputStream fsdos = isCompressed ? | ||
| new DataOutputStream(codec.createOutputStream(fs.create(file, true, bufferSize))) : | ||
| fs.create(file, true, bufferSize); |
There was a problem hiding this comment.
fs.create(file, true, bufferSize) could be factorized in a variable
|
I tested the fix. It is working (with minor changes, need to add the right imports) and can be imported from Python by setting Unit tests are still working |
|
I'm ok with a pull request that sets the TFRecordCompressionType. I'm just worried about using different compression formats. The TFRecord compression is integrated into the file format, and this PR gzips the file which ends up being a different format. Happy to accept a pull request that can set the option in TFRecords. |
|
Can you give more details on
What do you mean by ?
gzip is standardized. So it always will be the gzip format. From how I understand it (please correct me if I'm wrong)
About the settings, it ends up setting this to the Spark/PySpark job which also seems fine to me. Indeed it might not work in some cases as Python api might not support it but it gives enough flexibility for other codecs. At the end on my side I would like to have something that works (and I don't want to maintain my own fork). So any implementation is fine for me. |
|
TFRecord is a format that is essentially a sequence of records stored as bytes. Those can be anything, but are typically tf.Example protos. The TFRecord has custom compression settings that are different than just gzipping the file, which you can set in the options: I'm worried about offering an incompatible, but similar compression setting here. If we could make it compatible, then that's fine. |
|
In my opinion what is important is that TfRecords that are written here can be read by Pythons TFRecordReader. And when someone wants to implement all options of ZLIB he can do this in a second step. I would argue user rather want to use a newer compression lib than doing that. |
|
It would also need to work with tf.data. |
|
So maybe adding a new setting 'tfrecord.compressiontype=Gzip' is better because it restrains the number of possibilities and can be extended to what has been implemented in TfRecordOptions |
|
I tried this: It is working. As suggested I can provide a new PR with the same code + a unit test. |
|
@fhoering |
|
@jhseu |
|
hmmm.... I thought I would have a merge in this project. T.T |
|
anyway, it is good that this has been fixed. : ) |
|
Thanks @bigbear2017 for starting this effort! The test that checked that tf.data reads it correctly alleviated my concern about merging this kind of change in. |
|
Execuse me, i user spark to transform the original format to TFrecord format, it works , but the tfrecord file is too large , i want to compress it, what should i do? import org.tensorflow.hadoop.io.TFRecordFileOutputFormat val tfrecord_sample_dir = sample_dir + localArgs.yyyyMMdd + "/" + localArgs.loc+"_tfrecord" where tfrecord_sample is a RDD[(BytesWritable, NullWriteable)] format, BytesWritable is a tfrecord example format。 i see saveAsHadoopFile function provide a way to compress the original data, but i do not know how to use it, anyone can help? Output the RDD to any Hadoop-supported file system, using a Hadoop OutputFormat class |
|
hello,when i use follow code to compress the tfrecord as gzip format,it seems doesn't work. There is no different between the output file size whether add the "option("codec","org.apache.hadoop.io.compress.GzipCodec")" or not write.mode("overwrite") |
Default code doesn't support gzip or other compression type on hdfs. This
has been fixed in this pull request. Simply using following gzip compression,
it can reduce 6-7 times less space.