Python caffe 模块,NetSpec() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用caffe.NetSpec()

项目:monogreedy    作者:jinjunqi    | 项目源码 | 文件源码
def archiEncoder(convoList, fullList, lmdb, batch_size):
    n = caffe.NetSpec()
    n.data, n.label = L.Data(batch_size=batch_size, backend=P.Data.LMDB, source=lmdb, transform_param=dict(scale=1./255), ntop=2)

    n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=convoList[0], weight_filler=dict(type='xavier'))
    n.relu1 = L.ReLU(n.conv1, in_place=True)
    n.pool1 = L.Pooling(n.relu1, kernel_size=2, stride=2, pool=P.Pooling.MAX)

    n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=convoList[1], weight_filler=dict(type='xavier'))
    n.relu2 = L.ReLU(n.conv2, in_place=True)
    n.pool2 = L.Pooling(n.relu2, kernel_size=2, stride=2, pool=P.Pooling.MAX)

    n.ip2 = L.InnerProduct(n.pool2, num_output=10, weight_filler=dict(type='xavier'))
    n.loss = L.SoftmaxWithLoss(n.ip2, n.label)

    return n.to_proto()
项目:dilation    作者:fyu    | 项目源码 | 文件源码
def make_frontend_vgg(options, is_training):
    batch_size = options.train_batch if is_training else options.test_batch
    image_path = options.train_image if is_training else options.test_image
    label_path = options.train_label if is_training else options.test_label
    net = caffe.NetSpec()
    net.data, net.label = network.make_image_label_data(
        image_path, label_path, batch_size,
        is_training, options.crop_size, options.mean)
    last = network.build_frontend_vgg(
        net, net.data, options.classes)[0]
    if options.up:
        net.upsample = network.make_upsample(last, options.classes)
        last = net.upsample
    net.loss = network.make_softmax_loss(last, net.label)
    if not is_training:
        net.accuracy = network.make_accuracy(last, net.label)
    return net.to_proto()
项目:dilation    作者:fyu    | 项目源码 | 文件源码
def make_context(options, is_training):
    batch_size = options.train_batch if is_training else options.test_batch
    image_path = options.train_image if is_training else options.test_image
    label_path = options.train_label if is_training else options.test_label
    net = caffe.NetSpec()
    net.data, net.label = network.make_bin_label_data(
        image_path, label_path, batch_size,
        options.label_shape, options.label_stride)
    last = network.build_context(
        net, net.data, options.classes, options.layers)[0]
    if options.up:
        net.upsample = network.make_upsample(last, options.classes)
        last = net.upsample
    net.loss = network.make_softmax_loss(last, net.label)
    if not is_training:
        net.accuracy = network.make_accuracy(last, net.label)
    return net.to_proto()
项目:dilation    作者:fyu    | 项目源码 | 文件源码
def make_joint(options, is_training):
    batch_size = options.train_batch if is_training else options.test_batch
    image_path = options.train_image if is_training else options.test_image
    label_path = options.train_label if is_training else options.test_label
    net = caffe.NetSpec()
    net.data, net.label = network.make_image_label_data(
        image_path, label_path, batch_size,
        is_training, options.crop_size, options.mean)
    last = network.build_frontend_vgg(
        net, net.data, options.classes)[0]
    last = network.build_context(
        net, last, options.classes, options.layers)[0]
    if options.up:
        net.upsample = network.make_upsample(last, options.classes)
        last = net.upsample
    net.loss = network.make_softmax_loss(last, net.label)
    if not is_training:
        net.accuracy = network.make_accuracy(last, net.label)
    return net.to_proto()
项目:fcn    作者:wkentaro    | 项目源码 | 文件源码
def fcn(split, tops):
    n = caffe.NetSpec()
    n.color, n.hha, n.label = L.Python(module='nyud_layers',
            layer='NYUDSegDataLayer', ntop=3,
            param_str=str(dict(nyud_dir='../data/nyud', split=split,
                tops=tops, seed=1337)))
    n = modality_fcn(n, 'color', 'color')
    n = modality_fcn(n, 'hha', 'hha')
    n.score_fused = L.Eltwise(n.score_frcolor, n.score_frhha,
            operation=P.Eltwise.SUM, coeff=[0.5, 0.5])
    n.upscore = L.Deconvolution(n.score_fused,
        convolution_param=dict(num_output=40, kernel_size=64, stride=32,
            bias_term=False),
        param=[dict(lr_mult=0)])
    n.score = crop(n.upscore, n.color)
    n.loss = L.SoftmaxWithLoss(n.score, n.label,
            loss_param=dict(normalize=False, ignore_label=255))
    return n.to_proto()
项目:score-zeroshot    作者:pedro-morgado    | 项目源码 | 文件源码
def _new_model(self):
        self.netspec = caffe.NetSpec()
        if self.cnn == 'AlexNet':
            from cnns import AlexNet
            self.base_cnn = AlexNet(netspec=self.netspec)
            self.feat_layer = 'fc7'
            self.feat_dim = 4096
        elif self.cnn == 'GoogLeNet':
            from cnns import InceptionV1
            self.base_cnn = InceptionV1(netspec=self.netspec)
            self.feat_layer = 'pool5'
            self.feat_dim = 1024
        elif self.cnn == 'VGG19':
            from cnns import VGG19
            self.base_cnn = VGG19(netspec=self.netspec)
            self.feat_layer = 'fc7'
            self.feat_dim = 4096
        return self.netspec
项目:net-archive    作者:natanielruiz    | 项目源码 | 文件源码
def fcn(split, tops):
    n = caffe.NetSpec()
    n.color, n.hha, n.label = L.Python(module='nyud_layers',
            layer='NYUDSegDataLayer', ntop=3,
            param_str=str(dict(nyud_dir='../data/nyud', split=split,
                tops=tops, seed=1337)))
    n = modality_fcn(n, 'color', 'color')
    n = modality_fcn(n, 'hha', 'hha')
    n.score_fused = L.Eltwise(n.score_frcolor, n.score_frhha,
            operation=P.Eltwise.SUM, coeff=[0.5, 0.5])
    n.upscore = L.Deconvolution(n.score_fused,
        convolution_param=dict(num_output=40, kernel_size=64, stride=32,
            bias_term=False),
        param=[dict(lr_mult=0)])
    n.score = crop(n.upscore, n.color)
    n.loss = L.SoftmaxWithLoss(n.score, n.label,
            loss_param=dict(normalize=False, ignore_label=255))
    return n.to_proto()
项目:DeepLearning    作者:corecai163    | 项目源码 | 文件源码
def lenet(lmdb,batch_size):
    #define Lenet
    n = caffe.NetSpec()

    n.data, n.label = L.Data(batch_size=batch_size, backend=P.Data.LMDB, source=lmdb, transform_param=dict(scale=1./255),ntop=2)

    n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20, weight_filler=dict(type='xavier'))
    n.pool1 = L.Pooling(n.conv1, kernel_size=2, stride=2, pool=P.Pooling.MAX)
    n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=50, weight_filler = dict(type='xavier'))
    n.pool2 = L.Pooling(n.conv2, kernel_size=2, stride=2, pool=P.Pooling.MAX)
    n.fc1 = L.InnerProduct(n.pool2, num_output=500, weight_filler=dict(type='xavier'))
    n.relu1 = L.ReLU(n.fc1, in_place=True)
    n.score = L.InnerProduct(n.relu1,num_output=10, weight_filler=dict(type='xavier'))
    n.loss = L.SoftmaxWithLoss(n.score, n.label)

    return n.to_proto()
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def LeNet(lmdb, batch_size):
  # our version of LeNet: a series of linear and simple nonlinear transformations
  n = caffe.NetSpec()

  n.data, n.label = L.Data(batch_size=batch_size, backend=P.Data.LMDB, source=lmdb,
                           transform_param=dict(scale=1./255), ntop=2)

  n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20, weight_filler=dict(type='xavier'))
  n.pool1 = L.Pooling(n.conv1, kernel_size=2, stride=2, pool=P.Pooling.MAX)
  n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=50, weight_filler=dict(type='xavier'))
  n.pool2 = L.Pooling(n.conv2, kernel_size=2, stride=2, pool=P.Pooling.MAX)
  n.fc1 =   L.InnerProduct(n.pool2, num_output=500, weight_filler=dict(type='xavier'))
  n.relu1 = L.ReLU(n.fc1, in_place=True)
  n.score = L.InnerProduct(n.relu1, num_output=10, weight_filler=dict(type='xavier'))
  n.loss =  L.SoftmaxWithLoss(n.score, n.label)

  proto = n.to_proto()
  proto.name = 'LeNet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def LeNet(lmdb, batch_size):
  # our version of LeNet: a series of linear and simple nonlinear transformations
  n = caffe.NetSpec()

  n.data, n.label = L.Data(batch_size=batch_size, backend=P.Data.LMDB, source=lmdb,
                           transform_param=dict(scale=1./255), ntop=2)

  n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20, weight_filler=dict(type='xavier'))
  n.pool1 = L.Pooling(n.conv1, kernel_size=2, stride=2, pool=P.Pooling.MAX)
  n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=50, weight_filler=dict(type='xavier'))
  n.pool2 = L.Pooling(n.conv2, kernel_size=2, stride=2, pool=P.Pooling.MAX)
  n.fc1 =   L.InnerProduct(n.pool2, num_output=500, weight_filler=dict(type='xavier'))
  n.relu1 = L.ReLU(n.fc1, in_place=True)
  n.score = L.InnerProduct(n.relu1, num_output=10, weight_filler=dict(type='xavier'))
  n.loss =  L.SoftmaxWithLoss(n.score, n.label)

  proto = n.to_proto()
  proto.name = 'LeNet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def LeNet(lmdb, batch_size):
  # our version of LeNet: a series of linear and simple nonlinear transformations
  n = caffe.NetSpec()

  n.data, n.label = L.Data(batch_size=batch_size, backend=P.Data.LMDB, source=lmdb,
                           transform_param=dict(scale=1./255), ntop=2)

  n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20, weight_filler=dict(type='xavier'))
  n.pool1 = L.Pooling(n.conv1, kernel_size=2, stride=2, pool=P.Pooling.MAX)
  n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=50, weight_filler=dict(type='xavier'))
  n.pool2 = L.Pooling(n.conv2, kernel_size=2, stride=2, pool=P.Pooling.MAX)
  n.fc1 =   L.InnerProduct(n.pool2, num_output=500, weight_filler=dict(type='xavier'))
  n.relu1 = L.ReLU(n.fc1, in_place=True)
  n.score = L.InnerProduct(n.relu1, num_output=10, weight_filler=dict(type='xavier'))
  n.loss =  L.SoftmaxWithLoss(n.score, n.label)

  proto = n.to_proto()
  proto.name = 'LeNet'
  return proto
项目:pytorch-fcn    作者:wkentaro    | 项目源码 | 文件源码
def fcn(split, tops):
    n = caffe.NetSpec()
    n.color, n.hha, n.label = L.Python(module='nyud_layers',
            layer='NYUDSegDataLayer', ntop=3,
            param_str=str(dict(nyud_dir='../data/nyud', split=split,
                tops=tops, seed=1337)))
    n = modality_fcn(n, 'color', 'color')
    n = modality_fcn(n, 'hha', 'hha')
    n.score_fused = L.Eltwise(n.score_frcolor, n.score_frhha,
            operation=P.Eltwise.SUM, coeff=[0.5, 0.5])
    n.upscore = L.Deconvolution(n.score_fused,
        convolution_param=dict(num_output=40, kernel_size=64, stride=32,
            bias_term=False),
        param=[dict(lr_mult=0)])
    n.score = crop(n.upscore, n.color)
    n.loss = L.SoftmaxWithLoss(n.score, n.label,
            loss_param=dict(normalize=False, ignore_label=255))
    return n.to_proto()
项目:caffe-wrn-generator    作者:razorx89    | 项目源码 | 文件源码
def __create_network_prototxt(self, deploy):
        n = caffe.NetSpec()
        top = self.__create_data_layer(n, deploy=deploy)
        top = self.__create_first_convolutional_layer(n, top)

        # Create Residual Units
        for i in range(len(self.__num_residual_units)):
            stride = 1 if i == 0 else 2
            top = self.__layer(n, top, 'res%d' % (2+i), self.__wide_basic, self.__num_feature_maps[i],
                               self.__num_feature_maps[i+1], self.__num_residual_units[i], stride, deploy)

        top = self.__create_fully_connected_layer(n, top, deploy=deploy)
        self.__create_output_layer(n, top, deploy=deploy)

        # Return prototxt
        return str(n.to_proto()).replace('__test', '')
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data = L.Input(shape = dict(dim = [10,3,224,224]))

  block_1 = _block_crp('1', 2, net, net.data, 64)
  block_2 = _block_crp('2', 2, net, block_1,  128)
  block_3 = _block_crp('3', 4, net, block_2,  256)
  block_4 = _block_crp('4', 4, net, block_3,  512)
  block_5 = _block_crp('5', 4, net, block_4,  512)

  block_6 = _block_frd('6', net, block_5, 4096)
  block_7 = _block_frd('7', net, block_6, 4096)

  net.fc8 = L.InnerProduct(block_7, num_output = 1000)
  net.prob = L.Softmax(net.fc8)

  return net.to_proto()
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data = L.Input(shape = dict(dim = [10,3,224,224]))

  block_1 = _block_crp('1', 2, net, net.data, 64)
  block_2 = _block_crp('2', 2, net, block_1,  128)
  block_3 = _block_crp('3', 3, net, block_2,  256)
  block_4 = _block_crp('4', 3, net, block_3,  512)
  block_5 = _block_crp('5', 3, net, block_4,  512)

  block_6 = _block_frd('6', net, block_5, 4096)
  block_7 = _block_frd('7', net, block_6, 4096)

  net.fc8 = L.InnerProduct(block_7, num_output = 1000)
  net.prob = L.Softmax(net.fc8)

  return net.to_proto()
项目:DQN    作者:Ivehui    | 项目源码 | 文件源码
def overall_net(batch_size, channels, height, width, action_size, net_type):

    # param = learned_param
    n=caffe.NetSpec()
    # action
    n.frames = L.Input(shape=dict(dim=[batch_size, channels, height, width]))

    # Image feature
    if net_type == 'action':
        param = learned_param
    else:
        param = frozen_param

    n.conv1, n.relu1 = conv_relu(n.frames, 8, 32, stride=4, param=param)
    n.conv2, n.relu2 = conv_relu(n.relu1, 4, 64, stride=2, param=param)
    n.conv3, n.relu3 = conv_relu(n.relu2, 3, 64, stride=1, param=param)
    n.fc4, n.relu4 = fc_relu(n.relu3, 512, param=param)

    n.value_q = L.InnerProduct(n.relu4, num_output=action_size, param=param,
                               weight_filler=dict(type='gaussian', std=0.005),
                               bias_filler=dict(type='constant', value=1))

    if net_type == 'test':
        return n.to_proto()

    n.filter = L.Input(shape=dict(dim=[batch_size, action_size]))
    # operation 0: PROD
    n.filtered_value_q = L.Eltwise(n.value_q, n.filter, operation=0)

    n.target = L.Input(shape=dict(dim=[batch_size, action_size]))

    n.loss = L.EuclideanLoss(n.filtered_value_q, n.target)

    return n.to_proto()

### define solver
项目:self-augmented-net    作者:msraig    | 项目源码 | 文件源码
def __init__(self):
        self.net = caffe.NetSpec()
        self.testnet = caffe.NetSpec()
项目:dilation    作者:fyu    | 项目源码 | 文件源码
def make_frontend_vgg(options):
    deploy_net = caffe.NetSpec()
    deploy_net.data = network.make_input_data(options.input_size)
    last, final_name = network.build_frontend_vgg(
        deploy_net, deploy_net.data, options.classes)
    if options.up:
        deploy_net.upsample = network.make_upsample(last, options.classes)
        last = deploy_net.upsample
    deploy_net.prob = network.make_prob(last)
    deploy_net = deploy_net.to_proto()
    return deploy_net, final_name
项目:dilation    作者:fyu    | 项目源码 | 文件源码
def make_context(options):
    deploy_net = caffe.NetSpec()
    deploy_net.data = network.make_input_data(
        options.input_size, options.classes)
    last, final_name = network.build_context(
        deploy_net, deploy_net.data, options.classes, options.layers)
    if options.up:
        deploy_net.upsample = network.make_upsample(last, options.classes)
        last = deploy_net.upsample
    deploy_net.prob = network.make_prob(last)
    deploy_net = deploy_net.to_proto()
    return deploy_net, final_name
项目:Sensor-Specific-Hyperspectral-Image-Feature-Learning    作者:MeiShaohui    | 项目源码 | 文件源码
def deploy_net(conf, batch_size, class_num) :
    '''
    :param conf:  the data_set_config information, defined in data_info_set.item
    :param batch_size: the batch_size of prototxt
    :param class_num: the class_num of the data_set
    :param channels: the channels of hyperspectral data, maybe it is 224,448 or 103,206
    :param kernel_size: the kernel_size of the convolution layer, often is 1/9 of the channels
    :return: deploy file handle
    '''
    n = caffe.NetSpec()
    if conf.use_CK is True:
        n.data, n.label = L.DummyData(shape= {'dim' : [batch_size, 1, conf.CK_channels, 1]}, ntop = 2)
        n.conv1 = L.Convolution(n.data, kernel_h=conf.CK_kernel_size, kernel_w=1, num_output=20,
                                weight_filler=dict(type='gaussian', std=0.05),
                                bias_filler=dict(type='constant', value=0.1))
    else:
        n.data, n.label = L.DummyData(shape= {'dim' : [batch_size, 1, conf.channels, 1]}, ntop = 2)
        n.conv1 = L.Convolution(n.data, kernel_h = conf.kernel_size, kernel_w = 1, num_output = 20,
                                weight_filler = dict(type = 'gaussian', std = 0.05),
                                bias_filler = dict(type = 'constant', value = 0.1))
    n.bn1 = L.BatchNorm(n.conv1, use_global_stats = 1, in_place = True)
    n.relu1 = L.PReLU(n.bn1, in_place = True)
    n.ip1 = L.InnerProduct(n.relu1, num_output = 100, weight_filler = dict(type = 'gaussian', std = 0.05),
                           bias_filler = dict(type = 'constant', value = 0.1))
    n.drop1 = L.Dropout(n.ip1, dropout_ratio = 0.1, in_place = True)
    n.relu2 = L.PReLU(n.drop1, in_place = True)
    n.ip2 = L.InnerProduct(n.relu2, num_output = class_num, weight_filler = dict(type = 'gaussian', std = 0.05),
                            bias_filler = dict(type = 'constant', value = 0.1))
    return n.to_proto()
项目:caffe-model    作者:GeekLiB    | 项目源码 | 文件源码
def lenet_proto(self, batch_size, phase='TRAIN'):
        n = caffe.NetSpec()
        if phase == 'TRAIN':
            source_data = self.train_data
            mirror = False
        else:
            source_data = self.test_data
            mirror = False
        n.data, n.label = L.Data(source=source_data, backend=P.Data.LMDB, batch_size=batch_size, ntop=2,
                                 transform_param=dict(scale=0.00390625, mirror=mirror))

        n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20, stride=1,
                                weight_filler=dict(type='xavier'),
                                bias_filler=dict(type='constant'))
        n.pool1 = L.Pooling(n.conv1, pool=P.Pooling.MAX, kernel_size=2, stride=2)
        n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=50, stride=1,
                                weight_filler=dict(type='xavier'),
                                bias_filler=dict(type='constant'))
        n.pool2 = L.Pooling(n.conv2, pool=P.Pooling.MAX, kernel_size=2, stride=2)
        n.ip1 = L.InnerProduct(n.pool2, num_output=500,
                               weight_filler=dict(type='xavier'),
                               bias_filler=dict(type='constant'))
        n.relu1 = L.ReLU(n.ip1, in_place=True)
        n.ip2 = L.InnerProduct(n.relu1, num_output=self.classifier_num,
                               weight_filler=dict(type='xavier'),
                               bias_filler=dict(type='constant'))
        n.loss = L.SoftmaxWithLoss(n.ip2, n.label)
        if phase == 'TRAIN':
            pass
        else:
            n.accuracy = L.Accuracy(n.ip2, n.label, include=dict(phase=1))

        return n.to_proto()
项目:caffe-model    作者:GeekLiB    | 项目源码 | 文件源码
def lenet_bn_proto(self, batch_size, phase='TRAIN'):
        n = caffe.NetSpec()
        if phase == 'TRAIN':
            source_data = self.train_data
            mirror = False
        else:
            source_data = self.test_data
            mirror = False
        n.data, n.label = L.Data(source=source_data, backend=P.Data.LMDB, batch_size=batch_size, ntop=2,
                                 transform_param=dict(scale=0.00390625, mirror=mirror))

        n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20, stride=1,
                                weight_filler=dict(type='xavier'),
                                bias_filler=dict(type='constant'))
        n.bn1 = L.BatchNorm(n.conv1, use_global_stats=False)
        n.pool1 = L.Pooling(n.bn1, pool=P.Pooling.MAX, kernel_size=2, stride=2)
        n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=50, stride=1,
                                weight_filler=dict(type='xavier'),
                                bias_filler=dict(type='constant'))
        n.bn2 = L.BatchNorm(n.conv2, use_global_stats=False)
        n.pool2 = L.Pooling(n.bn2, pool=P.Pooling.MAX, kernel_size=2, stride=2)
        n.ip1 = L.InnerProduct(n.pool2, num_output=500,
                               weight_filler=dict(type='xavier'),
                               bias_filler=dict(type='constant'))
        n.relu1 = L.ReLU(n.ip1, in_place=True)
        n.ip2 = L.InnerProduct(n.relu1, num_output=self.classifier_num,
                               weight_filler=dict(type='xavier'),
                               bias_filler=dict(type='constant'))
        n.loss = L.SoftmaxWithLoss(n.ip2, n.label)
        if phase == 'TRAIN':
            pass
        else:
            n.accuracy = L.Accuracy(n.ip2, n.label, include=dict(phase=1))

        return n.to_proto()
项目:caffe-model    作者:GeekLiB    | 项目源码 | 文件源码
def alexnet_proto(self, batch_size, phase='TRAIN'):
        n = caffe.NetSpec()
        if phase == 'TRAIN':
            source_data = self.train_data
            mirror = True
        else:
            source_data = self.test_data
            mirror = False
        n.data, n.label = L.Data(source=source_data, backend=P.Data.LMDB, batch_size=batch_size, ntop=2,
                                 transform_param=dict(crop_size=227, mean_value=[104, 117, 123], mirror=mirror))

        n.conv1, n.relu1 = conv_relu(n.data, num_output=96, kernel_size=11, stride=4)  # 96x55x55
        n.norm1 = L.LRN(n.conv1, local_size=5, alpha=0.0001, beta=0.75)
        n.pool1 = L.Pooling(n.norm1, kernel_size=3, stride=2, pool=P.Pooling.MAX)  # 96x27x27

        n.conv2, n.relu2 = conv_relu(n.pool1, num_output=256, kernel_size=5, pad=2, group=2)  # 256x27x27
        n.norm2 = L.LRN(n.conv2, local_size=5, alpha=0.0001, beta=0.75)
        n.pool2 = L.Pooling(n.norm2, kernel_size=3, stride=2, pool=P.Pooling.MAX)  # 256x13x13

        n.conv3, n.relu3 = conv_relu(n.pool2, num_output=384, kernel_size=3, pad=1)  # 384x13x13
        n.conv4, n.relu4 = conv_relu(n.conv3, num_output=384, kernel_size=3, pad=1, group=2)  # 384x13x13

        n.conv5, n.relu5 = conv_relu(n.conv4, num_output=256, kernel_size=3, pad=1, group=2)  # 256x13x13
        n.pool5 = L.Pooling(n.conv5, kernel_size=3, stride=2, pool=P.Pooling.MAX)  # 256x6x16

        n.fc6, n.relu6, n.drop6 = fc_relu_drop(n.pool5, num_output=4096)  # 4096x1x1
        n.fc7, n.relu7, n.drop7 = fc_relu_drop(n.fc6, num_output=4096)  # 4096x1x1
        n.fc8 = L.InnerProduct(n.fc7, num_output=self.classifier_num,
                               param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)],
                               weight_filler=dict(type='gaussian', std=0.01),
                               bias_filler=dict(type='constant', value=0))
        n.loss = L.SoftmaxWithLoss(n.fc8, n.label)
        if phase == 'TRAIN':
            pass
        else:
            n.accuracy_top1, n.accuracy_top5 = accuracy_top1_top5(n.fc8, n.label)

        return n.to_proto()
项目:c3d_ucf101_siamese_yilin    作者:fxing328    | 项目源码 | 文件源码
def net(hdf5, batch_size):
    n = caffe.NetSpec()
    n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5, ntop=2)
    n.ip1 = L.InnerProduct(n.data, num_output=1024, weight_filler=dict(type='xavier'))
    n.relu1 = L.ReLU(n.ip1, in_place=True)
    n.ip2 = L.InnerProduct(n.relu1, num_output=1024, weight_filler=dict(type='xavier'))
    n.relu2 = L.ReLU(n.ip2, in_place=True)
    n.ip3 = L.InnerProduct(n.relu2, num_output=2, weight_filler=dict(type='xavier'))
    n.loss = L.SigmoidCrossEntropyLoss(n.ip3, n.label)
    return n.to_proto()
项目:c3d_ucf101_siamese_yilin    作者:fxing328    | 项目源码 | 文件源码
def net(hdf5, batch_size):
    n = caffe.NetSpec()
    n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5, ntop=2)
    n.ip1 = L.InnerProduct(n.data, num_output=1024, weight_filler=dict(type='xavier'))
    n.relu1 = L.ReLU(n.ip1, in_place=True)
    n.ip2 = L.InnerProduct(n.relu1, num_output=1024, weight_filler=dict(type='xavier'))
    n.relu2 = L.ReLU(n.ip2, in_place=True)
    n.ip3 = L.InnerProduct(n.relu2, num_output=2, weight_filler=dict(type='xavier'))
    n.loss = L.SigmoidCrossEntropyLoss(n.ip3, n.label)
    return n.to_proto()
项目:caffe-tools    作者:davidstutz    | 项目源码 | 文件源码
def test_train2deploy(self):
        """
        Test train to deploy conversion.
        """

        def network(lmdb_path, batch_size):
            net = caffe.NetSpec()

            net.data, net.labels = caffe.layers.Data(batch_size = batch_size, 
                                                     backend = caffe.params.Data.LMDB, 
                                                     source = lmdb_path, 
                                                     transform_param = dict(scale = 1./255), 
                                                     ntop = 2)

            net.conv1 = caffe.layers.Convolution(net.data, kernel_size = 5, num_output = 20, 
                                                 weight_filler = dict(type = 'xavier'))
            net.pool1 = caffe.layers.Pooling(net.conv1, kernel_size = 2, stride = 2, 
                                             pool = caffe.params.Pooling.MAX)
            net.conv2 = caffe.layers.Convolution(net.pool1, kernel_size = 5, num_output = 50, 
                                                 weight_filler = dict(type = 'xavier'))
            net.pool2 = caffe.layers.Pooling(net.conv2, kernel_size = 2, stride = 2, 
                                             pool = caffe.params.Pooling.MAX)
            net.fc1 =   caffe.layers.InnerProduct(net.pool2, num_output = 500, 
                                                  weight_filler = dict(type = 'xavier'))
            net.relu1 = caffe.layers.ReLU(net.fc1, in_place = True)
            net.score = caffe.layers.InnerProduct(net.relu1, num_output = 10, 
                                                  weight_filler = dict(type = 'xavier'))
            net.loss =  caffe.layers.SoftmaxWithLoss(net.score, net.labels)

            return net.to_proto()

        train_prototxt_path = 'tests/train.prototxt'
        deploy_prototxt_path = 'tests/deploy.prototxt'

        with open(train_prototxt_path, 'w') as f:
            f.write(str(network('tests/train_lmdb', 128)))

        tools.prototxt.train2deploy(train_prototxt_path, (128, 3, 28, 28), deploy_prototxt_path)
项目:deep_share    作者:luyongxi    | 项目源码 | 文件源码
def _update_deploy_net(self):
        """ Update deploy net. """
        self._deploy_net = caffe.NetSpec()
        data = self._add_input_layers(self._deploy_net, deploy=True)
        bottom_dict = self._add_intermediate_layers(self._deploy_net, data, deploy=True)
        self._add_output_layers(self._deploy_net, bottom_dict, deploy=True)
        # add input definition strings.
        self._deploy_str='input: {}\ninput_dim: {}\ninput_dim: {}\ninput_dim: {}\ninput_dim: {}'.\
            format('"'+self.io.data_name+'"', 1, 3, 224, 224)
项目:deep_share    作者:luyongxi    | 项目源码 | 文件源码
def _update_trainval_net(self):
        """ Update trainval net. """
        self._train_net = caffe.NetSpec()
        self._val_net = caffe.NetSpec()
        in_nets = {'train': self._train_net, 'val': self._val_net}
        data = self._add_input_layers(in_nets, deploy=False)
        bottom_dict = self._add_intermediate_layers(self._train_net, data, deploy=False)
        self._add_output_layers(self._train_net, bottom_dict, deploy=False)
项目:Land_Use_CNN    作者:BUPTLdy    | 项目源码 | 文件源码
def caffenet(data, label=None, train=True, num_classes=1000,
             classifier_name='fc8', learn_all=False):
    """Returns a NetSpec specifying CaffeNet, following the original proto text
       specification (./models/bvlc_reference_caffenet/train_val.prototxt)."""
    n = caffe.NetSpec()
    n.data = data
    param = learned_param if learn_all else frozen_param
    n.conv1, n.relu1 = conv_relu(n.data, 11, 96, stride=4, param=param)
    n.pool1 = max_pool(n.relu1, 3, stride=2)
    n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75)
    n.conv2, n.relu2 = conv_relu(n.norm1, 5, 256, pad=2, group=2, param=param)
    n.pool2 = max_pool(n.relu2, 3, stride=2)
    n.norm2 = L.LRN(n.pool2, local_size=5, alpha=1e-4, beta=0.75)
    n.conv3, n.relu3 = conv_relu(n.norm2, 3, 384, pad=1, param=param)
    n.conv4, n.relu4 = conv_relu(n.relu3, 3, 384, pad=1, group=2, param=param)
    n.conv5, n.relu5 = conv_relu(n.relu4, 3, 256, pad=1, group=2, param=param)
    n.pool5 = max_pool(n.relu5, 3, stride=2)
    n.fc6, n.relu6 = fc_relu(n.pool5, 4096, param=param)
    if train:
        n.drop6 = fc7input = L.Dropout(n.relu6, in_place=True)
    else:
        fc7input = n.relu6
    n.fc7, n.relu7 = fc_relu(fc7input, 4096, param=param)
    if train:
        n.drop7 = fc8input = L.Dropout(n.relu7, in_place=True)
    else:
        fc8input = n.relu7
    # always learn fc8 (param=learned_param)
    fc8 = L.InnerProduct(fc8input, num_output=num_classes, param=learned_param)
    # give fc8 the name specified by argument `classifier_name`
    n.__setattr__(classifier_name, fc8)
    if not train:
        n.probs = L.Softmax(fc8)
    if label is not None:
        n.label = label
        n.loss = L.SoftmaxWithLoss(fc8, n.label)
        n.acc = L.Accuracy(fc8, n.label)
    # write the net to a temporary file and return its filename
    with open('/home/ldy/workspace/caffe/models/finetune_UCMerced_LandUse/deploy.prototxt','w') as f:
        f.write(str(n.to_proto()))
        return f.name
项目:DeepLearning    作者:corecai163    | 项目源码 | 文件源码
def customNet(lmdb,batch_size):
    #define Lenet
    n = caffe.NetSpec()

    n.data, n.label = L.Data(batch_size=batch_size, backend=P.Data.LMDB, source=lmdb, transform_param=dict(scale=1./255),ntop=2)

    n.conv1 = L.Convolution(n.data, kernel_size=3, num_output=20, weight_filler=dict(type='xavier'))
    n.bn1 = L.BatchNorm(n.conv1,in_place=True)    
    n.scale1 = L.Scale(n.bn1,bias_term=True,bias_filler=dict(value=0),filler=dict(value=1))    
    n.conv2 = L.Convolution(n.scale1, kernel_size=3,stride=2, num_output=20, weight_filler=dict(type='xavier'))
    n.bn2 = L.BatchNorm(n.conv2,in_place=True)        
    n.scale2 = L.Scale(n.bn2,bias_term=True,bias_filler=dict(value=0),filler=dict(value=1))        
#    n.pool1 = L.Pooling(n.scale2, kernel_size=2, stride=2, pool=P.Pooling.MAX)
    n.conv3 = L.Convolution(n.scale2, kernel_size=3, num_output=50, weight_filler = dict(type='xavier'))
    n.bn3 = L.BatchNorm(n.conv3,in_place=True)        
    n.scale3 = L.Scale(n.bn3,bias_term=True,bias_filler=dict(value=0),filler=dict(value=1))        
    n.conv4 = L.Convolution(n.scale3, kernel_size=3, stride=2,num_output=50, weight_filler=dict(type='xavier'))
    n.bn4 = L.BatchNorm(n.conv4,in_place=True)        
    n.scale4 = L.Scale(n.bn4,bias_term=True,bias_filler=dict(value=0),filler=dict(value=1))    

#    n.pool2 = L.Pooling(n.scale4, kernel_size=2, stride=2, pool=P.Pooling.MAX)
    n.fc1 = L.InnerProduct(n.scale4, num_output=500, weight_filler=dict(type='xavier'))
    n.relu1 = L.ReLU(n.fc1, in_place=True)
    n.fc2 = L.InnerProduct(n.relu1, num_output=100, weight_filler=dict(type='xavier'))
    n.relu2 = L.ReLU(n.fc2, in_place=True)
    n.score = L.InnerProduct(n.relu2,num_output=10, weight_filler=dict(type='xavier'))
    n.loss = L.SoftmaxWithLoss(n.score, n.label)

    return n.to_proto()
项目:DeepLearning    作者:corecai163    | 项目源码 | 文件源码
def caffenet_multilabel(data_layer_params, datalayer):
    # setup the python data layer 
    n = caffe.NetSpec()
    n.data, n.label = L.Python(module = 'pascal_multilabel_datalayers', layer = datalayer, 
                               ntop = 2, param_str=str(data_layer_params))

    # the net itself
    n.conv1, n.relu1 = conv_relu(n.data, 11, 96, stride=4)
    n.pool1 = max_pool(n.relu1, 3, stride=2)
    n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75)
    n.conv2, n.relu2 = conv_relu(n.norm1, 5, 256, pad=2, group=2)
    n.pool2 = max_pool(n.relu2, 3, stride=2)
    n.norm2 = L.LRN(n.pool2, local_size=5, alpha=1e-4, beta=0.75)
    n.conv3, n.relu3 = conv_relu(n.norm2, 3, 384, pad=1)
    n.conv4, n.relu4 = conv_relu(n.relu3, 3, 384, pad=1, group=2)
    n.conv5, n.relu5 = conv_relu(n.relu4, 3, 256, pad=1, group=2)
    n.pool5 = max_pool(n.relu5, 3, stride=2)
    n.fc6, n.relu6 = fc_relu(n.pool5, 4096)
    n.drop6 = L.Dropout(n.relu6, in_place=True)
    n.fc7, n.relu7 = fc_relu(n.drop6, 4096)
    n.drop7 = L.Dropout(n.relu7, in_place=True)
    n.score = L.InnerProduct(n.drop7, num_output=20)
    n.loss = L.SigmoidCrossEntropyLoss(n.score, n.label)

    return str(n.to_proto())

# crete net and solver prototxts.
项目:DeepLearning    作者:corecai163    | 项目源码 | 文件源码
def logreg(hdf5, batch_size):
    # logistic regression: data, matrix multiplication, and 2-class softmax loss
    n=caffe.NetSpec()
    n.data,n.label = L.HDF5Data(batch_size=batch_size,source=hdf5,ntop=2)
    n.ip1 = L.InnerProduct(n.data,num_output=2,weight_filler=dict(type='xavier'))
    n.accuracy = L.Accuracy(n.ip1,n.label)
    n.loss = L.SoftmaxWithLoss(n.ip1,n.label)
    return n.to_proto()
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def SketchTriplet_anchor(out_dim):
  n = caffe.NetSpec()
  n.data_a              = L.Input(name='data',
                                  shape=dict(dim=[1,1,225,225]))
  n.conv1_a, n.relu1_a  = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
  n.pool1_a = pooling(n.relu1_a, 3, stride=2)

  n.conv2_a, n.relu2_a  = conv_relu_triplet_dep(n.pool1_a, 5, 128)
  n.pool2_a = pooling(n.relu2_a, 3, stride=2)

  n.conv3_a, n.relu3_a  = conv_relu_triplet_dep(n.pool2_a, 3, 256)

  n.conv4_a, n.relu4_a  = conv_relu_triplet_dep(n.relu3_a, 3, 256)

  n.conv5_a, n.relu5_a  = conv_relu_triplet_dep(n.relu4_a, 3, 256)
  n.pool5_a = pooling(n.relu5_a, 3, stride=2)

  n.fc6_a, n.relu6_a    = fc_relu_triplet_dep(n.pool5_a, 512)

  n.fc7_a, n.relu7_a    = fc_relu_triplet_dep(n.relu6_a, 512)

  #n.fc8_a, n.feat_a     = fc_norm_triplet_dep(n.relu7_a, out_dim)
  n.feat_a     = fc_triplet_dep(n.relu7_a, out_dim)
  proto = n.to_proto()
  proto.name = 'SketchTriplet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def SketchTriplet_pos(out_dim):
  n = caffe.NetSpec()
  n.data_p              = L.Input(name='data',
                                  shape=dict(dim=[1,1,225,225]))
  n.conv1_p, n.relu1_p  = conv_relu_triplet_dep(n.data_p, 15, 64, stride = 3)
  n.pool1_p = pooling(n.relu1_p, 3, stride=2)

  n.conv2_p, n.relu2_p  = conv_relu_triplet_dep(n.pool1_p, 5, 128)
  n.pool2_p = pooling(n.relu2_p, 3, stride=2)

  n.conv3_p, n.relu3_p  = conv_relu_triplet_dep(n.pool2_p, 3, 256)

  n.conv4_p, n.relu4_p  = conv_relu_triplet_dep(n.relu3_p, 3, 256)

  n.conv5_p, n.relu5_p  = conv_relu_triplet_dep(n.relu4_p, 3, 256)
  n.pool5_p = pooling(n.relu5_p, 3, stride=2)

  n.fc6_p, n.relu6_p    = fc_relu_triplet_dep(n.pool5_p, 512)

  n.fc7_p, n.relu7_p    = fc_relu_triplet_dep(n.relu6_p, 512)

  #n.fc8_p, n.feat_p     = fc_norm_triplet_dep(n.relu7_p, out_dim)
  n.feat_p     = fc_triplet_dep(n.relu7_p, out_dim)
  proto = n.to_proto()
  proto.name = 'SketchTriplet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def SketchTriplet_anchor(out_dim):
  n = caffe.NetSpec()
  n.data_a              = L.Input(name='data',
                                  shape=dict(dim=[1,1,225,225]))
  n.conv1_a, n.relu1_a  = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
  n.pool1_a = pooling(n.relu1_a, 3, stride=2)

  n.conv2_a, n.relu2_a  = conv_relu_triplet_dep(n.pool1_a, 5, 128)
  n.pool2_a = pooling(n.relu2_a, 3, stride=2)

  n.conv3_a, n.relu3_a  = conv_relu_triplet_dep(n.pool2_a, 3, 256)

  n.conv4_a, n.relu4_a  = conv_relu_triplet_dep(n.relu3_a, 3, 256)

  n.conv5_a, n.relu5_a  = conv_relu_triplet_dep(n.relu4_a, 3, 256)
  n.pool5_a = pooling(n.relu5_a, 3, stride=2)

  n.fc6_a, n.relu6_a    = fc_relu_triplet_dep(n.pool5_a, 512)

  n.fc7_a, n.relu7_a    = fc_relu_triplet_dep(n.relu6_a, 512)

  #n.fc8_a, n.feat_a     = fc_norm_triplet_dep(n.relu7_a, out_dim)
  n.feat_a     = fc_triplet_dep(n.relu7_a, out_dim)
  proto = n.to_proto()
  proto.name = 'SketchTriplet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def SketchTriplet_pos(out_dim):
  n = caffe.NetSpec()
  n.data_p              = L.Input(name='data',
                                  shape=dict(dim=[1,1,225,225]))
  n.conv1_p, n.relu1_p  = conv_relu_triplet_dep(n.data_p, 15, 64, stride = 3)
  n.pool1_p = pooling(n.relu1_p, 3, stride=2)

  n.conv2_p, n.relu2_p  = conv_relu_triplet_dep(n.pool1_p, 5, 128)
  n.pool2_p = pooling(n.relu2_p, 3, stride=2)

  n.conv3_p, n.relu3_p  = conv_relu_triplet_dep(n.pool2_p, 3, 256)

  n.conv4_p, n.relu4_p  = conv_relu_triplet_dep(n.relu3_p, 3, 256)

  n.conv5_p, n.relu5_p  = conv_relu_triplet_dep(n.relu4_p, 3, 256)
  n.pool5_p = pooling(n.relu5_p, 3, stride=2)

  n.fc6_p, n.relu6_p    = fc_relu_triplet_dep(n.pool5_p, 512)

  n.fc7_p, n.relu7_p    = fc_relu_triplet_dep(n.relu6_p, 512)

  #n.fc8_p, n.feat_p     = fc_norm_triplet_dep(n.relu7_p, out_dim)
  n.feat_p     = fc_triplet_dep(n.relu7_p, out_dim)
  proto = n.to_proto()
  proto.name = 'SketchTriplet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def SketchTriplet_anchor(out_dim):
  n = caffe.NetSpec()
  n.data_a              = L.Input(name='data',
                                  shape=dict(dim=[1,1,225,225]))
  n.conv1_a, n.relu1_a  = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
  n.pool1_a = pooling(n.relu1_a, 3, stride=2)

  n.conv2_a, n.relu2_a  = conv_relu_triplet_dep(n.pool1_a, 5, 128)
  n.pool2_a = pooling(n.relu2_a, 3, stride=2)

  n.conv3_a, n.relu3_a  = conv_relu_triplet_dep(n.pool2_a, 3, 256)

  n.conv4_a, n.relu4_a  = conv_relu_triplet_dep(n.relu3_a, 3, 256)

  n.conv5_a, n.relu5_a  = conv_relu_triplet_dep(n.relu4_a, 3, 256)
  n.pool5_a = pooling(n.relu5_a, 3, stride=2)

  n.fc6_a, n.relu6_a    = fc_relu_triplet_dep(n.pool5_a, 512)

  n.fc7_a, n.relu7_a    = fc_relu_triplet_dep(n.relu6_a, 512)

  #n.fc8_a, n.feat_a     = fc_norm_triplet_dep(n.relu7_a, out_dim)
  n.feat_a     = fc_triplet_dep(n.relu7_a, out_dim)
  n.norm_a = L.Normalize(n.feat_a,in_place=True)

  proto = n.to_proto()
  proto.name = 'SketchTriplet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def siamese_anchor(out_dim=100):
  n = caffe.NetSpec()
  n.data_a              = L.Input(name='data',
                                  shape=dict(dim=[1,1,225,225]))
  n.conv1_a, n.relu1_a  = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
  n.pool1_a = pooling(n.relu1_a, 3, stride=2)

  n.conv2_a, n.relu2_a  = conv_relu_triplet_dep(n.pool1_a, 5, 128)
  n.pool2_a = pooling(n.relu2_a, 3, stride=2)

  n.conv3_a, n.relu3_a  = conv_relu_triplet_dep(n.pool2_a, 3, 256)

  n.conv4_a, n.relu4_a  = conv_relu_triplet_dep(n.relu3_a, 3, 256)

  n.conv5_a, n.relu5_a  = conv_relu_triplet_dep(n.relu4_a, 3, 256)
  n.pool5_a = pooling(n.relu5_a, 3, stride=2)

  n.fc6_a, n.relu6_a    = fc_relu_triplet_dep(n.pool5_a, 512)

  n.fc7_a, n.relu7_a    = fc_relu_triplet_dep(n.relu6_a, 512)

  #n.fc8_a, n.feat_a     = fc_norm_triplet_dep(n.relu7_a, out_dim)
  n.feat_a     = fc_triplet_dep(n.relu7_a, out_dim)
  #n.norm_a = L.Normalize(n.feat_a,in_place=True)

  proto = n.to_proto()
  proto.name = 'SketchTriplet'
  return proto
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def siamese_pos(out_dim=100):
  n = caffe.NetSpec()
  n.data_p              = L.Input(name='data',
                                  shape=dict(dim=[1,1,225,225]))
  n.conv1_p, n.relu1_p  = conv_relu_triplet_dep(n.data_p, 15, 64, stride = 3)
  n.pool1_p = pooling(n.relu1_p, 3, stride=2)

  n.conv2_p, n.relu2_p  = conv_relu_triplet_dep(n.pool1_p, 5, 128)
  n.pool2_p = pooling(n.relu2_p, 3, stride=2)

  n.conv3_p, n.relu3_p  = conv_relu_triplet_dep(n.pool2_p, 3, 256)

  n.conv4_p, n.relu4_p  = conv_relu_triplet_dep(n.relu3_p, 3, 256)

  n.conv5_p, n.relu5_p  = conv_relu_triplet_dep(n.relu4_p, 3, 256)
  n.pool5_p = pooling(n.relu5_p, 3, stride=2)

  n.fc6_p, n.relu6_p    = fc_relu_triplet_dep(n.pool5_p, 512)

  n.fc7_p, n.relu7_p    = fc_relu_triplet_dep(n.relu6_p, 512)

  #n.fc8_p, n.feat_p     = fc_norm_triplet_dep(n.relu7_p, out_dim)
  n.feat_p     = fc_triplet_dep(n.relu7_p, out_dim)
  #n.norm_p = L.Normalize(n.feat_p,in_place=True)

  proto = n.to_proto()
  proto.name = 'SketchTriplet'
  return proto
项目:phocnet    作者:ssudholt    | 项目源码 | 文件源码
def get_phocnet(self, word_image_lmdb_path, phoc_lmdb_path,
                    phoc_size=604, generate_deploy=False):
        '''
        Returns a NetSpec definition of the PHOCNet. The definition can then be transformed
        into a protobuffer message by casting it into a str.
        '''
        n = NetSpec()
        # Data
        self.set_phocnet_data(n=n, generate_deploy=generate_deploy,
                              word_image_lmdb_path=word_image_lmdb_path,
                              phoc_lmdb_path=phoc_lmdb_path)

        # Conv Part
        self.set_phocnet_conv_body(n=n, relu_in_place=True)

        # FC Part
        n.spp5 = L.SPP(n.relu4_3, spp_param=dict(pool=P.SPP.MAX, pyramid_height=3, engine=self.spp_engine))
        n.fc6, n.relu6, n.drop6 = self.fc_relu(bottom=n.spp5, layer_size=4096,
                                               dropout_ratio=0.5, relu_in_place=True)
        n.fc7, n.relu7, n.drop7 = self.fc_relu(bottom=n.drop6, layer_size=4096,
                                               dropout_ratio=0.5, relu_in_place=True)
        n.fc8 = L.InnerProduct(n.drop7, num_output=phoc_size,
                               weight_filler=dict(type=self.initialization),
                               bias_filler=dict(type='constant'))
        n.sigmoid = L.Sigmoid(n.fc8, include=dict(phase=self.phase_test))

        # output part
        if not generate_deploy:
            n.silence = L.Silence(n.sigmoid, ntop=0, include=dict(phase=self.phase_test))
            n.loss = L.SigmoidCrossEntropyLoss(n.fc8, n.phocs)

        return n.to_proto()
项目:phocnet    作者:ssudholt    | 项目源码 | 文件源码
def get_tpp_phocnet(self, word_image_lmdb_path, phoc_lmdb_path, phoc_size, tpp_levels=5,
                        generate_deploy=False):
        '''
        Returns a NetSpec definition of the TPP-PHOCNet. The definition can then be transformed
        into a protobuffer message by casting it into a str.
        '''
        n = NetSpec()
        # Data
        self.set_phocnet_data(n=n, generate_deploy=generate_deploy,
                              word_image_lmdb_path=word_image_lmdb_path,
                              phoc_lmdb_path=phoc_lmdb_path)

        # Conv Part
        self.set_phocnet_conv_body(n=n, relu_in_place=True)

        # FC Part
        n.tpp5 = L.TPP(n.relu4_3, tpp_param=dict(pool=P.TPP.MAX, pyramid_layer=range(1, tpp_levels + 1), engine=self.spp_engine))
        n.fc6, n.relu6, n.drop6 = self.fc_relu(bottom=n.tpp5, layer_size=4096,
                                               dropout_ratio=0.5, relu_in_place=True)
        n.fc7, n.relu7, n.drop7 = self.fc_relu(bottom=n.drop6, layer_size=4096,
                                               dropout_ratio=0.5, relu_in_place=True)
        n.fc8 = L.InnerProduct(n.drop7, num_output=phoc_size,
                               weight_filler=dict(type=self.initialization),
                               bias_filler=dict(type='constant'))
        n.sigmoid = L.Sigmoid(n.fc8, include=dict(phase=self.phase_test))

        # output part
        if not generate_deploy:
            n.silence = L.Silence(n.sigmoid, ntop=0, include=dict(phase=self.phase_test))
            n.loss = L.SigmoidCrossEntropyLoss(n.fc8, n.phocs)

        return n.to_proto()
项目:FCNN_cell    作者:ale93111    | 项目源码 | 文件源码
def lenethdf5(hdf5 , batch_size):
    # Net: a series of linear and simple nonlinear transformations
    n = caffe.NetSpec()

    n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5,ntop=2)


    # the base net
    n.conv1, n.relu1 = conv_relu(n.data, 32)
    n.pool1 = max_pool(n.relu1)

    n.conv2, n.relu2 = conv_relu(n.pool1, 64)
    n.pool2 = max_pool(n.relu2)    
    n.conv3, n.relu3 = conv_relu(n.pool2, 128)
    n.pool3 = max_pool(n.relu3)      

    # fully convolutional
    n.fc1, n.rlfc1  = conv_relu(n.pool3, 512, ks=3, pad=1)


    n.decov5 = deconv(n.rlfc1, 128, pad=1)
    n.relu5, n.conv5 = relu_conv(n.decov5, 128, pad=0)
    n.decov6 = deconv(n.conv5, 64, pad=1)
    n.relu6, n.conv6 = relu_conv(n.decov6, 64, pad=0)
    n.decov7 = deconv(n.conv6, 32, pad=1)
    n.relu7, n.conv7 = relu_conv(n.decov7, 32, pad=0)

    n.relu8, n.conv8 = relu_conv(n.conv7, 2, pad=0)

    n.accuracy= L.Accuracy(n.conv8, n.label)        
    n.loss =  L.SoftmaxWithLoss(n.conv8, n.label)




    return n.to_proto()

# create file prototxt for training and validation
项目:FCNN_cell    作者:ale93111    | 项目源码 | 文件源码
def lenethdf5d():
    # our version of LeNet: a series of linear and simple nonlinear transformations
    n = caffe.NetSpec()
    #cambiano il primo e gli ultimi 2 strati
    n.data = L.Input(input_param=dict(shape=dict(dim=[1,1,128,128])))

    # the base net
    n.conv1, n.relu1 = conv_relu(n.data, 32)
    n.pool1 = max_pool(n.relu1)
    #n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75)
    n.conv2, n.relu2 = conv_relu(n.pool1, 64)
    n.pool2 = max_pool(n.relu2)    
    n.conv3, n.relu3 = conv_relu(n.pool2, 128)
    n.pool3 = max_pool(n.relu3)      

    # fully convolutional
    n.fc1, n.rlfc1  = conv_relu(n.pool3, 512, ks=3, pad=1)


    n.decov5 = deconv(n.rlfc1, 128, pad=1)
    n.relu5, n.conv5 = relu_conv(n.decov5, 128, pad=0)
    n.decov6 = deconv(n.conv5, 64, pad=1)
    n.relu6, n.conv6 = relu_conv(n.decov6, 64, pad=0)
    n.decov7 = deconv(n.conv6, 32, pad=1)
    n.relu7, n.conv7 = relu_conv(n.decov7, 32, pad=0)

    n.relu8, n.conv8 = relu_conv(n.conv7, 2, pad=0)  


    n.prob = L.Softmax(n.conv8)

    return n.to_proto()

# create file prototxt for deployment
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net(widening_factor, num_block_per_stage):
  net = caffe.NetSpec()

  net.data  = L.Input(input_param = dict(shape = dict(dim = [1,3,32,32])))

  net.conv1 = L.Convolution(net.data, num_output = 16,
                            kernel_size = 3, stride = 1, pad = 1,
                            bias_term = False)

  # stage 1
  num_out = widening_factor * 16
  block_pre = _block('2_1', net, net.conv1, num_out, has_branch1=True, increasing_dims=False)
  for idx in xrange(2,num_block_per_stage+1,1):
    flag = '2_{}'.format(idx)
    block_pre = _block(flag, net, block_pre, num_out)

  # stage 2
  num_out = widening_factor * 32
  block_pre = _block('3_1', net, block_pre, num_out, has_branch1=True)
  for idx in xrange(2,num_block_per_stage+1,1):
    flag = '3_{}'.format(idx)
    block_pre = _block(flag, net, block_pre, num_out)

  # stage 3
  num_out = widening_factor * 64
  block_pre = _block('4_1', net, block_pre, num_out, has_branch1=True)
  for idx in xrange(2,num_block_per_stage+1,1):
    flag = '4_{}'.format(idx)
    block_pre = _block(flag, net, block_pre, num_out)

  net.bn5    = L.BatchNorm(block_pre)
  net.scale5 = L.Scale(net.bn5, bias_term = True, in_place=True)
  net.relu5  = L.ReLU(net.scale5, in_place = True)
  net.pool5  = L.Pooling(net.relu5, pool = P.Pooling.AVE, global_pooling=True)

  net.fc6 = L.InnerProduct(net.pool5, num_output = 10)
  net.prob = L.Softmax(net.fc6)

  return net.to_proto()
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data  = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))

  block1    = _block_first(net, net.data)

  net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)

  branch_2a = _branch('2a', net, net.pool1, 64, has_branch1 = True, is_branch_2a = True)
  branch_2b = _branch('2b', net, branch_2a, 64)
  branch_2c = _branch('2c', net, branch_2b, 64)

  branch_3a = _branch('3a', net, branch_2c, 128, has_branch1 = True)
  branch_3b = _branch('3b', net, branch_3a, 128)
  branch_3c = _branch('3c', net, branch_3b, 128)
  branch_3d = _branch('3d', net, branch_3c, 128)

  branch_4a = _branch('4a', net, branch_3d, 256, has_branch1 = True)
  branch_pre = branch_4a
  for idx in xrange(1,23,1): # conv4_x total 1+22=23
    flag = '4b{}'.format(idx)
    branch_pre = _branch(flag, net, branch_pre, 256)

  branch_5a = _branch('5a', net, branch_pre, 512, has_branch1 = True)
  branch_5b = _branch('5b', net, branch_5a, 512)
  branch_5c = _branch('5c', net, branch_5b, 512)

  net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)

  net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
  net.prob = L.Softmax(net.fc6)

  return net.to_proto()
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data  = L.Input(input_param = dict(shape = dict(dim = [1,1,224,224])))

  block1    = _block_first(net, net.data)

  net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)

  branch_2a = _branch('2a', net, net.pool1, 64, has_branch1 = True, is_branch_2a = True)
  branch_2b = _branch('2b', net, branch_2a, 64)
  branch_2c = _branch('2c', net, branch_2b, 64)

  branch_3a = _branch('3a', net, branch_2c, 128, has_branch1 = True)
  branch_3b = _branch('3b', net, branch_3a, 128)
  branch_3c = _branch('3c', net, branch_3b, 128)
  branch_3d = _branch('3d', net, branch_3c, 128)

  branch_4a = _branch('4a', net, branch_3d, 256, has_branch1 = True)
  branch_4b = _branch('4b', net, branch_4a, 256)
  branch_4c = _branch('4c', net, branch_4b, 256)
  branch_4d = _branch('4d', net, branch_4c, 256)
  branch_4e = _branch('4e', net, branch_4d, 256)
  branch_4f = _branch('4f', net, branch_4e, 256)

  branch_5a = _branch('5a', net, branch_4f, 512, has_branch1 = True)
  branch_5b = _branch('5b', net, branch_5a, 512)
  branch_5c = _branch('5c', net, branch_5b, 512)

  net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)

  net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
  net.prob = L.Softmax(net.fc6)

  return net.to_proto()
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data  = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))

  block1    = _block_first(net, net.data)

  net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)

  branch_2a = _branch('2a', net, net.pool1, 64, has_branch1 = True, is_branch_2a = True)
  branch_2b = _branch('2b', net, branch_2a, 64)
  branch_2c = _branch('2c', net, branch_2b, 64)

  branch_3a = _branch('3a', net, branch_2c, 128, has_branch1 = True)
  branch_pre = branch_3a
  for idx in xrange(1,8,1): # conv3_x total 1+7=8
    flag = '3b{}'.format(idx)
    branch_pre = _branch(flag, net, branch_pre, 128)

  branch_4a = _branch('4a', net, branch_pre, 256, has_branch1 = True)
  branch_pre = branch_4a
  for idx in xrange(1,36,1): # conv4_x total 1+35=36
    flag = '4b{}'.format(idx)
    branch_pre = _branch(flag, net, branch_pre, 256)

  branch_5a = _branch('5a', net, branch_pre, 512, has_branch1 = True)
  branch_5b = _branch('5b', net, branch_5a, 512)
  branch_5c = _branch('5c', net, branch_5b, 512)

  net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)

  net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
  net.prob = L.Softmax(net.fc6)

  return net.to_proto()
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data = L.Input(shape = dict(dim = [10,3,224,224]))
  block_cr_1 = _block_cr('conv1', '7x7_s2', net, net.data, 64, 3, 7, 2)
  pool_layer_1 = 'pool1/3x3_s2'
  net[pool_layer_1] = L.Pooling(block_cr_1, pool = P.Pooling.MAX,
                                kernel_size = 3, stride = 2)
  ##LRN
  block_cr_2_reduce = _block_cr('conv2', '3x3_reduce', net, net[pool_layer_1], 64, 0, 1, 1)
  block_cr_2 = _block_cr('conv2', '3x3', net, block_cr_2_reduce, 192, 1, 3, 1)
  ##LRN
  pool_layer_2 = 'pool2/3x3_s2'
  net[pool_layer_2] = L.Pooling(block_cr_2, pool = P.Pooling.MAX,
                                kernel_size = 3, stride = 2)
  inception_3a = _inception_v1('inception_3a', net, net[pool_layer_2], [64,96,128,16,32,32])
  inception_3b = _inception_v1('inception_3b', net, inception_3a, [128,128,192,32,96,64])
  pool_layer_3 = 'pool3/3x3_s2'
  net[pool_layer_3] = L.Pooling(inception_3b, pool = P.Pooling.MAX,
                                kernel_size = 3, stride = 2)
  inception_4a = _inception_v1('inception_4a', net, net[pool_layer_3], [192,96,208,16,48,64])
  inception_4b = _inception_v1('inception_4b', net, inception_4a, [160,112,224,24,64,64])
  inception_4c = _inception_v1('inception_4c', net, inception_4b, [128,128,256,24,64,64])
  inception_4d = _inception_v1('inception_4d', net, inception_4c, [112,144,288,32,64,64])
  inception_4e = _inception_v1('inception_4e', net, inception_4d, [256,160,320,32,128,128])
  pool_layer_4 = 'pool4/3x3_s2'
  net[pool_layer_4] = L.Pooling(inception_4e, pool = P.Pooling.MAX,
                                kernel_size = 3, stride = 2)
  inception_5a = _inception_v1('inception_5a', net, net[pool_layer_4], [256,160,320,32,128,128])
  inception_5b = _inception_v1('inception_5b', net, inception_5a, [384,192,384,48,128,128])
  pool_layer_5 = 'pool5/7x7_s1'
  net[pool_layer_5] = L.Pooling(inception_5b, pool = P.Pooling.AVE,
                                kernel_size = 7, stride = 1)
  pool_layer_5_drop = 'pool5/drop_7x7_s1'
  net[pool_layer_5_drop] = L.Dropout(net[pool_layer_5], dropout_ratio = 0.4, in_place = True)
  fc_layer = 'loos3/classifier'
  net[fc_layer] = L.InnerProduct(net[pool_layer_5_drop], num_output = 1000)
  net.prob = L.Softmax(net[fc_layer])

  return net.to_proto()
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data  = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))

  block1    = _block_first(net, net.data)

  net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)

  branch_2a = _branch('2a', net, net.pool1, 128, has_branch1 = True, is_branch_2a = True)
  branch_2b = _branch('2b', net, branch_2a, 128)
  branch_2c = _branch('2c', net, branch_2b, 128)

  branch_3a = _branch('3a', net, branch_2c, 256, has_branch1 = True)
  branch_3b = _branch('3b', net, branch_3a, 256)
  branch_3c = _branch('3c', net, branch_3b, 256)
  branch_3d = _branch('3d', net, branch_3c, 256)

  branch_4a = _branch('4a', net, branch_3d, 512, has_branch1 = True)
  branch_pre = branch_4a
  for idx in xrange(1,23,1): # conv4_x total 1+22=23
    flag = '4b{}'.format(idx)
    branch_pre = _branch(flag, net, branch_pre, 512)

  branch_5a = _branch('5a', net, branch_pre, 1024, has_branch1 = True)
  branch_5b = _branch('5b', net, branch_5a,  1024)
  branch_5c = _branch('5c', net, branch_5b,  1024)

  net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)

  net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
  net.prob = L.Softmax(net.fc6)

  return net.to_proto()
项目:caffe_toolkit    作者:binLearning    | 项目源码 | 文件源码
def construc_net():
  net = caffe.NetSpec()

  net.data  = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))

  block1    = _block_first(net, net.data)

  net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)

  branch_2a = _branch('2a', net, net.pool1, 128, has_branch1 = True, is_branch_2a = True)
  branch_2b = _branch('2b', net, branch_2a, 128)
  branch_2c = _branch('2c', net, branch_2b, 128)

  branch_3a = _branch('3a', net, branch_2c, 256, has_branch1 = True)
  branch_3b = _branch('3b', net, branch_3a, 256)
  branch_3c = _branch('3c', net, branch_3b, 256)
  branch_3d = _branch('3d', net, branch_3c, 256)

  branch_4a = _branch('4a', net, branch_3d, 512, has_branch1 = True)
  branch_4b = _branch('4b', net, branch_4a, 512)
  branch_4c = _branch('4c', net, branch_4b, 512)
  branch_4d = _branch('4d', net, branch_4c, 512)
  branch_4e = _branch('4e', net, branch_4d, 512)
  branch_4f = _branch('4f', net, branch_4e, 512)

  branch_5a = _branch('5a', net, branch_4f, 1024, has_branch1 = True)
  branch_5b = _branch('5b', net, branch_5a, 1024)
  branch_5c = _branch('5c', net, branch_5b, 1024)

  net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)

  net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
  net.prob = L.Softmax(net.fc6)

  return net.to_proto()