<p>The data format for storing training/test is defined in the FSNS paper <a href="https://arxiv.org/pdf/1702.03970.pdf" rel="noreferrer">https://arxiv.org/pdf/1702.03970.pdf</a> (Table 4). </p>

<p>To store tfrecord files with tf.Example protos you can use <a href="http://tf.python_io.tfrecordwriter/" rel="noreferrer">tf.python_io.TFRecordWriter</a>. There is <a href="http://warmspringwinds.github.io/tensorflow/tf-slim/2016/12/21/tfrecords-guide/" rel="noreferrer">a nice tutorial</a>, an existing <a href="https://stackoverflow.com/questions/33849617/how-do-i-convert-a-directory-of-jpeg-images-to-tfrecords-file-in-tensorflow">answer on the stackoverflow</a> and a <a href="https://gist.github.com/gvanhorn38/ac19b85a4f7b5fb9e82e04f4ac6d5566" rel="noreferrer">short gist</a>.</p>

<p>Assume you have an numpy ndarray <code>img</code> which has <code>num_of_views</code> images stored side-by-side (see Fig. 3 in the <a href="https://arxiv.org/pdf/1702.03970.pdf" rel="noreferrer">paper</a>):
<img src="https://i.stack.imgur.com/OIdak.png" alt="enter image description here">
and a corresponding text in a variable <code>text</code>. You will need to define some function to convert a unicode string into a list of character ids padded to a fixed length and unpadded as well. For example:</p>

<pre class="lang-py prettyprint-override"><code>char_ids_padded, char_ids_unpadded = encode_utf8_string(
   text='abc', 
   charset={'a':0, 'b':1, 'c':2},
   length=5,
   null_char_id=3)
</code></pre>

<p>the result should be:</p>

<pre class="lang-py prettyprint-override"><code>char_ids_padded = [0,1,2,3,3]
char_ids_unpadded = [0,1,2]
</code></pre>

<p>If you use functions <code>_int64_feature</code> and <code>_bytes_feature</code> defined in the <a href="https://gist.github.com/gvanhorn38/ac19b85a4f7b5fb9e82e04f4ac6d5566" rel="noreferrer">gist</a> you can create a FSNS compatible tf.Example proto using a following snippet:</p>

<pre class="lang-py prettyprint-override"><code>char_ids_padded, char_ids_unpadded = encode_utf8_string(
   text, charset, length, null_char_id)
example = tf.train.Example(features=tf.train.Features(
  feature={
    'image/format': _bytes_feature("PNG"),
    'image/encoded': _bytes_feature(img.tostring()),
    'image/class': _int64_feature(char_ids_padded),
    'image/unpadded_class': _int64_feature(char_ids_unpadded),
    'height': _int64_feature(img.shape[0]),
    'width': _int64_feature(img.shape[1]),
    'orig_width': _int64_feature(img.shape[1]/num_of_views),
    'image/text': _bytes_feature(text)
  }
))
</code></pre>
How to create dataset in the same format as the FSNS dataset?
<p>I'm working on this <a href="https://github.com/tensorflow/models/tree/master/attention_ocr" rel="noreferrer">project</a> based on TensorFlow.</p>

<p>I just want to train an OCR model by attention_ocr based on my own datasets, but I don't know how to store my images and ground truth in the same format as FSNS datasets.</p>

<p>Is there anybody also work on this project or know how to solve this problem?</p>