<s> try : <EOL> from bokeh . plotting import figure <EOL> from bokeh . palettes import brewer <EOL> from bokeh . models import Range1d <EOL> from bokeh . embed import components <EOL> from jinja2 import Template <EOL> except ImportError : <EOL> pass <EOL> def x_label ( epoch_axis ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" if epoch_axis else "<STR_LIT>" <EOL> def cost_fig ( cost_data , plot_height , plot_width , epoch_axis = True ) : <EOL> """<STR_LIT>""" <EOL> fig = figure ( plot_height = plot_height , <EOL> plot_width = plot_width , <EOL> title = "<STR_LIT>" , <EOL> x_axis_label = x_label ( epoch_axis ) , <EOL> y_axis_label = "<STR_LIT>" ) <EOL> num_colors_required = len ( cost_data ) <EOL> assert num_colors_required <= <NUM_LIT:11> , "<STR_LIT>" <EOL> colors = list ( brewer [ "<STR_LIT>" ] [ max ( <NUM_LIT:3> , len ( cost_data ) ) ] ) <EOL> if num_colors_required < <NUM_LIT:3> : <EOL> colors [ <NUM_LIT:0> ] = brewer [ "<STR_LIT>" ] [ <NUM_LIT:6> ] [ <NUM_LIT:0> ] <EOL> if num_colors_required == <NUM_LIT:2> : <EOL> colors [ <NUM_LIT:1> ] = brewer [ "<STR_LIT>" ] [ <NUM_LIT:6> ] [ - <NUM_LIT:1> ] <EOL> for name , x , y in cost_data : <EOL> fig . line ( x , y , legend = name , color = colors . pop ( <NUM_LIT:0> ) , line_width = <NUM_LIT:2> ) <EOL> return fig <EOL> def hist_fig ( hist_data , plot_height , plot_width , x_range = None , epoch_axis = True ) : <EOL> """<STR_LIT>""" <EOL> name , hdata , dh , dw , bins , offset = hist_data <EOL> if x_range is None : <EOL> x_range = ( <NUM_LIT:0> , dw ) <EOL> fig = figure ( plot_height = plot_height , <EOL> plot_width = plot_width , <EOL> title = name , <EOL> x_axis_label = x_label ( epoch_axis ) , <EOL> x_range = x_range , <EOL> y_range = ( offset , offset + bins ) ) <EOL> fig . image ( image = [ hdata ] , x = [ <NUM_LIT:0> ] , y = [ offset ] , dw = [ dw ] , dh = [ dh ] , palette = "<STR_LIT>" ) <EOL> return fig <EOL> def image_fig ( data , h , w , x_range , y_range , plot_size ) : <EOL> fig = figure ( x_range = x_range , y_range = y_range , <EOL> plot_width = plot_size , plot_height = plot_size , <EOL> toolbar_location = None ) <EOL> fig . image_rgba ( [ data ] , x = [ <NUM_LIT:0> ] , y = [ <NUM_LIT:0> ] , dw = [ w ] , dh = [ h ] ) <EOL> fig . axis . visible = None <EOL> fig . min_border = <NUM_LIT:0> <EOL> return fig <EOL> def deconv_figs ( layer_name , layer_data , fm_max = <NUM_LIT:8> , plot_size = <NUM_LIT> ) : <EOL> vis_keys = dict ( ) <EOL> img_keys = dict ( ) <EOL> fig_dict = dict ( ) <EOL> for fm_num , ( fm_name , deconv_data , img_data ) in enumerate ( layer_data ) : <EOL> if fm_num >= fm_max : <EOL> break <EOL> img_h , img_w = img_data . shape <EOL> x_range = Range1d ( start = <NUM_LIT:0> , end = img_w ) <EOL> y_range = Range1d ( start = <NUM_LIT:0> , end = img_h ) <EOL> img_fig = image_fig ( img_data , img_h , img_w , x_range , y_range , plot_size ) <EOL> deconv_fig = image_fig ( deconv_data , img_h , img_w , x_range , y_range , plot_size ) <EOL> title = "<STR_LIT>" . format ( layer_name , fm_num ) <EOL> vis_keys [ fm_num ] = "<STR_LIT>" + title <EOL> img_keys [ fm_num ] = "<STR_LIT>" + title <EOL> fig_dict [ vis_keys [ fm_num ] ] = deconv_fig <EOL> fig_dict [ img_keys [ fm_num ] ] = img_fig <EOL> return vis_keys , img_keys , fig_dict <EOL> def deconv_summary_page ( filename , cost_data , deconv_data ) : <EOL> fig_dict = dict ( ) <EOL> cost_key = "<STR_LIT>" <EOL> fig_dict [ cost_key ] = cost_fig ( cost_data , <NUM_LIT> , <NUM_LIT> , epoch_axis = True ) <EOL> vis_keys = dict ( ) <EOL> img_keys = dict ( ) <EOL> for layer , layer_data in deconv_data : <EOL> lyr_vis_keys , lyr_img_keys , lyr_fig_dict = deconv_figs ( layer , layer_data , fm_max = <NUM_LIT:4> ) <EOL> vis_keys [ layer ] = lyr_vis_keys <EOL> img_keys [ layer ] = lyr_img_keys <EOL> fig_dict . update ( lyr_fig_dict ) <EOL> script , div = components ( fig_dict ) <EOL> template = Template ( '''<STR_LIT>''' ) <EOL> with open ( filename , '<STR_LIT:w>' ) as htmlfile : <EOL> htmlfile . write ( template . render ( page_title = "<STR_LIT>" , script = script , <EOL> div = div , cost_key = cost_key , vis_keys = vis_keys , <EOL> img_keys = img_keys , <EOL> sorted_layers = sorted ( vis_keys ) ) ) </s>
