1

I'm trying to read binary file in tensorflow. I want to ask, which method should I use, and how for reading binary file. In tensorflow, they recommends use dataset in tf.data. But I can't find simple example of using dataset, especially FixedLengthRecordDataset. I think I should use this method, but I don't know how to use.

[hg file] := [file header] [image1] [image2] [image3] ...

[file header] := "hg  " (8 bytes)

[imageN] := [image header] [image data]

[image header] := [code(2 bytes)] [width (1 byte)] [height(1 byte)] [reserved(2 bytes)]

[image data] := 256 gray data (width * height bytes, row-major format)

This is the format of my binary file.

Please give me some advice for this work.

EDIT : All images have different size. So maybe I can't use FixedLengthRecordDatasest. I think I have to convert all images to same size of dataset

1 Answer 1

1

I believe you'd need to write your own Dataset reader op to parse that format. FixedLengthRecordDataset's implementation would be a good place to start for structuring the code (but as you note, the records you've described are not fixed length).

I would recommend instead re-encoding the images in tf.train.Example protocol buffers, then using a TFRecordDataset for input. That way the parsing is already written for you; you should be able to create tf.train.Example protos in any language.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.