Skip to content

Instantly share code, notes, and snippets.

@XericZephyr
Created October 27, 2015 01:35
Show Gist options
  • Save XericZephyr/cf449eaab99aa5af2425 to your computer and use it in GitHub Desktop.
Save XericZephyr/cf449eaab99aa5af2425 to your computer and use it in GitHub Desktop.
Prepare list file on TACC for imagenet
__author__ = 'zhengxu'
import os
import glob
import pickle
def make_record_io_list(image_net_folder, label_list_file, list_file):
label_list = os.listdir(image_net_folder)
with open(label_list_file, 'w') as f:
pickle.dump(label_list, f)
current_index = 0
with open(list_file, 'w') as f:
for i, label in enumerate(label_list):
file_list = glob.glob(os.path.join(image_net_folder, label, '*.JPEG'))
file_list_len = len(file_list)
index_list = list(range(current_index, current_index + file_list_len))
current_index += file_list_len
string_list = zip(index_list, [i] * file_list_len, file_list)
for str_tup in string_list:
f.write("%d\t%d\t%s\r\n" % str_tup)
if __name__ == '__main__':
TRAIN_DIR = '/work/03332/zhengxu/Data/ImageNet/ilsvrc12/train'
VAL_DIR = '/work/03332/zhengxu/Data/ImageNet/ilsvrc12/val'
# make_record_io_list(TRAIN_DIR, TRAIN_DIR+'/label_list.pickle', TRAIN_DIR+'/train.lst')
make_record_io_list(VAL_DIR, VAL_DIR+'/label_list.pickle', VAL_DIR+'/train.lst')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment