本文整理匯總了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