| import os |
| import json |
|
|
| mini_global_path = '/scratch/yuqian_fu/Data/CDFSL/miniImagenet/' |
|
|
| |
| def miniImg(flag='test'): |
| file_path = mini_global_path + flag + '.json' |
| with open(file_path, 'r') as file: |
| data = json.load(file) |
|
|
| print(data.keys()) |
| image_names = data['image_names'] |
| lengthes = len(image_names) |
| print(lengthes) |
|
|
| for i in range(lengthes): |
| print(image_names[i]) |
| splits = image_names[i].split('\n') |
| print(splits) |
| if (flag == 'novel'): |
| new_line = mini_global_path + 'test' + '/n' + splits[-2] + '/n' + splits[-1] |
| else: |
| new_line = mini_global_path + flag + '/n' + splits[-2] + '/n' + splits[-1] |
| print(new_line) |
| if os.path.exists(new_line): |
| pass |
| else: |
| print('file:', new_line, 'does not exist!') |
| break |
| data['image_names'][i] = new_line |
|
|
| with open(file_path, 'w') as file: |
| json.dump(data, file, indent=4) |
|
|
|
|
| with open(file_path, 'r') as file: |
| data = json.load(file) |
|
|
| for i in range(lengthes): |
| print(data['image_names'][i]) |
| return |
|
|
|
|
| |
| mini_global_path_cub = '/scratch/yuqian_fu/Data/CDFSL/cub/' |
| def cub(flag='base'): |
| file_path = mini_global_path_cub + flag + '.json' |
| with open(file_path, 'r') as file: |
| data = json.load(file) |
|
|
| print(data.keys()) |
| image_names = data['image_names'] |
| lengthes = len(image_names) |
| print(lengthes) |
|
|
| for i in range(lengthes): |
| print(image_names[i]) |
| new_line = image_names[i].replace('/wy_test/qiuxingyu/CrossDomainFewShot/filelists/cub/', mini_global_path_cub) |
| print(new_line) |
| if os.path.exists(new_line): |
| pass |
| else: |
| print('file:', new_line, 'does not exist!') |
| break |
| data['image_names'][i] = new_line |
|
|
| with open(file_path, 'w') as file: |
| json.dump(data, file, indent=4) |
|
|
| with open(file_path, 'r') as file: |
| data = json.load(file) |
| for i in range(lengthes): |
| print(data['image_names'][i]) |
| return |
|
|
| |
| mini_global_path_cars = '/scratch/yuqian_fu/Data/CDFSL/cars/' |
| def cars(flag='base'): |
| file_path = mini_global_path_cars + flag + '.json' |
| with open(file_path, 'r') as file: |
| data = json.load(file) |
|
|
| print(data.keys()) |
| image_names = data['image_names'] |
| lengthes = len(image_names) |
| print(lengthes) |
|
|
| for i in range(lengthes): |
| print(image_names[i]) |
| new_line = image_names[i].replace('/wy_test/qiuxingyu/CrossDomainFewShot/filelists/cars/', mini_global_path_cars) |
| print(new_line) |
| if os.path.exists(new_line): |
| pass |
| else: |
| print('file:', new_line, 'does not exist!') |
| break |
| data['image_names'][i] = new_line |
|
|
| with open(file_path, 'w') as file: |
| json.dump(data, file, indent=4) |
|
|
| with open(file_path, 'r') as file: |
| data = json.load(file) |
| for i in range(lengthes): |
| print(data['image_names'][i]) |
| return |
| |
|
|
|
|
| |
| |
| mini_global_path_places = '/scratch/yuqian_fu/Data/CDFSL/places/' |
| def places(flag='base'): |
| file_path = mini_global_path_places + flag + '.json' |
| with open(file_path, 'r') as file: |
| data = json.load(file) |
|
|
| print(data.keys()) |
| image_names = data['image_names'] |
| lengthes = len(image_names) |
| print(lengthes) |
|
|
| for i in range(lengthes): |
| print(image_names[i]) |
| |
| new_line = image_names[i].replace('places365_standard', 'places') |
| print(new_line) |
| if os.path.exists(new_line): |
| pass |
| else: |
| print('file:', new_line, 'does not exist!') |
| break |
| data['image_names'][i] = new_line |
|
|
| with open(file_path, 'w') as file: |
| json.dump(data, file, indent=4) |
|
|
| with open(file_path, 'r') as file: |
| data = json.load(file) |
| for i in range(lengthes): |
| print(data['image_names'][i]) |
| return |
|
|
| |
| |
| mini_global_path_plantae = '/scratch/yuqian_fu/Data/CDFSL/plantae/' |
| def plantae(flag='base'): |
| file_path = mini_global_path_plantae + flag + '.json' |
| with open(file_path, 'r') as file: |
| data = json.load(file) |
|
|
| print(data.keys()) |
| image_names = data['image_names'] |
| lengthes = len(image_names) |
| print(lengthes) |
|
|
| for i in range(lengthes): |
| print(image_names[i]) |
| |
| new_line = image_names[i].replace('Plantae', 'plantae') |
| print(new_line) |
| if os.path.exists(new_line): |
| pass |
| else: |
| print('file:', new_line, 'does not exist!') |
| break |
| data['image_names'][i] = new_line |
|
|
| with open(file_path, 'w') as file: |
| json.dump(data, file, indent=4) |
|
|
| with open(file_path, 'r') as file: |
| data = json.load(file) |
| for i in range(lengthes): |
| print(data['image_names'][i]) |
| return |
|
|
|
|
|
|
| if __name__ == '__main__': |
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| plantae(flag='base') |
| plantae(flag='val') |
| plantae(flag='novel') |
| |
|
|
|
|
|
|
|
|