本文整理汇总了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