1. BGR TO RGB

由于训练过程,使用的是RGB,在计算过程中,caffe 调用的是opencv,因此需要将在.protxt中写入代码, 将BGR转换为RGB 

里面使用的是caffe中的Slice 和 Concat模块 

layer  {
name: "convert_slice" 
    type: "Slice"
    bottom: "data_"
    top: "B"
    top: "G"
    top: "R"
    slice_param {
       axis: 1
       slice_point: 1 
       slice_point: 2  
    }
}

layer {
name: "convert_concat" 
       type: "Concat" 
       bottom:"R"
       bottom:"G"
       bottom:"B"
       top:"data"                
}

2. Data layer 

使用的数据集是LMDB类型 

layer {
  name: "cifar" # 层的名字
  type: "Data" # 告诉网络第一层是数据层 
  top: "data"  #一般用bottom表示输入,top表示输出,多个top代表有多个输出
  top: "label"
  include {
    phase: TRAIN #训练网络分为训练阶段和自测试阶段,如果没写include则表示该层即在测试中,又在训练中, 加上TRAIN表示只在训练层使用 
  }
  transform_param {
    mean_file: "examples/cifar10/mean.binaryproto" #用一个配置文件来进行均值的操作 
    transform_param {
    scale: 0.00390625 # 表示进行0-1的归一化操作 
    mirror: 1  # 1表示开启镜像,0表示关闭,也可用ture和false来表示
    # 剪裁一个 227*227的图块,在训练阶段随机剪裁,在测试阶段从中间裁剪
    crop_size: 227
  }
  }
  data_param {
    source: "examples/cifar10/cifar10_train_lmdb" #数据库来源
    batch_size: 64 #每次批处理的个数
    backend: LMDB #选用数据的名称
  }
}

使用的数据集是HDF5数据源

layer {
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  hdf5_data_param {
    source: "examples/hdf5_classification/data/train.txt"
    batch_size: 10
  }
}

直接使用image_path, 这里使用的是file_list.txt 添加文件的路径 

###数据直接来源与图片
#/path/to/images/img3423.jpg 2  
#/path/to/images/img3424.jpg 13  
#/path/to/images/img3425.jpg 8

layer {
  name: "data"
  type: "ImageData" #类型
  top: "data"
  top: "label"
  transform_param {
    mirror: false
    crop_size: 227
    mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
  }
  image_data_param {
    source: "examples/_temp/file_list.txt"
    batch_size: 50
    new_height: 256 #如果设置就对图片进行resize操作
    new_width: 256
  }
}

 

posted on 2020-05-15 17:36  python我的最爱  阅读(298)  评论(0编辑  收藏  举报