在Keras中创建恒定值

在Keras中创建恒定值,第1张

在Keras中创建恒定值

您不能有大小可变的常数。常数始终具有相同的值。您可以做的就是获取

(1,50)
常量,然后使用将该常量平铺在TensorFlow中
K.tile
。也可以
np.arange
代替更好地使用
np.array(list(range(50))
。就像是:

from keras.layers.core import Lambdaimport keras.backend as Kdef operateWithConstant(input_batch):    tf_constant = K.constant(np.arange(50).reshape((1, 50)))    batch_size = K.shape(input_batch)[0]    tiled_constant = K.tile(tf_constant, (batch_size, 1))    # Do some operation with tiled_constant and input_batch    result = ...    return resultinput_batch = Input(...)input_operated = Lambda(operateWithConstant)(input_batch)# continue...


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5663240.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存