有没有一种简单的方法可以将数据提供给 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/