Skip to content

becauseofAI/caffe-plus-plus

Repository files navigation

Caffe++☕️

Assemble new features to enhance Caffe.

The Caffe revision: 99bd99795dcdf0b1d3086a8d67ab1782a8a08383(commit SHA)

New Layers

Common: you can use directly
Special: need special net structure
Experienced: need to adjust parameters or try some times

Common

layer {
  name: "center_loss"
  type: "CenterLoss"
  bottom: "fc5"
  bottom: "label"
  top: "center_loss"
  param {
    lr_mult: 1
    decay_mult: 2 
  }
  center_loss_param {
    num_output: 10572
    center_filler {
      type: "xavier"
    }
  }
  loss_weight: 0.008
}
layer {
  name: "upsample5"
  type: "Upsample"
  bottom: "pool5"
  top: "pool5_D"
  bottom: "pool5_mask"
  upsample_param {
    scale: 2
    upsample_w: 30
    upsample_h: 23
  }
}
layer {
  name: "branch1_1_conv1"
  type: "ConvolutionDepthwise"
  bottom: "pool1"
  top: "branch1_1_conv1"
  convolution_param {
    num_output: 24
    kernel_size: 3
    stride: 2
    pad: 1
    bias_term: false
    weight_filler {
      type: "msra"
    }
  }
}
layer {
  name: "shuffle1"
  type: "ShuffleChannel"
  bottom: "concat1"
  top: "shuffle1"
  shuffle_channel_param {
    group: 2
  }
}
layer {
  name: "loss"
  type: "WeightedSoftmaxWithLoss"
  bottom: "fc_end"
  bottom: "label"
  top: "loss"
  softmax_param {
    pos_cid: 1
    pos_mult: 2.0
  }
}

Special

layer {
  name: "conv2_1"
  type: "Axpy"
  bottom: "conv2_1_1x1_up"
  bottom: "conv2_1_1x1_increase"
  bottom: "conv2_1_1x1_proj"
  top: "conv2_1"
}

Experienced

layer {
  name: "fc6"
  type: "MarginInnerProduct"
  bottom: "fc5"
  bottom: "label"
  top: "fc6"
  top: "lambda"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  margin_inner_product_param {
    num_output: 10572
    type: SINGLE
    weight_filler {
      type: "xavier"
    }
    base: 0
    gamma: 0.12
    power: 1
    lambda_min: 3
    iteration: 0
    triplet: true
    semihard: true
  }
}
layer {
  name: "fc6"
  type: "MarginInnerProduct"
  bottom: "fc5"
  bottom: "label"
  top: "fc6"
  top: "lambda"
  param {
    name: "fc6_w"
    lr_mult: 1
    decay_mult: 1
  }
  margin_inner_product_param {
    num_output: 10572
    type: QUADRUPLE
    weight_filler {
      type: "xavier"
    }
    base: 1000
    gamma: 0.12
    power: 1
    lambda_min: 5
    iteration: 2000
  }
}
layer {
  name: "inter_class_dist_output"
  type: "InterClass"
  bottom: "fc5"
  bottom: "label"
  top: "maximize_inter_class_dist"
  param {
    name: "fc6_w"
    lr_mult: 1
    decay_mult: 1
  }
  inter_class_param {
    num_output: 10572
    type: AMONG
    iteration: 16000
    alpha_start_iter: 16001
    alpha_start_value: 10 #among
  }
}
layer {
  name: "softmax_loss"
  type: "SoftmaxWithLoss"
  bottom: "fc6"
  bottom: "label"
  top: "softmax_loss"
}

Examples

New layer examples are here.

New Functions

Multi-Label for Multi-Task

  • ImageData

train.txt

image/00001.jpg 0 5 1
image/00002.jpg 0 9 -1
image/00003.jpg 1 9 2
image/00004.jpg 1 -1 0
image/00005.jpg 1 0 2

train.prototxt

layer {
  name: "data"
  type: "ImageData"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
    mirror: true
  }
  image_data_param {
    source: "/your/path/train.txt"  
    root_folder: "/your/image/data/path"  
    new_height: 224 
    new_width: 224  
    batch_size: 64 
    is_color: true  
    shuffle: true
    label_dim: 3
   }
}

layer {
  name: "slice"
  type: "Slice"
  bottom: "label"
  top: "label_1"
  top: "label_2"
  top: "label_3"
  slice_param {
    axis: 1
    slice_point:1
    slice_point:2
  }
}

layer {
  name: "fc7_1"
  type: "InnerProduct"
  bottom: "conv7_1"
  top: "fc7_1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 5
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
} 

layer {
  name: "fc7_2"
  type: "InnerProduct"
  bottom: "conv7_2"
  top: "fc7_2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 10
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
} 

layer {
  name: "fc7_3"
  type: "InnerProduct"
  bottom: "conv7_3"
  top: "fc7_3"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
} 

layer {
  name: "loss1"
  type: "SoftmaxWithLoss"
  bottom: "fc7_1"
  bottom: "label_1"
  loss_param {
    ignore_label: -1
  }
}

layer {
  name: "loss2"
  type: "SoftmaxWithLoss"
  bottom: "fc7_2"
  bottom: "label_2"
  loss_param {
    ignore_label: -1
  }
}

layer {
  name: "loss3"
  type: "SoftmaxWithLoss"
  bottom: "fc7_3"
  bottom: "label_3"
  loss_param {
    ignore_label: -1
  }
}

New Performance

The implementation for global average pooling on GPU supported by cuDNN and BVLC/caffe is less efficient. In this regard, the author re-implement the operation which achieves significant acceleration.

layer {
  name: "conv2_1_global_pool"
  type: "Pooling"
  bottom: "conv2_1_1x1_increase"
  top: "conv2_1_global_pool"
  pooling_param {
    pool: AVE
    engine: CAFFE
    global_pooling: true
  }
}

Caffe

Build Status License

Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by Berkeley AI Research (BAIR)/The Berkeley Vision and Learning Center (BVLC) and community contributors.

Check out the project site for all the details like

and step-by-step examples.

Custom distributions

Community

Join the chat at https://gitter.im/BVLC/caffe

Please join the caffe-users group or gitter chat to ask questions and talk about methods and models. Framework development discussions and thorough bug reports are collected on Issues.

Happy brewing!

License and Citation

Caffe is released under the BSD 2-Clause license. The BAIR/BVLC reference models are released for unrestricted use.

Please cite Caffe in your publications if it helps your research:

@article{jia2014caffe,
  Author = {Jia, Yangqing and Shelhamer, Evan and Donahue, Jeff and Karayev, Sergey and Long, Jonathan and Girshick, Ross and Guadarrama, Sergio and Darrell, Trevor},
  Journal = {arXiv preprint arXiv:1408.5093},
  Title = {Caffe: Convolutional Architecture for Fast Feature Embedding},
  Year = {2014}
}