title: How to optimize loading of batch on tensorflow?
body: <p>I have a problem with the very slow batch loading in tensorflow.
  Each step in the training is reasonably fast but my function to load data is extremely slow.</p>
  
  <p>I was wondering if there were any ways to make this faster or run it in the background when train operation is running so that the batch can be ready by the time one step is done.</p>
  
  <p>My features are stored in numpy arrays.</p>
  
  <p>Any Ideas? 
  This is my code.</p>
  
  <pre><code>def test_loadbatch(no_timesteps,list_of_file_paths,batch_size):
      nof=no_timesteps# No of combined
      files=list_of_file_paths
      files=shuffle_list(files)
      classes=get_class_number(files)
      temp_batch=np.zeros(shape=(batch_size,no_timesteps,4096),dtype=np.float32)
      temp_classes=np.zeros(shape=(batch_size,101),dtype=np.float32)
      bat_num=0
      fileno=0
      while bat_num != batch_size :
          if os.path.isfile(str(files[fileno])):
              val=np.load(str(files[fileno]))
              try:
                  if val.shape[0]&gt;no_timesteps+2:
                      num=random.randint(0,val.shape[0]-(no_timesteps+2))
                      temp_batch[bat_num,:,:]=val[num:num+nof,:]
                      temp_classes[bat_num,:]=create_one_hot(classes[fileno])
                      bat_num=bat_num+1
              except Exception as ex:
                  fileno=fileno+1
          fileno=fileno+1
      return np.maximum(np.tanh(temp_batch), 0),temp_classes #normalize in range 0-&gt;1
  </code></pre>