Downloading our training file took a long time. Even extracting all the images took a while. To avoid repeating all this, we will try to do all the work just once and then create pickle files—archives of the Python data structures.
The following procedure runs through each class in our training and test set and creates a separate pickle file for each. In future runs, we'll just begin from here:
def makePickle(imgSrcPath): data_folders = [os.path.join(tst_files, d) for d in
os.listdir(tst_files) if os.path.isdir(os.path.join(tst_files,
d))] dataset_names = [] for folder in data_folders: set_filename = folder + '.pickle' dataset_names.append(set_filename) print('Pickling %s.' % set_filename) dataset = loadClass(folder) try: with open(set_filename, 'wb') as f: pickle.dump(dataset, f, pickle.HIGHEST_PROTOCOL) except Exception as e: print('Unable to save data to', set_filename, ':', e) return dataset_names
The Pickle files are essentially persistable and reconstitutable dumps of dictionaries.