|
|
| imagenet_label_path = "you_path/map_clsloc.txt"
|
| train_file_path = "you_path/train.txt"
|
| eval_file_path = "you_path/train.txt"
|
|
|
| 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.")
|
|
|