'Create index file for dataloader.'

def run(self):

    if os.path.exists(self.index_file):
        return
    logger.warning(('%s    not    found.    Attempting    to    create...' % self.index_file))
    assert os.path.exists(self.path)
    subdirs = glob.iglob(os.path.join(self.path, '*'))
    subdirs = [x for x in subdirs if os.path.isdir(x)]
    classes = sorted([os.path.basename(x) for x in subdirs])
    class_map = {key: val for (key, val) in zip(classes, list(range(len(classes))))}
    with open(self.index_file, 'w') as fd:
        fd.write('filename,label1\n')
        for subdir in subdirs:
            label = class_map[os.path.basename(subdir)]
            files = glob.iglob(os.path.join(subdir, self.pattern))
            for filename in files:
                rel_path = os.path.join(os.path.basename(subdir), os.path.basename(filename))
                fd.write((((rel_path + ',') + str(label)) + '\n'))
    logger.info(('Created    index    file:    %s' % self.index_file))
