Jin Joo Hyeong
Jin Joo Hyeong

Reputation: 11

How can I read binary file in Tensorflow

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

Upvotes: 1

Views: 2755

Answers (1)

Allen Lavoie
Allen Lavoie

Reputation: 5808

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.

Upvotes: 1

Related Questions