1+ """
2+ # Created: 2023-12-31 22:19
3+ # LastEdit: 2024-01-12 18:46
4+ # Copyright (C) 2023-now, RPL, KTH Royal Institute of Technology
5+ # Author: Qingwen Zhang (https://kin-zhang.github.io/)
6+
7+ # Description:
8+ # Quick Read the keys in an h5 file, print out their shapes and data types etc.
9+
10+ # Example Running:
11+ python tools/readh5pkl.py --file_path /home/kin/data/av2/h5py/sensor/test/0c6e62d7-bdfa-3061-8d3d-03b13aa21f68.h5
12+ """
13+
14+ import os , pickle
15+ os .environ ["OMP_NUM_THREADS" ] = "1"
16+ import fire , time , h5py
17+
18+ def readfile (
19+ file_path : str = "/home/kin/data/av2/h5py/sensor/test/0c6e62d7-bdfa-3061-8d3d-03b13aa21f68.h5"
20+ ):
21+ if file_path .endswith ('.h5' ):
22+ with h5py .File (file_path , 'r' ) as f :
23+ for cnt , k in enumerate (f .keys ()):
24+ if cnt % 2 == 1 :
25+ continue
26+ print (f"id: { cnt } ; Key (TimeStamp): { k } " )
27+ for sub_k in f [k ].keys ():
28+ print (f" Sub-Key: { sub_k } , Shape: { f [k ][sub_k ].shape } , Dtype: { f [k ][sub_k ].dtype } " )
29+ if cnt >= 10 :
30+ break
31+ print (f"\n Total { len (f .keys ())} timestamps in the file." )
32+ elif file_path .endswith ('.pkl' ):
33+ with open (file_path , 'rb' ) as f :
34+ data_index = pickle .load (f )
35+ for cnt , (scene_token , timestamp ) in enumerate (data_index ):
36+ if cnt % 2 == 1 :
37+ continue
38+ print (f"id: { cnt } ; Scene Token: { scene_token } , Timestamp: { timestamp } " )
39+ if cnt >= 10 :
40+ break
41+ print (f"\n Total { len (data_index )} timestamps in the file." )
42+
43+ if __name__ == '__main__' :
44+ start_time = time .time ()
45+ fire .Fire (readfile )
46+ print (f"\n Time used: { (time .time () - start_time )/ 60 :.2f} mins" )
0 commit comments