| import h5py |
| import numpy as np |
| import cv2 |
| import os |
|
|
| def verify_h5(file_path): |
| if not os.path.exists(file_path): |
| print(f"File not found: {file_path}") |
| return |
|
|
| with h5py.File(file_path, 'r') as f: |
| print(f"Keys: {list(f.keys())}") |
| for key in f.keys(): |
| print(f"{key} shape: {f[key].shape}") |
| |
| num_samples = f['left_patches'].shape[0] |
| if num_samples == 0: |
| print("No samples found.") |
| return |
| |
| |
| for i in range(min(num_samples, 5)): |
| lp = f['left_patches'][i] |
| rp = f['right_patches'][i] |
| lg = f['left_gaze'][i] |
| rg = f['right_gaze'][i] |
| |
| |
| |
| l_combined = np.zeros((16, 16), dtype='uint8') |
| l_combined[0:8, 0:8] = lp[0] |
| l_combined[0:8, 8:16] = lp[1] |
| l_combined[8:16, 0:8] = lp[2] |
| l_combined[8:16, 8:16] = lp[3] |
| |
| r_combined = np.zeros((16, 16), dtype='uint8') |
| r_combined[0:8, 0:8] = rp[0] |
| r_combined[0:8, 8:16] = rp[1] |
| r_combined[8:16, 0:8] = rp[2] |
| r_combined[8:16, 8:16] = rp[3] |
| |
| |
| l_view = cv2.resize(l_combined, (128, 128), interpolation=cv2.INTER_NEAREST) |
| r_view = cv2.resize(r_combined, (128, 128), interpolation=cv2.INTER_NEAREST) |
| |
| |
| info = np.zeros((128, 400), dtype='uint8') |
| cv2.putText(info, f"Sample {i}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, 255, 2) |
| cv2.putText(info, f"L Gaze: {lg[0]:.3f}, {lg[1]:.3f}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.6, 255, 1) |
| cv2.putText(info, f"R Gaze: {rg[0]:.3f}, {rg[1]:.3f}", (10, 90), cv2.FONT_HERSHEY_SIMPLEX, 0.6, 255, 1) |
| |
| combined = np.hstack([l_view, r_view, info]) |
| output_dir = 'data/verification' |
| os.makedirs(output_dir, exist_ok=True) |
| output_path = os.path.join(output_dir, f"sample_{i}.png") |
| cv2.imwrite(output_path, combined) |
| print(f"Saved verification image to {output_path}") |
| print(f"Sample {i}: Left Gaze {lg}, Right Gaze {rg}") |
| |
| |
|
|
| if __name__ == '__main__': |
| import argparse |
| parser = argparse.ArgumentParser() |
| parser.add_argument('--file', type=str, default='data/processed/p00.h5') |
| args = parser.parse_args() |
| verify_h5(args.file) |
|
|