| 991 | self.readable_label(labels, save_file, hierarchy=True) |
| 992 | |
| 993 | def valid_image_preprocess(self, image_path, meta_path, save_file): |
| 994 | from scipy.io import loadmat |
| 995 | |
| 996 | image_files = glob.glob(os.path.join(image_path, "*.JPEG")) |
| 997 | if len(image_files) == 0: |
| 998 | return image_path |
| 999 | |
| 1000 | logger.info("re-arranging images into sub-folders") |
| 1001 | |
| 1002 | image_files = sorted(image_files) |
| 1003 | meta_file = os.path.join(meta_path, "ILSVRC2012_devkit_t12/data/meta.mat") |
| 1004 | id_file = os.path.join(meta_path, "ILSVRC2012_devkit_t12/data/ILSVRC2012_validation_ground_truth.txt") |
| 1005 | metas = loadmat(meta_file, squeeze_me=True)["synsets"][:1000] |
| 1006 | id2class = {meta[0]: meta[1] for meta in metas} |
| 1007 | ids = np.loadtxt(id_file) |
| 1008 | labels = [id2class[id] for id in ids] |
| 1009 | for image_file, label in zip(image_files, labels): |
| 1010 | class_path = os.path.join(image_path, label) |
| 1011 | if not os.path.exists(class_path): |
| 1012 | os.mkdir(class_path) |
| 1013 | shutil.move(image_file, class_path) |
| 1014 | |
| 1015 | return image_path |
| 1016 | |
| 1017 | def valid_feature_data_preprocess(self, save_file): |
| 1018 | numpy_file = os.path.splitext(save_file)[0] + ".npy" |