本文整理匯總了Python中keras.layers.Average方法的典型用法代碼示例。如果您正苦於以下問題:Python layers.Average方法的具體用法?Python layers.Average怎麽用?Python layers.Average使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類keras.layers
的用法示例。
在下文中一共展示了layers.Average方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_merge_average
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Average [as 別名]
def test_merge_average():
i1 = layers.Input(shape=(4, 5))
i2 = layers.Input(shape=(4, 5))
o = layers.average([i1, i2])
assert o._keras_shape == (None, 4, 5)
model = models.Model([i1, i2], o)
avg_layer = layers.Average()
o2 = avg_layer([i1, i2])
assert avg_layer.output_shape == (None, 4, 5)
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
out = model.predict([x1, x2])
assert out.shape == (2, 4, 5)
assert_allclose(out, 0.5 * (x1 + x2), atol=1e-4)
示例2: ensemble
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Average [as 別名]
def ensemble(models,model_input):
outputs = [model(model_input) for model in models]
y = Average()(outputs)
model = Model(model_input, y, name='ensemble')
return model
示例3: create_multi_input_model_from
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Average [as 別名]
def create_multi_input_model_from(layer1, layer2):
input_1 = Input(shape=(data_dim,))
input_2 = Input(shape=(data_dim,))
out1 = layer1(input_1)
out2 = layer2(input_2)
out = Average()([out1, out2])
model = Model([input_1, input_2], out)
model.add_loss(K.mean(out2))
model.add_loss(1)
model.add_loss(1)
return model