小编Seb*_*eza的帖子

Bokeh服务器回调工具

我是Python的新手,目前正在使用Bokeh进行交互式绘图可视化,我需要显示多个相关图表.为了实现这一点,我正在使用散景服务器.

我一直在阅读文档和一些示例,但我一直无法找到由绘图上的选择触发的python回调(在服务器中执行)的示例.基本上我想做的是:

from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource

TOOLS = "tap"
p = figure(title="Some Figure", tools=TOOLS)

source = ColumnDataSource(dict(x=[[1, 3, 2], [3, 4, 6, 6]], y=[[2, 1, 4], [4, 7, 8, 5]], name=['A', 'B']))

p.patches('x', 'y', source=source, color=["firebrick", "navy"], alpha=[0.8, 0.3], line_width=2)


def callback():
    print("TapTool callback executed on Patch {}")


??? <- some code here linking the taptool with the callback function defined above


curdoc().add_root(column(p))
Run Code Online (Sandbox Code Playgroud)

然后在执行服务器并单击补丁时:

2017-02-14 16:32:00,000在补丁A上执行TapTool回调

这种行为可以用散景来实现吗?

python callback python-3.x bokeh

6
推荐指数
1
解决办法
4628
查看次数

Keras 函数式 API 和 TensorFlow Hub

我正在尝试以功能方式使用TF Hub 中的通用句子编码器作为 keras 层。我想hub.KerasLayer与 Keras 功能 API 一起使用,但我不确定如何实现这一点,到目前为止我只看到 hub.KerasLayer 与 Sequential API 的示例

import tensorflow_hub as hub
import tensorflow as tf
from tensorflow.keras import layers
import tf_sentencepiece


use_url = 'https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/1'

english_sentences = ["dog", "Puppies are nice.", "I enjoy taking long walks along the beach with my dog."]
english_sentences = np.array(english_sentences, dtype=object)[:, np.newaxis]


seq = layers.Input(shape=(None, ), name='sentence', dtype=tf.string)
module = hub.KerasLayer(hub.Module(use_url))(seq)
model = tf.keras.models.Model(inputs=[seq], outputs=[module])
model.summary()

x = model.predict(english_sentences)
print(x)

Run Code Online (Sandbox Code Playgroud)

将输入层传递到嵌入时,上面的代码会遇到此错误:TypeError: Can't convert 'inputs': …

python keras tensorflow

6
推荐指数
1
解决办法
1334
查看次数

标签 统计

python ×2

bokeh ×1

callback ×1

keras ×1

python-3.x ×1

tensorflow ×1