plot_model.py
Go to the documentation of this file.
1 """
2 This is the plot module.
3 """
4 
5 __version__ = '1.0'
6 __author__ = 'Saul Alonso-Monsalve'
7 __email__ = "saul.alonso.monsalve@cern.ch"
8 
9 import configparser
10 import ast
11 import re
12 import logging
13 import sys
14 
15 from os import listdir
16 from os.path import isfile, join
17 from keras.models import load_model
18 from keras.utils import plot_model
19 
20 '''
21 ****************************************
22 ************** PARAMETERS **************
23 ****************************************
24 '''
25 
26 logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
27 
28 config = configparser.ConfigParser()
29 config.read('config/config.ini')
30 
31 # model
32 
33 CHECKPOINT_PATH = config['model']['checkpoint_path']
34 CHECKPOINT_PREFIX = config['model']['checkpoint_prefix']
35 CHECKPOINT_SAVE_MANY = ast.literal_eval(config['model']['checkpoint_save_many'])
36 CHECKPOINT_SAVE_BEST_ONLY = ast.literal_eval(config['model']['checkpoint_save_best_only'])
37 PRINT_SUMMARY = ast.literal_eval(config['model']['print_summary'])
38 
39 
40 '''
41 ****************************************
42 ************** LOAD MODEL **************
43 ****************************************
44 '''
45 
46 # Load model
47 
48 logging.info('Loading model from disk...')
49 
50 if CHECKPOINT_SAVE_MANY:
51 
52  # Load the last generated model
53 
54  files = [f for f in listdir(CHECKPOINT_PATH) if isfile(join(CHECKPOINT_PATH, f))]
55  files.sort(reverse=True)
56 
57  r = re.compile(CHECKPOINT_PREFIX[1:] + '-.*-.*.h5')
58 
59  for fil in files:
60  if r.match(fil) is not None:
61  model = load_model(CHECKPOINT_PATH + '/' + fil)
62  break
63 
64 else:
65 
66  # Load the model
67 
68  model = load_model(CHECKPOINT_PATH + CHECKPOINT_PREFIX + '.h5')
69 
70 # Print model summary
71 
72 if(PRINT_SUMMARY):
73  model.summary()
74 
75 plot_model(model, to_file='model.pdf', show_shapes='True')
def load_model(name)
if(!yymsg) yymsg