SAE / datasets /imagenet100label.py
Ttius's picture
Upload 192 files
998bb30 verified
# There is an iamgenet mapping of classes and filename
imagenet_label_path = "you_path/map_clsloc.txt" # ImageNet class mapping file
train_file_path = "you_path/train.txt" # ImageNet100 train classes
eval_file_path = "you_path/train.txt" # ImageNet100 eval classes
label_dict = {}
with open(imagenet_label_path, 'r') as f:
for line in f:
folder_name, label, class_name = line.strip().split(',')
label_dict[folder_name] = (label, class_name)
def update_file(input_file_path, output_file_path):
with open(input_file_path, 'r') as infile, open(output_file_path, 'w') as outfile:
folder_name = None
for line in infile:
line = line.strip()
if line in label_dict:
folder_name = line
label, class_name = label_dict[folder_name]
outfile.write(f"{folder_name},{label},{class_name}\n")
update_file(train_file_path, "you_path/map_clsloc_imagenet100_train.txt")
update_file(eval_file_path, "you_path/map_clsloc_imagenet100_eval.txt")
print("Files have been updated.")