name: "CaffeNET"
layers {
  name: "data"
  type: IMAGE_DATA_PAIR
  top: "data"
  top: "index1_si"
  top: "index2_si"
  top: "pairlabel_si"
  image_data_pair_param {
    source: "../dataset" # it will not be used in the test process
    img_files: "../filelist/trainlist.txt" # it will not be used in the test process
    cropsize:1
    cropsize_h:160
    cropsize_w:60
    class_per_iter:60
    triplet_per_class:80
    batch_iter:1
    img_counts_per_class_per_iter:2
    mirror: false
    scale: 1
  }
  include: { phase: TRAIN }
}


layers {
  name: "data1"
  type: DATA
  top: "mdata1"
  top: "label1"
  data_param {
    source: "../testlmdb/test_detected_probe_180x80_lmdb"
    backend: LMDB
    batch_size: 1
  }
  transform_param {
    mirror: false
  }
  include: { phase: TEST }
}

layers {
  name: "data2"
  type: DATA
  top: "mdata2"
  top: "label2"
  data_param {
    source: "../testlmdb/test_detected_gallery_180x80_lmdb"
    backend: LMDB
    batch_size: 488 # gallery number
  }
  transform_param {
    mirror: false
  }
  include: { phase: TEST }
}

layers {
  name: "transform1"
  type: IMAGE_TEST_TRANSFORM
  bottom: "mdata1"
  top: "data1"
  image_data_pair_param {
    cropsize:1
    cropsize_h:160
    cropsize_w:60
    scale: 1
  }
  include: { phase: TEST }
}



layers {
  name: "transform2"
  type: IMAGE_TEST_TRANSFORM
  bottom: "mdata2"
  top: "data2"
  image_data_pair_param {
    cropsize:1
    cropsize_h:160
    cropsize_w:60
    scale: 1
  }
  include: { phase: TEST }
}

layers {
  name: "randci"
  type: RAND_SELECT
  bottom: "index1_si"
  bottom: "index2_si"
  bottom: "pairlabel_si"
  top: "index1_ci"
  top: "index2_ci"
  top: "pairlabel_ci"
  rand_select_param {
    batchsize: 100
  }
  include: { phase: TRAIN }
}

layers {
  name: "pairdata_data"
  type: PAIR_DATA
  bottom: "index1_ci"
  bottom: "index2_ci"
  bottom: "data"
  top: "data1"
  top: "data2"
  include: { phase: TRAIN }
}







layers {
  name: "conv11"
  type: CONVOLUTION
  bottom: "data"
  top: "conv11"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 0
  weight_decay: 0
  convolution_param {
    num_output: 32
    kernel_size: 5
    pad: 0
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  include: { phase: TRAIN }
}

layers {
  name: "conv11"
  type: CONVOLUTION
  bottom: "data1"
  bottom: "data2"
  top: "conv11_1"
  top: "conv11_2"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 0
  weight_decay: 0
  convolution_param {
    num_output: 32
    kernel_size: 5
    pad: 0
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  include: { phase: TEST }
}





layers {
  name: "relu11"
  type: RELU
  bottom: "conv11"
  top: "conv11"
  include: { phase: TRAIN }
}

layers {
  name: "relu11_1"
  type: RELU
  bottom: "conv11_1"
  top: "conv11_1"
  include: { phase: TEST }
}

layers {
  name: "relu11_2"
  type: RELU
  bottom: "conv11_2"
  top: "conv11_2"
  include: { phase: TEST }
}










layers {
  name: "pool1"
  type: POOLING
  bottom: "conv11"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 3
  }
  include: { phase: TRAIN }
}

layers {
  name: "pool1_1"
  type: POOLING
  bottom: "conv11_1"
  top: "pool1_1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 3
  }
  include: { phase: TEST }
}

layers {
  name: "pool1_2"
  type: POOLING
  bottom: "conv11_2"
  top: "pool1_2"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 3
  }
  include: { phase: TEST }
}



layers {
  name: "pairdata_pool1"
  type: PAIR_DATA
  bottom: "index1_ci"
  bottom: "index2_ci"
  bottom: "pool1"
  top: "pool1_1"
  top: "pool1_2"
  include: { phase: TRAIN }
}


layers {
  name: "conv21"
  type: CONVOLUTION
  bottom: "pool1"
  top: "conv21"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 0
  weight_decay: 0
  convolution_param {
    num_output: 64
    kernel_size: 3
    pad: 0
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  include: { phase: TRAIN }
}

layers {
  name: "relu21"
  type: RELU
  bottom: "conv21"
  top: "conv21"
  include: { phase: TRAIN }
}

layers {
  name: "conv21"
  type: CONVOLUTION
  bottom: "pool1_1"
  bottom: "pool1_2"
  top: "conv21_1"
  top: "conv21_2"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 0
  weight_decay: 0
  convolution_param {
    num_output: 64
    kernel_size: 3
    pad: 0
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  include: { phase: TEST }
}

layers {
  name: "relu21_1"
  type: RELU
  bottom: "conv21_1"
  top: "conv21_1"
  include: { phase: TEST }
}

layers {
  name: "relu21_2"
  type: RELU
  bottom: "conv21_2"
  top: "conv21_2"
  include: { phase: TEST }
}









layers {
  name: "pool2"
  type: POOLING
  bottom: "conv21"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
  include: { phase: TRAIN }
}

layers {
  name: "pool2_1"
  type: POOLING
  bottom: "conv21_1"
  top: "pool2_1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
  include: { phase: TEST }
}

layers {
  name: "pool2_2"
  type: POOLING
  bottom: "conv21_2"
  top: "pool2_2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
  include: { phase: TEST }
}




layers {
  name: "pairdata_pool2"
  type: PAIR_DATA
  bottom: "index1_ci"
  bottom: "index2_ci"
  bottom: "pool2"
  top: "pool2_1"
  top: "pool2_2"
  include: { phase: TRAIN }
}



layers {
  name: "concat22"
  type: CONCAT_COMB
  bottom: "pool2_1"
  bottom: "pool2_2"
  top: "concat22"
}

layers {
  name: "conv31"
  type: CONVOLUTION
  bottom: "pool2"
  top: "conv31"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 0
  weight_decay: 0
  convolution_param {
    num_output: 32
    kernel_size: 3
    pad: 0
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  include: { phase: TRAIN }
}

layers {
  name: "relu31"
  type: RELU
  bottom: "conv31"
  top: "conv31"
  include: { phase: TRAIN }
}

layers {
  name: "conv31"
  type: CONVOLUTION
  bottom: "pool2_1"
  bottom: "pool2_2"
  top: "conv31_1"
  top: "conv31_2"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 0
  weight_decay: 0
  convolution_param {
    num_output: 32
    kernel_size: 3
    pad: 0
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  include: { phase: TEST }
}

layers {
  name: "relu31_1"
  type: RELU
  bottom: "conv31_1"
  top: "conv31_1"
  include: { phase: TEST }
}

layers {
  name: "relu31_2"
  type: RELU
  bottom: "conv31_2"
  top: "conv31_2"
  include: { phase: TEST }
}





layers {
  name: "conv31b"
  type: CONVOLUTION
  bottom: "concat22"
  top: "conv31b"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 0
  weight_decay: 0
  convolution_param {
    num_output: 32
    kernel_size: 3
    pad: 0
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}


layers {
  name: "relu31b"
  type: RELU
  bottom: "conv31b"
  top: "conv31b"
}

layers {
  name: "pool3"
  type: POOLING
  bottom: "conv31"
  top: "pool3"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
  include: { phase: TRAIN }
}

layers {
  name: "pool3_1"
  type: POOLING
  bottom: "conv31_1"
  top: "pool3_1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
  include: { phase: TEST }
}

layers {
  name: "pool3_2"
  type: POOLING
  bottom: "conv31_2"
  top: "pool3_2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
  include: { phase: TEST }
}





layers {
  name: "pairdata_pool3"
  type: PAIR_DATA
  bottom: "index1_ci"
  bottom: "index2_ci"
  bottom: "pool3"
  top: "pool3_1"
  top: "pool3_2"
  include: { phase: TRAIN }
}

layers {
  name: "pool3b"
  type: POOLING
  bottom: "conv31b"
  top: "pool3b"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}



layers {
  name: "drop1"
  type: DROPOUT
  bottom: "pool3"
  top: "drop1"
  dropout_param {
    dropout_ratio: 0.4
  }
  include: { phase: TRAIN }
}

layers {
  name: "drop1_1"
  type: DROPOUT
  bottom: "pool3_1"
  top: "drop1_1"
  dropout_param {
    dropout_ratio: 0.4
  }
  include: { phase: TEST }
}

layers {
  name: "drop1_2"
  type: DROPOUT
  bottom: "pool3_2"
  top: "drop1_2"
  dropout_param {
    dropout_ratio: 0.4
  }
  include: { phase: TEST }
}

layers {
  name: "dropb"
  type: DROPOUT
  bottom: "pool3b"
  top: "drop1_b"
  dropout_param {
    dropout_ratio: 0.4
  }
}

layers {
  name: "fc1"
  type: INNER_PRODUCT
  bottom: "drop1"
  top: "fc1"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 10
  weight_decay: 0
  inner_product_param {
    num_output: 1000
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
  include: { phase: TRAIN }
}



layers {
  name: "fc1"
  type: INNER_PRODUCT
  bottom: "drop1_1"
  bottom: "drop1_2"
  top: "fc1_1"
  top: "fc1_2"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 10
  weight_decay: 0
  inner_product_param {
    num_output: 1000
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
  include: { phase: TEST }
}

layers {
  name: "relu3"
  type: RELU
  bottom: "fc1"
  top: "fc1"
  include: { phase: TRAIN }
}

layers {
  name: "relu3_1"
  type: RELU
  bottom: "fc1_1"
  top: "fc1_1"
  include: { phase: TEST }
}

layers {
  name: "relu3_2"
  type: RELU
  bottom: "fc1_2"
  top: "fc1_2"
  include: { phase: TEST }
}



layers {
  name: "fc1_b"
  type: INNER_PRODUCT
  bottom: "drop1_b"
  top: "fc1_b"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 10
  weight_decay: 0
  inner_product_param {
    num_output: 1000
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
}

layers {
  name: "relu3_b"
  type: RELU
  bottom: "fc1_b"
  top: "fc1_b"
}


layers {
  name: "fc2"
  type: INNER_PRODUCT
  bottom: "fc1"
  top: "fc2"
  blobs_lr: 1
  weight_decay: 10
  inner_product_param {
    num_output: 500
    bias_term: false
    weight_filler {
      type: "xavier"
    }
  }
  include: { phase: TRAIN }
}

layers {
  name: "fc2"
  type: INNER_PRODUCT
  bottom: "fc1_1"
  bottom: "fc1_2"
  top: "fc2_1"
  top: "fc2_2"
  blobs_lr: 1
  weight_decay: 10
  inner_product_param {
    num_output: 500
    bias_term: false
    weight_filler {
      type: "xavier"
    }
  }
  include: { phase: TEST }
}





layers {
  name: "fc3b"
  type: INNER_PRODUCT
  bottom: "fc1_b"
  top: "fc3b"
  blobs_lr: 1
  blobs_lr: 2
  weight_decay: 10
  weight_decay: 0
  inner_product_param {
    num_output: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 1
    }
  }
}

layers {
  name: "pairlabel_si"
  type: PAIR_LABEL
  bottom: "label1"
  bottom: "label2"
  top: "pairlabel_si"
  include: { phase: TEST }
}

layers {
  name: "pairlabel_ci"
  type: PAIR_LABEL
  bottom: "label1"
  bottom: "label2"
  top: "pairlabel_ci"
  include: { phase: TEST }
}


layers {
  name: "flat_fc"
  type: FLATTEN
  bottom: "fc2"
  top: "flat_fc"
  include: { phase: TRAIN }
}

layers {
  name: "pairdata_flatfc"
  type: PAIR_DATA
  bottom: "index1_si"
  bottom: "index2_si"
  bottom: "flat_fc"
  top: "flat_fc1"
  top: "flat_fc2"
  include: { phase: TRAIN }
}

layers {
  name: "flat_fc1"
  type: FLATTEN
  bottom: "fc2_1"
  top: "flat_fc1"
  include: { phase: TEST }
}

layers {
  name: "flat_fc2"
  type: FLATTEN
  bottom: "fc2_2"
  top: "flat_fc2"
  include: { phase: TEST }
}




#layers {
#  name: "cost3"
#  type: CONTRASTIVE_LOSS
#  bottom: "flat_fc1"
#  bottom: "flat_fc2"
#  bottom: "pairlabel"
#  top: "loss3"
#  loss_weight: 1
#  contrastive_loss_param {
#    margin: 10
#  }
#}


#layers {
#  name: "cost4"
#  type: SOFTMAX_LOSS
#  bottom: "fc3b"
#  bottom: "pairlabel"
#  top: "loss4"
#  loss_weight: 1
#}


layers {
  name: "cost3"
  type: DOUBLET_LOSS
  bottom: "flat_fc1"
  bottom: "flat_fc2"
  bottom: "pairlabel_si"
  top: "loss3"
  blobs_lr: 0
  recording: 0
  loss_weight: 1
  doublet_loss_param {
    margin: 1
    bias_term: true
    bias_filler {
      type: "constant"
      value: 5
    }
  }
}



layers {
  name: "lossSI"
  type: KNN_ACCURACY
  bottom: "flat_fc1"
  bottom: "flat_fc2"
  bottom: "label1"
  bottom: "label2"
  top: "accuracy"
  recording: 1
  include: { phase: TEST }
}

layers {
  name: "cost4"
  type: LINEAR_CONTRASTIVE_LOSS
  bottom: "fc3b"
  bottom: "pairlabel_ci"
  top: "loss4"
  loss_weight: 1
  recording: 1
  contrastive_loss_param {
    margin: 1
  }
}

