Exemple #1
0
def make_net(phase='train'):
  n = caffe.NetSpec()
  if phase=='train':
      batch_size = train_batch_size
      n.data, n.label = L.ImageData(ntop=2,image_data_param=dict(source=args.traintxt,root_folder=traindir,shuffle=True,batch_size=batch_size,new_height=256,new_width=256),
            transform_param=dict(mirror=True,mean_value=112,crop_size=224))
  elif phase=='test':
      batch_size = test_batch_size
      n.data, n.label = L.ImageData(ntop=2,image_data_param=dict(source=args.testtxt,root_folder=testdir,batch_size=batch_size),
            transform_param=dict(mean_value=112,crop_size=224))
  if phase == 'deploy':
      n.data = L.Input(shape=dict(dim=[1,3,256,256]))

  n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, mult=[10,10,20,0])
  n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64, mult=[10,10,20,0])
  n.pool1 = max_pool(n.relu1_2)

  n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128, mult=[10,1,20,0])
  n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128, mult=[10,1,20,0])
  n.pool2 = max_pool(n.relu2_2)

  n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256, mult=[10,1,20,0])
  n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256, mult=[10,1,20,0])
  n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256, mult=[10,1,20,0])
  n.pool3 = max_pool(n.relu3_3)

  n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512)
  n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512)
  n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512)
  n.pool4 = max_pool(n.relu4_3)
  
  n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512)
  n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512)
  n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512)
  n.pool5 = max_pool(n.relu5_3)

  n.fc6 = L.InnerProduct(n.pool5, num_output=4096, bias_term=True, weight_filler=dict(type='gaussian', std=0.005), bias_filler=dict(type='constant', value=0),
            param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)])
  n.relu6 = L.ReLU(n.fc6, in_place=True)
  n.drop6 = L.Dropout(n.relu6, in_place=True, dropout_ratio=0.5)

  n.fc7 = L.InnerProduct(n.drop6, num_output=4096, bias_term=True, weight_filler=dict(type='gaussian', std=0.005), bias_filler=dict(type='constant', value=0),
            param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)])
  n.relu7 = L.ReLU(n.fc7, in_place=True)
  n.drop7 = L.Dropout(n.relu7, in_place=True, dropout_ratio=0.5)

  if args.nout > 0:
    assert(args.nout >= int(pow(2, treeDepth - 1) - 1))
    nout = args.nout
  else:
    if ntree == 1:
      nout = int(pow(2, treeDepth - 1) - 1)
    else:
      nout = int((pow(2, treeDepth - 1) - 1) * ntree * 2 / 3)
  n.fc8 = L.InnerProduct(n.drop7, num_output=nout, bias_term=True, weight_filler=dict(type='gaussian', std=0.005), bias_filler=dict(type='constant', value=0),
            param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)], name='fc8-101')#name='fc8a')

  if phase=='train':
    all_data_vec_length = int(50)
    #all_data_vec_length = int(nTrain / train_batch_size)
    n.loss = L.NeuralDecisionRegForestWithLoss(n.fc8, n.label, param=[dict(lr_mult=0, decay_mult=0), dict(lr_mult=0, decay_mult=0),dict(lr_mult=0, decay_mult=0)], 
        neural_decision_forest_param=dict(depth=treeDepth, num_trees=ntree, num_classes=1, iter_times_class_label_distr=20, 
            iter_times_in_epoch=50, all_data_vec_length=all_data_vec_length, drop_out=args.drop, init_filename=args.init,record_filename='F_megaage.record'), name='probloss1')
  elif phase=='test':
    n.pred = L.NeuralDecisionRegForest(n.fc8, n.label, neural_decision_forest_param=dict(depth=treeDepth, num_trees=ntree, num_classes=1), name='probloss1')
    n.MAE = L.MAE(n.pred, n.label)
    n.CS5 = L.CS(n.pred, n.label,cs_param = dict(lll = args.cs_l))
  elif phase=='deploy':
    n.pred = L.NeuralDecisionRegForest(n.fc8, neural_decision_forest_param=dict(depth=treeDepth, num_trees=ntree, num_classes=1), name='probloss1')
  return n.to_proto()
Exemple #2
0
def make_net(phase='train'):
    data_source = join('data', args.data + 'DB', 'Ratio' + str(args.ratio))
    n = caffe.NetSpec()
    if phase == 'train':
        batch_size = train_batch_size
    elif phase == 'test':
        batch_size = test_batch_size
    if phase != 'deploy':
        n.data = L.Data(source=join(data_source, phase + '-img'),
                        backend=P.Data.LMDB,
                        batch_size=batch_size,
                        transform_param=dict(mean_value=112, crop_size=224),
                        ntop=1)
        n.label = L.Data(source=join(data_source, phase + '-age'),
                         backend=P.Data.LMDB,
                         batch_size=batch_size,
                         ntop=1)
    else:
        n.data = L.Input(shape=dict(dim=[1, 3, 256, 256]))

    n.conv1_1, n.relu1_1 = conv_relu(n.data, 64)
    n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64)
    n.pool1 = max_pool(n.relu1_2)

    n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128)
    n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128)
    n.pool2 = max_pool(n.relu2_2)

    n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256)
    n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256)
    n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256)
    n.pool3 = max_pool(n.relu3_3)

    n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512)
    n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512)
    n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512)
    n.pool4 = max_pool(n.relu4_3)

    n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512)
    n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512)
    n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512)
    n.pool5 = max_pool(n.relu5_3)

    n.fc6 = L.InnerProduct(
        n.pool5,
        num_output=4096,
        bias_term=True,
        weight_filler=dict(type='gaussian', std=0.005),
        bias_filler=dict(type='constant', value=0),
        param=[dict(lr_mult=1, decay_mult=1),
               dict(lr_mult=2, decay_mult=0)])
    n.relu6 = L.ReLU(n.fc6, in_place=True)
    n.drop6 = L.Dropout(n.relu6, in_place=True, dropout_ratio=0.5)

    n.fc7 = L.InnerProduct(
        n.drop6,
        num_output=4096,
        bias_term=True,
        weight_filler=dict(type='gaussian', std=0.005),
        bias_filler=dict(type='constant', value=0),
        param=[dict(lr_mult=1, decay_mult=1),
               dict(lr_mult=2, decay_mult=0)])
    n.relu7 = L.ReLU(n.fc7, in_place=True)
    n.drop7 = L.Dropout(n.relu7, in_place=True, dropout_ratio=0.5)

    if args.nout > 0:
        assert (args.nout >= int(pow(2, treeDepth - 1) - 1))
        nout = args.nout
    else:
        if ntree == 1:
            nout = int(pow(2, treeDepth - 1) - 1)
        else:
            nout = int((pow(2, treeDepth - 1) - 1) * ntree * 2 / 3)
    n.fc8 = L.InnerProduct(
        n.drop7,
        num_output=nout,
        bias_term=True,
        weight_filler=dict(type='gaussian', std=0.005),
        bias_filler=dict(type='constant', value=0),
        param=[dict(lr_mult=1, decay_mult=1),
               dict(lr_mult=2, decay_mult=0)],
        name='fc8a')

    if phase == 'train':
        all_data_vec_length = int(nTrain / train_batch_size)
        n.loss = L.NeuralDecisionDLForestWithLoss(
            n.fc8,
            n.label,
            param=[
                dict(lr_mult=0, decay_mult=0),
                dict(lr_mult=0, decay_mult=0)
            ],
            neural_decision_forest_param=dict(
                depth=treeDepth,
                num_trees=ntree,
                num_classes=maxAge - minAge + 1,
                iter_times_class_label_distr=20,
                iter_times_in_epoch=100,
                all_data_vec_length=all_data_vec_length,
                drop_out=args.drop),
            name='probloss')
    elif phase == 'test':
        n.pred = L.NeuralDecisionForest(n.fc8,
                                        n.label,
                                        neural_decision_forest_param=dict(
                                            depth=treeDepth,
                                            num_trees=ntree,
                                            num_classes=maxAge - minAge + 1),
                                        name='probloss')
        n.MAE = L.MAE(n.pred, n.label)
    elif phase == 'deploy':
        n.pred = L.NeuralDecisionForest(n.fc8,
                                        neural_decision_forest_param=dict(
                                            depth=treeDepth,
                                            num_trees=ntree,
                                            num_classes=maxAge - minAge + 1),
                                        name='probloss')
    return n.to_proto()
Exemple #3
0
def make_net(phase='train'):
    data_source = join('data', args.data + 'DB', 'Ratio' + str(args.ratio))
    n = caffe.NetSpec()
    if phase == 'train':
        batch_size = train_batch_size
    elif phase == 'test':
        batch_size = test_batch_size
    if phase != 'deploy':
        n.data = L.Data(source=join(data_source, phase + '-img'),
                        backend=P.Data.LMDB,
                        batch_size=batch_size,
                        transform_param=dict(mean_value=112, crop_size=227),
                        ntop=1)
        n.label = L.Data(source=join(data_source, phase + '-age'),
                         backend=P.Data.LMDB,
                         batch_size=batch_size,
                         ntop=1)
    else:
        n.data = L.Input(shape=dict(dim=[1, 3, 256, 256]))
    n.conv1 = L.Convolution(n.data,
                            kernel_size=11,
                            stride=4,
                            num_output=96,
                            weight_filler=dict(type='xavier'),
                            param=[
                                dict(lr_mult=0.1, decay_mult=1),
                                dict(lr_mult=0.2, decay_mult=0)
                            ])
    n.relu1 = L.ReLU(n.conv1, in_place=True)
    n.lrn1 = L.LRN(n.relu1, local_size=5, alpha=0.0001, beta=0.75)
    n.pool1 = L.Pooling(n.lrn1, pool=P.Pooling.MAX, stride=2, kernel_size=3)

    n.conv2 = L.Convolution(n.pool1,
                            kernel_size=5,
                            pad=2,
                            num_output=256,
                            group=2,
                            weight_filler=dict(type='xavier'),
                            param=[
                                dict(lr_mult=0.1, decay_mult=1),
                                dict(lr_mult=0.2, decay_mult=0)
                            ])
    n.relu2 = L.ReLU(n.conv2, in_place=True)
    n.lrn2 = L.LRN(n.relu2, local_size=5, alpha=0.0001, beta=0.75)
    n.pool2 = L.Pooling(n.lrn2, pool=P.Pooling.MAX, stride=2, kernel_size=3)

    n.conv3 = L.Convolution(n.pool2,
                            kernel_size=3,
                            pad=1,
                            num_output=384,
                            weight_filler=dict(type='xavier'),
                            param=[
                                dict(lr_mult=0.1, decay_mult=1),
                                dict(lr_mult=0.2, decay_mult=0)
                            ])
    n.relu3 = L.ReLU(n.conv3, in_place=True)

    n.conv4 = L.Convolution(n.relu3,
                            kernel_size=3,
                            pad=1,
                            num_output=384,
                            group=2,
                            weight_filler=dict(type='xavier'),
                            param=[
                                dict(lr_mult=0.1, decay_mult=1),
                                dict(lr_mult=0.2, decay_mult=0)
                            ])
    n.relu4 = L.ReLU(n.conv4, in_place=True)

    n.conv5 = L.Convolution(n.relu4,
                            kernel_size=3,
                            pad=1,
                            num_output=256,
                            group=2,
                            weight_filler=dict(type='xavier'),
                            param=[
                                dict(lr_mult=0.1, decay_mult=1),
                                dict(lr_mult=0.2, decay_mult=0)
                            ])
    n.relu5 = L.ReLU(n.conv5, in_place=True)
    n.pool5 = L.Pooling(n.relu5, pool=P.Pooling.MAX, stride=2, kernel_size=3)

    n.fc6 = L.InnerProduct(
        n.pool5,
        num_output=4096,
        bias_term=True,
        weight_filler=dict(type='xavier'),
        bias_filler=dict(type='constant', value=0.1),
        param=[dict(lr_mult=1, decay_mult=1),
               dict(lr_mult=2, decay_mult=0)])
    n.relu6 = L.ReLU(n.fc6, in_place=True)
    n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True)

    n.fc7 = L.InnerProduct(
        n.drop6,
        num_output=4096,
        bias_term=True,
        weight_filler=dict(type='xavier'),
        bias_filler=dict(type='constant', value=0.1),
        param=[dict(lr_mult=1, decay_mult=1),
               dict(lr_mult=2, decay_mult=0)])
    n.relu7 = L.ReLU(n.fc7, in_place=True)
    n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True)
    if args.nout > 0:
        assert (args.nout >= int(pow(2, treeDepth - 1) - 1))
        nout = args.nout
    else:
        if ntree == 1:
            nout = int(pow(2, treeDepth - 1) - 1)
        else:
            nout = int((pow(2, treeDepth - 1) - 1) * ntree * 2 / 3)
    n.fc8 = L.InnerProduct(
        n.drop7,
        num_output=nout,
        bias_term=True,
        weight_filler=dict(type='xavier'),
        param=[dict(lr_mult=1, decay_mult=1),
               dict(lr_mult=2, decay_mult=0)],
        name='fc8a')

    if phase == 'train':
        all_data_vec_length = int(nTrain / train_batch_size)
        n.loss = L.NeuralDecisionDLForestWithLoss(
            n.fc8,
            n.label,
            param=[
                dict(lr_mult=0, decay_mult=0),
                dict(lr_mult=0, decay_mult=0)
            ],
            neural_decision_forest_param=dict(
                depth=treeDepth,
                num_trees=ntree,
                num_classes=maxAge - minAge + 1,
                iter_times_class_label_distr=20,
                iter_times_in_epoch=100,
                all_data_vec_length=all_data_vec_length,
                drop_out=args.drop),
            name='probloss')
    elif phase == 'test':
        n.pred = L.NeuralDecisionForest(n.fc8,
                                        n.label,
                                        neural_decision_forest_param=dict(
                                            depth=treeDepth,
                                            num_trees=ntree,
                                            num_classes=maxAge - minAge + 1),
                                        name='probloss')
        n.MAE = L.MAE(n.pred, n.label)
    elif phase == 'deploy':
        n.pred = L.NeuralDecisionForest(n.fc8,
                                        neural_decision_forest_param=dict(
                                            depth=treeDepth,
                                            num_trees=ntree,
                                            num_classes=maxAge - minAge + 1),
                                        name='probloss')
    return n.to_proto()