1
+ #! /usr/bin/env python
2
+
3
+ ###############################################################################
4
+ # keras_examine_weights.py
5
+ #
6
+ # script to examine the weights saved by Keras as .h5f file
7
+ #
8
+ # Modified from:
9
+ # https://github.com/fchollet/keras/issues/91
10
+ #
11
+ # NOTE: Any plotting is set up for output, not viewing on screen.
12
+ # So, it will likely be ugly on screen. The saved PDFs should look
13
+ # better.
14
+ #
15
+ # Created: 07/14/17
16
+ # - Joshua Vaughan
17
+
18
+ # - http://www.ucs.louisiana.edu/~jev9637
19
+ #
20
+ # Modified:
21
+ # *
22
+ #
23
+ # TODO:
24
+ # *
25
+ ###############################################################################
26
+
27
+ from __future__ import print_function
28
+
29
+ import numpy as np
30
+ import matplotlib .pyplot as plt
31
+
32
+ import h5py
33
+
34
+ FILENAME = '../OpenAI Gym/weights/ddpg_planar_crane_continuous-v0_weights_2048_3_100000_2017-07-14_163738_actor.h5f'
35
+
36
+ def print_structure (weight_file_path ):
37
+ """
38
+ Prints out the structure of HDF5 file.
39
+
40
+ Args:
41
+ weight_file_path (str) : Path to the file to analyze
42
+ """
43
+ f = h5py .File (weight_file_path )
44
+ try :
45
+ if len (f .attrs .items ()):
46
+ print ("{} contains: " .format (weight_file_path ))
47
+ print ("Root attributes:" )
48
+ for key , value in f .attrs .items ():
49
+ print (" {}: {}" .format (key , value ))
50
+
51
+ if len (f .items ())== 0 :
52
+ return
53
+
54
+ for layer , g in f .items ():
55
+ print (" {}" .format (layer ))
56
+ print (" Attributes:" )
57
+ for key , value in g .attrs .items ():
58
+ print (" {}: {}" .format (key , value ))
59
+
60
+ print (" Dataset:" )
61
+ for p_name in g .keys ():
62
+ param = g [p_name ]
63
+ print (" {}: {}" .format (p_name , param ))
64
+ finally :
65
+ f .close ()
66
+
67
+ if __name__ == '__main__' :
68
+ print_structure (FILENAME )
0 commit comments