如何对隐藏层结果进行加法运算?

假设我们有一个如下结构的神经网络

input = layers.Input(shape=(num_inputs,))out = layers.Dense(1028, activation="relu")(input)out = layers.Dense(512, activation="relu")(out)out = layers.Dense(256, activation="relu")(out)output = layers.Dense(4, activation="softmax")(out)

如果我想对任何隐藏层的结果加上一个随机数,代码应该如何修改?


回答:

你可以按以下方式对任何隐藏层的结果加上一个随机数。参考和更多详情

from tensorflow.keras.layers import *from tensorflow.keras.models import Modelfrom tensorflow.keras import backend as K ins = Input((1,))out = Dense(1028, activation="relu")(ins)out = Lambda(lambda x: K.random_uniform((1,))*x)(out)out = Dense(512, activation="relu")(out)out = Lambda(lambda x: K.random_uniform((1,))*x)(out)out = Dense(256, activation="relu")(out)out = Lambda(lambda x: K.random_uniform((1,))*x)(out)outs = Dense(256, activation="softmax")(out)model = Model(ins, outs)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注