use*_*004 5 python keras tensorflow
是否有一种简单的方法可以将数据提供给 Keras 中的层(通过 TF)并查看返回值以进行测试,而无需实际构建完整模型并为其拟合数据?
如果没有,如何测试他们开发的自定义层?
您可以为此目的定义并使用后端函数:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1742 次 |
| 最近记录: |