python - 如何在 Keras 的数据上应用(调用)单层?

标签 python tensorflow keras

有没有一种简单的方法可以将数据提供给 Keras 中的一个层(通过 TF)并查看返回值,以用于测试目的,而无需实际构建完整模型并为其拟合数据?

如果没有,如何测试他们开发的自定义层?

最佳答案

您可以定义和使用 backend function为此目的:

from keras import backend as K

# my_layer could be a layer from a previously built model, like:
# my_layer = model.layers[3]
func = K.function(model.inputs, [my_layer.output])

# or it is a layer with customized weights, like:
# my_layer = Dense(...)
# my_layer.set_weights(...)
# out = my_layer(input_data)
input_data = Input(shape=...)
func = K.function([input_data], [my_layer.output])

# to use the function:
layer_output = func(layer_input)   # layer_input is a list of numpy array(s)

关于python - 如何在 Keras 的数据上应用(调用)单层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52338033/

相关文章:

Python Pandas : Operation on a column - Error: must be str not int

python - 用 python 编写脚本语言

python - 如何显示一个句子中下一个单词的多个预测?

python - 安装 Keras 时的 Linux 错误

python - TensorFlow 中的损失是如何计算的?

python - DataFrame groupby 方法的语义

python - python 列表中的 Writerows - 如何删除括号和撇号

python - 寻找 tensorflow 模型的准确性

tensorflow - 使用opencv预处理测试图像进​​行预测

parameters - Keras Sequential fit_generator 参数列表中validation_steps的含义