Total Complexity | 0 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import h5py |
||
2 | |||
3 | filename = "my_model_weights_noTraining.h5" |
||
4 | |||
5 | with h5py.File(filename, "r") as f: |
||
6 | # Print all root level object names (aka keys) |
||
7 | # these can be group or dataset names |
||
8 | print("Keys: %s" % f.keys()) |
||
9 | # get first object name/key; may or may NOT be a group |
||
10 | a_group_key = list(f.keys())[0] |
||
11 | |||
12 | # get the object type for a_group_key: usually group or dataset |
||
13 | print("\n type a_group_key \n", type(f[a_group_key]), "\n") |
||
14 | |||
15 | # If a_group_key is a group name, |
||
16 | # this gets the object names in the group and returns as a list |
||
17 | data = list(f[a_group_key]) |
||
18 | |||
19 | # If a_group_key is a dataset name, |
||
20 | # this gets the dataset values and returns as a list |
||
21 | data = list(f[a_group_key]) |
||
22 | print("\n data \n", data, "\n") |
||
23 | # preferred methods to get dataset values: |
||
24 | ds_obj = f[a_group_key] # returns as a h5py dataset object |
||
25 |