简体   繁体   中英

Keras Custom Scaling Layer

For my work, I need to make a layer, that has only single weight, that will multiply the data in the current layer by some trained value. Is there a way to do this?

Or change the merge layer, which will be able to make a weighted average of input layers. Thanks

Try Lambda layer

model.add(Lambda(lambda x: x *MyValue))

https://keras.io/layers/core/#lambda

Extending @user375348's answer you can create a learned variable and use it within the Lambda :

initial_value = 1
learned = tf.Variable(initial_value, name='learned_scalar')
Lambda(lambda x: x * learned)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM