当前位置: 首页>>代码示例>>Python>>正文


Python bricks.Identity方法代码示例

本文整理汇总了Python中blocks.bricks.Identity方法的典型用法代码示例。如果您正苦于以下问题:Python bricks.Identity方法的具体用法?Python bricks.Identity怎么用?Python bricks.Identity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blocks.bricks的用法示例。


在下文中一共展示了bricks.Identity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from blocks import bricks [as 别名]
# 或者: from blocks.bricks import Identity [as 别名]
def __init__(self, n_layers_conv, n_layers_dense_lower, n_layers_dense_upper,
        n_hidden_conv, n_hidden_dense_lower, n_hidden_dense_lower_output, n_hidden_dense_upper,
        spatial_width, n_colors, n_scales, n_temporal_basis):
        """
        The multilayer perceptron, that provides temporal weighting coefficients for mu and sigma
        images. This consists of a lower segment with a convolutional MLP, and optionally with a
        dense MLP in parallel. The upper segment then consists of a per-pixel dense MLP
        (convolutional MLP with 1x1 kernel).
        """
        super(MLP_conv_dense, self).__init__()

        self.n_colors = n_colors
        self.spatial_width = spatial_width
        self.n_hidden_dense_lower = n_hidden_dense_lower
        self.n_hidden_dense_lower_output = n_hidden_dense_lower_output
        self.n_hidden_conv = n_hidden_conv

        ## the lower layers
        self.mlp_conv = MultiLayerConvolution(n_layers_conv, n_hidden_conv, spatial_width, n_colors, n_scales)
        self.children = [self.mlp_conv]
        if n_hidden_dense_lower > 0 and n_layers_dense_lower > 0:
            n_input = n_colors*spatial_width**2
            n_output = n_hidden_dense_lower_output*spatial_width**2
            self.mlp_dense_lower = MLP([dense_nonlinearity] * n_layers_conv,
                [n_input] + [n_hidden_dense_lower] * (n_layers_conv-1) + [n_output],
                name='MLP dense lower', weights_init=Orthogonal(), biases_init=Constant(0))
            self.children.append(self.mlp_dense_lower)
        else:
            n_hidden_dense_lower_output = 0

        ## the upper layers (applied to each pixel independently)
        n_output = n_colors*n_temporal_basis*2 # "*2" for both mu and sigma
        self.mlp_dense_upper = MLP([dense_nonlinearity] * (n_layers_dense_upper-1) + [Identity()],
            [n_hidden_conv+n_hidden_dense_lower_output] +
            [n_hidden_dense_upper] * (n_layers_dense_upper-1) + [n_output],
            name='MLP dense upper', weights_init=Orthogonal(), biases_init=Constant(0))
        self.children.append(self.mlp_dense_upper) 
开发者ID:Sohl-Dickstein,项目名称:Diffusion-Probabilistic-Models,代码行数:39,代码来源:regression.py

示例2: setUp

# 需要导入模块: from blocks import bricks [as 别名]
# 或者: from blocks.bricks import Identity [as 别名]
def setUp(self):
        self.mlp = MLP([Sequence([Identity(name='id1').apply,
                                  Tanh(name='tanh1').apply],
                                 name='sequence1'),
                        Sequence([Logistic(name='logistic1').apply,
                                  Identity(name='id2').apply,
                                  Tanh(name='tanh2').apply],
                                 name='sequence2'),
                        Logistic(name='logistic2'),
                        Sequence([Sequence([Logistic(name='logistic3').apply],
                                           name='sequence4').apply],
                                 name='sequence3')],
                       [10, 5, 9, 5, 9]) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:15,代码来源:test_utils.py

示例3: test_find_second_and_third_level

# 需要导入模块: from blocks import bricks [as 别名]
# 或者: from blocks.bricks import Identity [as 别名]
def test_find_second_and_third_level(self):
        found = set(find_bricks([self.mlp], lambda x: isinstance(x, Identity)))
        assert len(found) == 2
        assert self.mlp.activations[0].children[0] in found
        assert self.mlp.activations[1].children[1] in found 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:7,代码来源:test_utils.py

示例4: test_snapshot

# 需要导入模块: from blocks import bricks [as 别名]
# 或者: from blocks.bricks import Identity [as 别名]
def test_snapshot():
    x = tensor.matrix('x')
    linear = MLP([Identity(), Identity()], [10, 10, 10],
                 weights_init=Constant(1), biases_init=Constant(2))
    linear.initialize()
    y = linear.apply(x)
    cg = ComputationGraph(y)
    snapshot = cg.get_snapshot(dict(x=numpy.zeros((1, 10),
                                                  dtype=theano.config.floatX)))
    assert len(snapshot) == 14 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:12,代码来源:test_graph.py

示例5: main

# 需要导入模块: from blocks import bricks [as 别名]
# 或者: from blocks.bricks import Identity [as 别名]
def main(save_to, num_batches):
    mlp = MLP([Tanh(), Identity()], [1, 10, 1],
              weights_init=IsotropicGaussian(0.01),
              biases_init=Constant(0), seed=1)
    mlp.initialize()
    x = tensor.vector('numbers')
    y = tensor.vector('roots')
    cost = SquaredError().apply(y[:, None], mlp.apply(x[:, None]))
    cost.name = "cost"

    main_loop = MainLoop(
        GradientDescent(
            cost=cost, parameters=ComputationGraph(cost).parameters,
            step_rule=Scale(learning_rate=0.001)),
        get_data_stream(range(100)),
        model=Model(cost),
        extensions=[
            Timing(),
            FinishAfter(after_n_batches=num_batches),
            DataStreamMonitoring(
                [cost], get_data_stream(range(100, 200)),
                prefix="test"),
            TrainingDataMonitoring([cost], after_epoch=True),
            Checkpoint(save_to),
            Printing()])
    main_loop.run()
    return main_loop 
开发者ID:mila-iqia,项目名称:blocks-examples,代码行数:29,代码来源:__init__.py


注:本文中的blocks.bricks.Identity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。