title: Write custom Data Generator for Keras
body: <p>I have each datapoint stored in a .npy file, with <code>shape=(1024,7,8)</code>. I want to load them to a Keras model by a manner similar to <code>ImageDataGenerator</code>, so I wrote and tried different custom generators but none of them work, here is one I adapted from <a href="https://stackoverflow.com/questions/46493419/use-a-generator-for-keras-model-fit-generator">this</a></p>
  
  <pre><code>def find(dirpath, prefix=None, suffix=None, recursive=True):
      """Function to find recursively all files with specific prefix and suffix in a directory
      Return a list of paths
      """
      l = []
      if not prefix:
          prefix = ''
      if not suffix:
          suffix = ''
      for (folders, subfolders, files) in os.walk(dirpath):
          for filename in [f for f in files if f.startswith(prefix) and f.endswith(suffix)]:
              l.append(os.path.join(folders, filename))
          if not recursive:
              break
      l
      return l
  
  def generate_data(directory, batch_size):
      i = 0
      file_list = find(directory)
      while True:
          array_batch = []
          for b in range(batch_size):
              if i == len(file_list):
                  i = 0
                  random.shuffle(file_list)
              sample = file_list[i]
              i += 1
  
              array = np.load(sample)
              array_batch.append(array)
  
          yield array_batch
  </code></pre>
  
  <p>I found this lacks of the label, so it won't be fit into the model using <code>fit_generator</code> . How can I add the label into this generator, given that I can store them in a numpy array?</p>