本文整理汇总了Python中blocks.graph.apply_dropout方法的典型用法代码示例。如果您正苦于以下问题:Python graph.apply_dropout方法的具体用法?Python graph.apply_dropout怎么用?Python graph.apply_dropout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blocks.graph
的用法示例。
在下文中一共展示了graph.apply_dropout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_models
# 需要导入模块: from blocks import graph [as 别名]
# 或者: from blocks.graph import apply_dropout [as 别名]
def create_models(self):
gan = self.create_model_brick()
x = tensor.matrix('features')
zs = []
for i in range(self._config["num_packing"]):
z = circle_gaussian_mixture(num_modes=self._config["num_zmode"], num_samples=x.shape[0], dimension=self._config["num_zdim"], r=self._config["z_mode_r"], std=self._config["z_mode_std"])
zs.append(z)
def _create_model(with_dropout):
cg = ComputationGraph(gan.compute_losses(x, zs))
if with_dropout:
inputs = VariableFilter(
bricks=gan.discriminator.children[1:],
roles=[INPUT])(cg.variables)
cg = apply_dropout(cg, inputs, 0.5)
inputs = VariableFilter(
bricks=[gan.discriminator],
roles=[INPUT])(cg.variables)
cg = apply_dropout(cg, inputs, 0.2)
return Model(cg.outputs)
model = _create_model(with_dropout=False)
with batch_normalization(gan):
bn_model = _create_model(with_dropout=False)
pop_updates = list(set(get_batch_normalization_updates(bn_model, allow_duplicates=True)))
# merge same variables
names = []
counts = []
pop_update_merges = []
pop_update_merges_finals = []
for pop_update in pop_updates:
b = False
for i in range(len(names)):
if (pop_update[0].auto_name == names[i]):
counts[i] += 1
pop_update_merges[i][1] += pop_update[1]
b = True
break
if not b:
names.append(pop_update[0].auto_name)
counts.append(1)
pop_update_merges.append([pop_update[0], pop_update[1]])
for i in range(len(pop_update_merges)):
pop_update_merges_finals.append((pop_update_merges[i][0], pop_update_merges[i][1] / counts[i]))
bn_updates = [(p, m * 0.05 + p * 0.95) for p, m in pop_update_merges_finals]
return model, bn_model, bn_updates