简体   繁体   中英

is there a layer, that learns how to scale?

I am looking for something like this:

inputs = tf.keras.Input(shape = input_shape)
# network structure
x = layers.Dense(4, activation='relu')(inputs) 
x = layers.Dense(4, activation='relu')(x)
#output layer
outputs = layers.Dense(output_size, activation='linear')(x)


#scaling layer??
outputs = layers.Scale(output_size)(outputs)


#build model 
model = tf.keras.models.Model(inputs=inputs, outputs=outputs, name = 'mymodel') 

I want the layer to scale my outputs by a scalar. And I don't want to specify this scalar, but rather have the model learn this scalar by itself.

Is there such a layer?

Or can I achieve this with a Multiply layer in combination with something like sympy?

I need this for a quantum-computing model (made with tfq) which can only give outputs between 0 and 1. I can't use a dense layer, because that would bring in classical machine-learning, which I don't want to use.

A scale layer is usually unnecessary because the desired information is in the relationship between the outputs.

If you want specific values, you probably need to change the loss function.

However, this link can allow you to make a personalized layer: https://keras.io/guides/making_new_layers_and_models_via_subclassing/

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