''' 1. Please first extract RGB folder in each video folder in each scene folder and organize as below: |-- RGB_file |-- 1 |-- 1.1 ... |-- 1.4 # (end of folder) | |-- 2 |-- 2.1 |-- color (folder) # |-- 2.2 |-- color # |-- 2.3 |-- color # |-- 2.4 |-- color # |-- 2.5 |-- color # | ... | |-- 11 |-- 11.1 ... |-- 11.5 # | # and run the code below ''' import h5py import numpy as np import io from PIL import Image import os from tqdm import tqdm f = h5py.File("RGB_dataset.hdf5", "w") # saving path: f["color/scene/video/"] # color path: color_file_path = "RGB_file" color_grp = f.require_group("color") for scene in tqdm(os.listdir(color_file_path)): print(scene) scene_file_path = os.path.join(color_file_path, scene) scene_grp = color_grp.require_group(scene) for video in tqdm(os.listdir(scene_file_path)): if video=="groundtruth": continue video_grp = scene_grp.require_group(video) video_color_path = os.path.join(scene_file_path,video,"color") for image in tqdm(os.listdir(video_color_path)): img_path = os.path.join(video_color_path, image) with open(img_path, 'rb') as img_f: binary_data = img_f.read() binary_data_np = np.asarray(binary_data) dset = video_grp.create_dataset(f'{image[:-4]}', data=binary_data_np) f.close()