title: Tensorflow-IO Dataset input pipeline with very large HDF5 files
body: <p>I have very big training (30Gb) files.<br />
  Since all the data does not fit in my available RAM, I want to read the data by batch.<br />
  I saw that there is Tensorflow-io package which <a href="https://www.tensorflow.org/io/api_docs/python/tfio/IODataset#from_hdf5" rel="nofollow noreferrer">implemented a way</a> to read HDF5 into Tensorflow this way thanks to the function <code>tfio.IODataset.from_hdf5()</code><br />
  Then, since <code>tf.keras.model.fit()</code> takes a <code>tf.data.Dataset</code> as input containing both samples and targets, I need to zip my X and Y together and then use <code>.batch and .prefetch</code> to load in memory just the necessary data. For testing I tried to apply this method to smaller samples: training (9Gb), validation (2.5Gb) and testing (1.2Gb) which I know work well because they can fit into memory and I have good results (70% accuracy and &lt;1 loss).<br />
  The training files are stored in HDF5 files split into samples (X) and labels (Y) files like so:</p>
  <pre><code>X_learn.hdf5  
  X_val.hdf5  
  X_test.hdf5  
  Y_test.hdf5  
  Y_learn.hdf5  
  Y_val.hdf5
  </code></pre>
  <p>Here is my code:</p>
  <pre class="lang-py prettyprint-override"><code>BATCH_SIZE = 2048
  EPOCHS = 100
  
  # Create an IODataset from a hdf5 file's dataset object  
  x_val = tfio.IODataset.from_hdf5(path_hdf5_x_val, dataset='/X_val')
  y_val = tfio.IODataset.from_hdf5(path_hdf5_y_val, dataset='/Y_val')
  x_test = tfio.IODataset.from_hdf5(path_hdf5_x_test, dataset='/X_test')
  y_test = tfio.IODataset.from_hdf5(path_hdf5_y_test, dataset='/Y_test')
  x_train = tfio.IODataset.from_hdf5(path_hdf5_x_train, dataset='/X_learn')
  y_train = tfio.IODataset.from_hdf5(path_hdf5_y_train, dataset='/Y_learn')
   
  # Zip together samples and corresponding labels
  train = tf.data.Dataset.zip((x_train,y_train)).batch(BATCH_SIZE, drop_remainder=True).prefetch(tf.data.experimental.AUTOTUNE)
  test = tf.data.Dataset.zip((x_test,y_test)).batch(BATCH_SIZE, drop_remainder=True).prefetch(tf.data.experimental.AUTOTUNE)
  val = tf.data.Dataset.zip((x_val,y_val)).batch(BATCH_SIZE, drop_remainder=True).prefetch(tf.data.experimental.AUTOTUNE)
  
  # Build the model
  model = build_model()
   
  # Compile the model with custom learing rate function for Adam optimizer
  model.compile(loss='categorical_crossentropy',
                 optimizer=Adam(lr=lr_schedule(0)),
                 metrics=['accuracy'])
  
  # Fit model with class_weights calculated before
  model.fit(train,
            epochs=EPOCHS,
            class_weight=class_weights_train,
            validation_data=val,
            shuffle=True,
            callbacks=callbacks)
  </code></pre>
  <p>This code runs but the loss goes very high (300+) and accuracy drops to 0 (0.30 -&gt; 4*e^-5) right from the beginning... I don't understand what I am doing wrong, am I missing something ?</p>