Exemplo n.º 1
0
def tab(filename="info"):
    '''
    分页组件
    '''
    tab = Tab()
    tab.add(liquid_data_precision("111"), "前日留存")
    tab.add(bar_datazoom_slider("222"), "分端留存")
    tab.add(table_base("222"), "明细")
    tab.add(line_markpoint("222"), "人群留存")
    tab.add(pie_rosetype("222"), "城市")
    tab.add(grid_mutil_yaxis("222"), "新增留存")
    tab.render_notebook()
    tab.render('{}.html'.format(filename))
Exemplo n.º 2
0
def test_tab_render_notebook():
    tab = Tab()
    tab.add(_create_line(), "line-example")
    tab.add(_create_bar(), "bar-example")
    tab.add(_create_table(), "table-example")
    html = tab.render_notebook().__html__()
    assert_in("City name", html)
Exemplo n.º 3
0
def visualize_layer(model, image, layer_name, layer_max_image=32, jupyter=True, path='visualize_layer.html'):
    """network layer visualize.
    
    Args:
        model: a tf.keras model or keras model.
        image: a image array with shape (1, height, width, channel), height and width are necessary.
        layer_name: a list of model layers name.
        layer_max_image: every layer max plot images.
        jupyter: if plot in jupyter, default True.
        path: if jupyter is False, result save a html file.
    Returns:
        A pyecharts polt object.
    """
    if tf.io.gfile.exists('feature_map'):
        tf.io.gfile.rmtree('feature_map')
    tf.io.gfile.makedirs('feature_map')
    if np.ndim(image)==2:
        image = tf.expand_dims(tf.expand_dims(image, 0), -1)
    elif np.ndim(image)==3:
        image = tf.expand_dims(image, 0)
    elif np.ndim(image)==4:
        pass
    else:
        raise ValueError('image shape is error.')
    temp_model = tf.keras.backend.function(model.inputs, [i.output for i in model.layers if i.name in layer_name])
    temp_name = [i.name for i in model.layers if i.name in layer_name]
    result = temp_model(image)
    images_per_row = 16
    count = 0
    name_dict = {}
    tab = Tab()
    for feature, name in zip(result, temp_name):
        if feature.ndim==4:
            if feature.shape[-1]==3:
                display_grid = feature[0,:,:,:].astype('uint8')
            else:
                n_features = feature.shape[-1] if feature.shape[-1]<layer_max_image else layer_max_image
                size = feature.shape[1]
                n_cols = int(np.ceil(n_features/images_per_row))
                display_grid = np.ones((size * n_cols, images_per_row * size),dtype=np.uint8)*255
                for col in range(n_cols):
                    for row in range(images_per_row):
                        if (col+1)*(row+1)>n_features:
                            break
                        channel_image = feature[0, :, :, col * images_per_row + row]
                        channel_image -= channel_image.mean()
                        channel_image /= channel_image.std()
                        channel_image *= 64
                        channel_image += 128
                        channel_image = np.clip(channel_image, 0, 255).astype('uint8')
                        display_grid[col * size : (col + 1) * size, row * size : (row + 1) * size] = channel_image
                display_grid = np.expand_dims(display_grid, axis=-1)
            name_dict[name] = f'./feature_map/{count}.png'
            ImageAug(display_grid).save_image(name_dict[name])
            tab.add(image_base(name_dict[name], name, 'shape='+str(feature.shape)), name)
        count += 1
    return tab.render_notebook() if jupyter else tab.render(path)
Exemplo n.º 4
0
def visualize_heatmaps(model, image, layer_name, jupyter=True, path='visualize_heatmaps.html'):
    """network layer visualize.
    
    Args:
        model: a tf.keras model or keras model.
        image: a image array with shape (1, height, width, channel), height and width are necessary.
        layer_name: a list of model layers name.
        jupyter: if plot in jupyter, default True.
        path: if jupyter is False, result save a html file.
    Returns:
        A pyecharts polt object.
    """
    if tf.io.gfile.exists('feature_map'):
        tf.io.gfile.rmtree('feature_map')
    tf.io.gfile.makedirs('feature_map')
    if np.ndim(image)==2:
        image = tf.expand_dims(tf.expand_dims(image, 0), -1)
    elif np.ndim(image)==3:
        image = tf.expand_dims(image, 0)
    elif np.ndim(image)==4:
        pass
    else:
        raise ValueError('image shape is error.')
    temp_model = tf.keras.backend.function(model.inputs, [i.output for i in model.layers if i.name in layer_name])
    temp_name = [i.name for i in model.layers if i.name in layer_name]
    result = temp_model(image)
    images_per_row = 16
    count = 0
    name_dict = {}
    tab = Tab()
    for feature, name in zip(result, temp_name):
        if feature.ndim==4:
            if model.get_layer(name).__class__.__name__=='InputLayer':
                out = np.squeeze(image, 0).astype('uint8')
            else:
                out = tf.image.resize(tf.expand_dims(tf.squeeze(tf.reduce_sum(tf.abs(feature), axis=-1)), axis=-1), (image.shape[1], image.shape[2]))
                out = 255-tf.cast(out/tf.reduce_max(out)*255., tf.uint8)
    #             print(np.squeeze(image, 0).shape)
                out = addWeighted(applyColorMap(out.numpy(), COLORMAP_JET), 0.7, np.squeeze(image, 0).astype('uint8'), 0.3, 0)
    #             out = np.expand_dims(out, axis=-1)
            name_dict[name] = f'./feature_map/{count}.png'
            ImageAug(out).save_image(name_dict[name])
            tab.add(image_base(name_dict[name], name, 'shape='+str(feature.shape)), name)
        count += 1
    return tab.render_notebook() if jupyter else tab.render(path)
Exemplo n.º 5
0
                is_show=True)),
        ))
    return c  #返回数据


effectscatter_symbol().render_notebook()

tab = Tab()  #添加tab
tab.add(teachers_map(), "特殊教育专任教师数")
tab.add(schools_map(), "各省特殊教育学校数")
tab.add(recruit_students_map(), "各省特殊教育招生数")
tab.add(all(), "教育支出与特殊教育在校学生详情")
tab.add(finacial_education_map(), "地方财政教育支出")
tab.add(four_compare(), "四个不同省份对比")
tab.add(effectscatter_symbol(), "四川特殊教育基本情况")
tab.render_notebook()


@app.route('/', endpoint='r1', redirect_to='/index')
def root():
    return render_template('index.html')


@app.route('/index')
def index():
    return render_template('index.html')


@app.route('/local_expense')
def local_expense():
    c = tab = Tab()
Exemplo n.º 6
0
            title_opts=opts.TitleOpts(title="Grid-多 Y 轴示例"),
            tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
        )
    )

    line = (
        Line()
        .add_xaxis(x_data)
        .add_yaxis(
            "平均温度",
            [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
            yaxis_index=2,
            color="#675bba",
            label_opts=opts.LabelOpts(is_show=False),
        )
    )

    bar.overlap(line)
    return Grid().add(
        bar, opts.GridOpts(pos_left="5%", pos_right="20%"), is_control_axis_index=True
    )


tab = Tab()
tab.add(bar_datazoom_slider(), "bar-example")
tab.add(line_markpoint(), "line-example")
tab.add(pie_rosetype(), "pie-example")
tab.add(grid_mutil_yaxis(), "grid-example")
put_html(tab.render_notebook())