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


Python brew.conv方法代码示例

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


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

示例1: AddLeNetModel

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def AddLeNetModel(model, data):
    '''
    This part is the standard LeNet model: from data to the softmax prediction.

    For each convolutional layer we specify dim_in - number of input channels
    and dim_out - number or output channels. Also each Conv and MaxPool layer changes the
    image size. For example, kernel of size 5 reduces each side of an image by 4.

    While when we have kernel and stride sizes equal 2 in a MaxPool layer, it divides
    each side in half.
    '''
    # Image size: 28 x 28 -> 24 x 24
    conv1 = brew.conv(model, data, 'conv1', dim_in=1, dim_out=20, kernel=5)
    # Image size: 24 x 24 -> 12 x 12
    pool1 = brew.max_pool(model, conv1, 'pool1', kernel=2, stride=2)
    # Image size: 12 x 12 -> 8 x 8
    conv2 = brew.conv(model, pool1, 'conv2', dim_in=20, dim_out=50, kernel=5)
    # Image size: 8 x 8 -> 4 x 4
    pool2 = brew.max_pool(model, conv2, 'pool2', kernel=2, stride=2)
    # 50 * 4 * 4 stands for dim_out from previous layer multiplied by the image size
    fc3 = brew.fc(model, pool2, 'fc3', dim_in=50 * 4 * 4, dim_out=500)
    fc3 = brew.relu(model, fc3, fc3)
    pred = brew.fc(model, fc3, 'pred', 500, 10)
    softmax = brew.softmax(model, pred, 'softmax')
    return softmax 
开发者ID:Azure,项目名称:batch-shipyard,代码行数:27,代码来源:mnist.py

示例2: create_model

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def create_model(model_builder, model, enable_tensor_core, float16_compute, loss_scale=1.0):
    """Creates one model replica.

    :param obj model_builder: A model instance that contains `forward_pass_builder` method.
    :param model: Caffe2's model helper class instances.
    :type model: :py:class:`caffe2.python.model_helper.ModelHelper`
    :param bool enable_tensor_core: If true, Volta's tensor core ops are enabled.
    :param float loss_scale: Scale loss for multi-GPU training.
    :return: Head nodes (softmax or loss depending on phase)
    """
    initializer = (pFP16Initializer if model_builder.dtype == 'float16' else Initializer)
    with brew.arg_scope([brew.conv, brew.fc],
                        WeightInitializer=initializer,
                        BiasInitializer=initializer,
                        enable_tensor_core=enable_tensor_core,
                        float16_compute=float16_compute):
        outputs = model_builder.forward_pass_builder(model, loss_scale=loss_scale)
    return outputs 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:20,代码来源:benchmarks.py

示例3: create_model

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def create_model(m, device_opts) :
    with core.DeviceScope(device_opts):

        conv1 = brew.conv(m, 'data', 'conv1', dim_in=1, dim_out=20, kernel=5)
        pool1 = brew.max_pool(m, conv1, 'pool1', kernel=2, stride=2)
        conv2 = brew.conv(m, pool1, 'conv2', dim_in=20, dim_out=50, kernel=5)
        pool2 = brew.max_pool(m, conv2, 'pool2', kernel=2, stride=2)
        fc3 = brew.fc(m, pool2, 'fc3', dim_in=50 * 4 * 4, dim_out=500)
        fc3 = brew.relu(m, fc3, fc3)
        pred = brew.fc(m, fc3, 'pred', 500, 2)
        softmax = brew.softmax(m, pred, 'softmax')
        m.net.AddExternalOutput(softmax)
        return softmax

# add loss and optimizer 
开发者ID:peterneher,项目名称:peters-stuff,代码行数:17,代码来源:classification_no_db_example.py

示例4: AddLeNetModel

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def AddLeNetModel(model, data):
    '''
    This part is the standard LeNet model: from data to the softmax prediction.

    For each convolutional layer we specify dim_in - number of input channels
    and dim_out - number or output channels. Also each Conv and MaxPool layer changes the
    image size. For example, kernel of size 5 reduces each side of an image by 4.

    While when we have kernel and stride sizes equal 2 in a MaxPool layer, it divides
    each side in half.
    '''
    # Image size: 28 x 28 -> 24 x 24
    conv1 = brew.conv(model, data, 'conv1', dim_in=1, dim_out=20, kernel=5)
    # Image size: 24 x 24 -> 12 x 12
    pool1 = brew.max_pool(model, conv1, 'pool1', kernel=2, stride=2)
    # Image size: 12 x 12 -> 8 x 8
    conv2 = brew.conv(model, pool1, 'conv2', dim_in=20, dim_out=100, kernel=5)
    # Image size: 8 x 8 -> 4 x 4
    pool2 = brew.max_pool(model, conv2, 'pool2', kernel=2, stride=2)
    # 50 * 4 * 4 stands for dim_out from previous layer multiplied by the
    # image size
    fc3 = brew.fc(model, pool2, 'fc3', dim_in=100 * 4 * 4, dim_out=500)
    relu = brew.relu(model, fc3, fc3)
    pred = brew.fc(model, relu, 'pred', 500, 10)
    softmax = brew.softmax(model, pred, 'softmax')
    return softmax 
开发者ID:lanpa,项目名称:tensorboardX,代码行数:28,代码来源:demo_caffe2.py

示例5: test_simple_model

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def test_simple_model(self):
        model = model_helper.ModelHelper(name="mnist")
        # how come those inputs don't break the forward pass =.=a
        workspace.FeedBlob("data", np.random.randn(1, 3, 64, 64).astype(np.float32))
        workspace.FeedBlob("label", np.random.randn(1, 1000).astype(np.int))

        with core.NameScope("conv1"):
            conv1 = brew.conv(model, "data", 'conv1', dim_in=1, dim_out=20, kernel=5)
            # Image size: 24 x 24 -> 12 x 12
            pool1 = brew.max_pool(model, conv1, 'pool1', kernel=2, stride=2)
            # Image size: 12 x 12 -> 8 x 8
            conv2 = brew.conv(model, pool1, 'conv2', dim_in=20, dim_out=100, kernel=5)
            # Image size: 8 x 8 -> 4 x 4
            pool2 = brew.max_pool(model, conv2, 'pool2', kernel=2, stride=2)
        with core.NameScope("classifier"):
            # 50 * 4 * 4 stands for dim_out from previous layer multiplied by the image size
            fc3 = brew.fc(model, pool2, 'fc3', dim_in=100 * 4 * 4, dim_out=500)
            relu = brew.relu(model, fc3, fc3)
            pred = brew.fc(model, relu, 'pred', 500, 10)
            softmax = brew.softmax(model, pred, 'softmax')
            xent = model.LabelCrossEntropy([softmax, "label"], 'xent')
            # compute the expected loss
            loss = model.AveragedLoss(xent, "loss")
        model.net.RunAllOnMKL()
        model.param_init_net.RunAllOnMKL()
        model.AddGradientOperators([loss], skip=1)
        blob_name_tracker = {}
        graph = tb.model_to_graph_def(
            model,
            blob_name_tracker=blob_name_tracker,
            shapes={},
            show_simplified=False,
        )

        compare_proto(graph, self) 
开发者ID:lanpa,项目名称:tensorboardX,代码行数:37,代码来源:test_caffe2.py

示例6: conv_factory

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def conv_factory(self, model, v, num_in_channels, num_filters, kernel,
                     stride=1, pad=0, relu=True, name='conv'):
        """Standard convolution block: Conv -> BatchNorm -> Activation
        """
        if isinstance(pad, int):
            pad_t = pad_b = pad_l = pad_r = pad
        elif isinstance(pad, list) or isinstance(pad, tuple):
            if len(pad) == 2:
                pad_t = pad_b = pad[0]
                pad_l = pad_r = pad[1]
            elif len(pad) == 4:
                pad_t = pad[0]
                pad_b = pad[1]
                pad_l = pad[2]
                pad_r = pad[3]
            else:
                assert False, "Invalid length of pad array. Expecting 2 or 4 but have: " + str(pad)
        else:
            assert False, "Invalid type of padding: " + str(pad)

        v = brew.conv(model, v, name + '_conv', num_in_channels, num_filters,
                      kernel=kernel, pad_t=pad_t, pad_l=pad_l, pad_b=pad_b,
                      pad_r=pad_r, stride=stride)
        v = brew.spatial_bn(model, v, name+'_bn', num_filters, eps=2e-5,
                            momentum=0.9, is_test=(self.phase == 'inference'))
        if relu is True:
            v = brew.relu(model, v, name + '_relu')
        return v 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:30,代码来源:inception_resnet_v2.py

示例7: forward_pass_builder

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def forward_pass_builder(self, model, loss_scale=1.0):
        """
            This function adds the operators, layers to the network. It should return a list
            of loss-blobs that are used for computing the loss gradient. This function is
            also passed an internally calculated loss_scale parameter that is used to scale
            your loss to normalize for the number of GPUs. Signature: function(model, loss_scale)
        """
        is_inference = self.phase == 'inference'

        v = 'data'

        v = brew.conv(model, v, 'conv1', 3, 64, kernel=11, stride=4)
        v = brew.relu(model, v, 'relu1')
        v = brew.max_pool(model, v, 'pool1', kernel=3, stride=2)

        v = brew.conv(model, v, 'conv2', 64, 192, kernel=5, pad=2, group=1)
        v = brew.relu(model, v, 'relu2')
        v = brew.max_pool(model, v, 'pool2', kernel=3, stride=2)

        v = brew.conv(model, v, 'conv3', 192, 384, kernel=3, pad=1)
        v = brew.relu(model, v, 'relu3')

        v = brew.conv(model, v, 'conv4', 384, 256, kernel=3, pad=1, group=1)
        v = brew.relu(model, v, 'relu4')

        v = brew.conv(model, v, 'conv5', 256, 256, kernel=3, pad=1, group=1)
        v = brew.relu(model, v, 'relu5')
        v = brew.max_pool(model, v, 'pool5', kernel=3, stride=2)

        v = brew.fc(model, v, 'fc6', dim_in=9216, dim_out=4096)
        v = brew.relu(model, v, 'relu6')
        v = brew.dropout(model, v, 'drop6', ratio=0.5, is_test=is_inference)

        v = brew.fc(model, v, 'fc7', dim_in=4096, dim_out=4096)
        v = brew.relu(model, v, 'relu7')
        v = brew.dropout(model, v, 'drop7', ratio=0.5, is_test=is_inference)

        return self.add_head_nodes(model, v, 4096, 'fc8', loss_scale=loss_scale) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:40,代码来源:alexnet_owt.py

示例8: forward_pass_builder

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def forward_pass_builder(self, model, loss_scale=1.0):
        """
            This function adds the operators, layers to the network. It should return
            a list of loss-blobs that are used for computing the loss gradient. This
            function is also passed an internally calculated loss_scale parameter that
            is used to scale your loss to normalize for the number of GPUs.
            Signature: function(model, loss_scale)
        """
        is_inference = self.phase == 'inference'
        layers, filters = VGG.specs[self.__model]['specs']
        v = 'data'
        dim_in = self.input_shape[0]
        for i, num in enumerate(layers):
            for j in range(num):
                v = brew.conv(model, v, 'conv%d_%d' % (i+1, j+1), dim_in, filters[i], kernel=3, pad=1)
                v = brew.relu(model, v, 'relu%d_%d' % (i+1, j+1))
                dim_in = filters[i]
            v = brew.max_pool(model, v, 'pool%d' % (i+1), kernel=2, stride=2)

        dim_in = 25088 # 512 * 7 * 7 (output tensor of previous max pool layer)
        for i in range(2):
            v = brew.fc(model, v, 'fc%d' % (6+i), dim_in=dim_in, dim_out=4096)
            v = brew.relu(model, v, 'relu%d' % (6+i))
            v = brew.dropout(model, v, 'drop%d' % (6+i), ratio=0.5, is_test=is_inference)
            dim_in = 4096

        return self.add_head_nodes(model, v, 4096, 'fc8', loss_scale=loss_scale) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:29,代码来源:vgg.py

示例9: conv

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def conv(self, model, name, inputs, input_depth, num_filters, kernel, stride,
             pad, is_inference):
        # Check padding
        if isinstance(pad, int):
            pad_t = pad_b = pad_l = pad_r = pad
        elif isinstance(pad, list) or isinstance(pad, tuple):
            if len(pad) == 2:
                pad_t = pad_b = pad[0]
                pad_l = pad_r = pad[1]
            elif len(pad) == 4:
                pad_t = pad[0]
                pad_b = pad[1]
                pad_l = pad[2]
                pad_r = pad[3]
            else:
                assert False, "Invalid length of pad array. Expecting 2 or 4 but have: " + str(pad)
        else:
            assert False, "Invalid type of padding: " + str(pad)
        # Check kernel
        if isinstance(kernel, int):
            kernel = [kernel, kernel]
        elif isinstance(kernel, tuple) or isinstance(kernel, list):
            assert len(kernel) == 2, "Kernel must have length 2"
            kernel = [kernel[0], kernel[1]]
        else:
            assert False, "Invalid type of kerne;: " + str(kernel)
        #
        self.counts[name] += 1
        name = name + str(self.counts[name]-1)
        #
        v = brew.conv(model, inputs, name + '_conv', input_depth, num_filters,
                      kernel=kernel, stride=stride,
                      pad_t=pad_t, pad_l=pad_l, pad_b=pad_b, pad_r=pad_r,
                      no_bias=True)
        v = brew.spatial_bn(model, v, name+'_bn', num_filters, eps=2e-5,
                            momentum=0.9, is_test=is_inference)
        v = brew.relu(model, v, name+'_relu')
        return v 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:40,代码来源:inception.py

示例10: module_a

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def module_a(self, model, inputs, input_depth, n, is_inference):
        branhes = [
            [('conv', 64, 1, 1, 0)],
            [('conv', 48, 1, 1, 0), ('conv', 64, 5, 1, 2)],
            [('conv', 64, 1, 1, 0), ('conv', 96, 3, 1, 1), ('conv', 96, 3, 1, 1)],
            [('avg', 3, 1, 1), ('conv', n, 1, 1, 0)]
        ]
        return self.inception_module(model, 'inception_a', inputs, input_depth,
                                     branhes, is_inference) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:11,代码来源:inception.py

示例11: module_b

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def module_b(self, model, inputs, input_depth, is_inference):
        branches = [
            [('conv', 384, 3, 2, 0)],
            [('conv', 64, 1, 1, 0), ('conv', 96, 3, 1, 1), ('conv', 96, 3, 2, 0)],
            [('max', 3, 2, 0)]
        ]
        return self.inception_module(model, 'inception_b', inputs, input_depth,
                                     branches, is_inference) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:10,代码来源:inception.py

示例12: module_c

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def module_c(self, model, inputs, input_depth, n, is_inference):
        branches = [
            [('conv', 192, 1, 1, 0)],
            [('conv', n, 1, 1, 0), ('conv', n, (1,7), 1, (0,3)), ('conv', 192, (7,1), 1, (3,0))],
            [('conv', n, 1, 1, 0), ('conv', n, (7,1), 1, (3,0)), ('conv', n, (1,7), 1, (0,3)),
             ('conv', n, (7,1), 1, (3,0)), ('conv', 192, (1,7), 1, (0,3))],
            [('avg', 3, 1, 1), ('conv', 192, 1, 1, 0)]
        ]
        return self.inception_module(model, 'inception_c', inputs, input_depth,
                                     branches, is_inference) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:12,代码来源:inception.py

示例13: module_e

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def module_e(self, model, inputs, input_depth, pooltype, is_inference):
        branches = [
            [('conv', 320, 1, 1, 0)],
            [('conv', 384, 1, 1, 0), ('conv', 384, (1,3), 1, (0,1))],
            [('share',),             ('conv', 384, (3,1), 1, (1,0))],
            [('conv', 448, 1, 1, 0), ('conv', 384, 3, 1, 1), ('conv', 384, (1,3), 1, (0,1))],
            [('share',),             ('share',),             ('conv', 384, (3,1), 1, (1,0))],
            [(pooltype, 3, 1, 1), ('conv', 192, 1, 1, 0)]
        ]
        return self.inception_module(model, 'inception_e', inputs, input_depth,
                                     branches, is_inference) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:13,代码来源:inception.py

示例14: forward_pass_builder

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def forward_pass_builder(self, model, loss_scale=1.0):
        """
            This function adds the operators, layers to the network. It should return a list
            of loss-blobs that are used for computing the loss gradient. This function is
            also passed an internally calculated loss_scale parameter that is used to scale
            your loss to normalize for the number of GPUs. Signature: function(model, loss_scale)
        """
        self.counts = defaultdict(lambda: 0)
        is_inference = self.phase == 'inference'

        v = 'data'

        # Input conv modules
        v = self.conv(model, 'conv', v, input_depth=3, num_filters=32, kernel=3, stride=2, pad=0, is_inference=is_inference)
        v = self.conv(model, 'conv', v, input_depth=32, num_filters=32, kernel=3, stride=1, pad=0, is_inference=is_inference)
        v = self.conv(model, 'conv', v, input_depth=32, num_filters=64, kernel=3, stride=1, pad=1, is_inference=is_inference)
        v = brew.max_pool(model, v, blob_out='pool1', kernel=3, stride=2, pad=0)
        v = self.conv(model, 'conv', v, input_depth=64, num_filters=80, kernel=1, stride=1, pad=0, is_inference=is_inference)
        v = self.conv(model, 'conv', v, input_depth=80, num_filters=192, kernel=3, stride=1, pad=0, is_inference=is_inference)
        v = brew.max_pool(model, v, blob_out='pool2', kernel=3, stride=2, pad=0)
        # Three Type A inception modules
        v = self.module_a(model, inputs=v, input_depth=192, n=32, is_inference=is_inference)
        v = self.module_a(model, inputs=v, input_depth=256, n=64, is_inference=is_inference)
        v = self.module_a(model, inputs=v, input_depth=288, n=64, is_inference=is_inference)
        # One Type B inception module
        v = self.module_b(model, inputs=v, input_depth=288, is_inference=is_inference)
        # Four Type C inception modules
        for n in (128, 160, 160, 192):
            v = self.module_c(model, inputs=v, input_depth=768, n=n, is_inference=is_inference)
        # One Type D inception module
        v = self.module_d(model, inputs=v, input_depth=768, is_inference=is_inference)
        # Two Type E inception modules
        v = self.module_e(model, inputs=v, input_depth=1280, pooltype='avg', is_inference=is_inference)
        v = self.module_e(model, inputs=v, input_depth=2048, pooltype='max', is_inference=is_inference)
        # Final global pooling
        v = brew.average_pool(model, v, blob_out='pool', kernel=8, stride=1, pad=0)
        # And classifier
        return self.add_head_nodes(model, v, 2048, 'classifier', loss_scale=loss_scale) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:40,代码来源:inception.py

示例15: inception_v4_sa

# 需要导入模块: from caffe2.python import brew [as 别名]
# 或者: from caffe2.python.brew import conv [as 别名]
def inception_v4_sa(self, model, inputs, input_depth, is_inference):
        branches = [
            [('conv', 96, 3, 2, 0)],
            [('max', 3, 2, 0)]
        ]
        return self.inception_module(model, 'incept_v4_sa', inputs, input_depth,
                                     branches, is_inference) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:9,代码来源:inception.py


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