'For python 2.x.
# Returns
The next batch.'

def next(self):

    with self.lock:
        (index_array, current_index, current_batch_size) = next(self.index_generator)
    batch_x = np.zeros(tuple(([current_batch_size] + list(self.x.shape)[1:])), dtype=K.floatx())
    for (i, j) in enumerate(index_array):
        x = self.x[j]
        x = self.image_data_generator.random_transform(x.astype(K.floatx()))
        x = self.image_data_generator.standardize(x)
        batch_x[i] = x
    if self.save_to_dir:
        for i in range(current_batch_size):
            img = array_to_img(batch_x[i], self.data_format, scale=True)
            fname = '{prefix}_{index}_{hash}.{format}'.format(prefix=self.save_prefix, index=(current_index + i), hash=np.random.randint(10000.0), format=self.save_format)
            img.save(os.path.join(self.save_to_dir, fname))
    if (self.y is None):
        return batch_x
    batch_y = self.y[index_array]
    return (batch_x, batch_y)
