【发布时间】:2020-08-01 15:08:23
【问题描述】:
如果这是一个框架不佳的问题,请原谅我。这恰好是我在这里的第一个问题。
假设我在 Keras 中有一个输出层,我想将最后一个值(sigmoid 激活的结果)乘以一个标量(比如 5)。
(我在这里附上了一个代码sn-p。假设包括所有必要的库/依赖项)
def create_model():
inp = Input(shape=(561,))
x = Dense(units=1024,input_dim=561)(inp)
x = LeakyReLU(0.2)(x)
x = Dropout(0.3)(x)
x = Dense(units=512)(x)
x = LeakyReLU(0.2)(x)
x = Dropout(0.3)(x)
x = Dense(units=256)(x)
x = LeakyReLU(0.2)(x)
x = Dense(units=1, activation='sigmoid')(x)
m = tf.convert_to_tensor(5) #creating a tensor of value = 5
o = Multiply()([x, m]) #trying to multiply x with o. Doesn't work though!
model = Model(inputs=[inp], outputs=[o])
model.compile(loss='binary_crossentropy', optimizer = Adam(lr=0.0002, beta_1=0.5))
return model
model = create_model()
model.summary()
我试过这个,我得到“元组索引超出范围”错误。 如果有人可以帮助我,我会很高兴(即将最后一层的输出与标量相乘)
【问题讨论】:
标签: keras keras-layer tf.keras