- layer {
- name: "data"
- type: "Data"
- top: "data"
- top: "label"
- include {
- phase: TRAIN
- }
- transform_param {
- mirror: true
- crop_size: 600
- mean_file: "examples/images/imagenet_mean.binaryproto"
- }
- data_param {
- source: "examples/images/train_lmdb"
- batch_size: 256
- backend: LMDB
- }
- }
- layer {
- name: "data"
- type: "Data"
- top: "data"
- top: "label"
- include {
- phase: TEST
- }
- transform_param {
- mirror: false
- crop_size: 600
- mean_file: "examples/images/imagenet_mean.binaryproto"
- }
- data_param {
- source: "examples/images/val_lmdb"
- batch_size: 50
- backend: LMDB
- }
- }
从上面的 数据层的定义,看得出用了镜像和crop_size,还定义了 mean_file。
利用crop_size这种方式可以剪裁中心关注点和边角特征,mirror可以产生镜像,弥补小数据集的不足.
这里要重点讲一下crop_size在训练层与测试层的区别:
首先我们需要了解mean_file和crop_size没什么大关系。mean_file是根据训练集图片制作出来的,crop_size是对训练集图像进行裁剪,两个都是对原始的训练集图像进行处理。如果原始训练图像的尺寸大小为800*800,crop_size的图片为600*600,则mean_file与crop_size的图片均为800*800的图像集。
在caffe中,如果定义了crop_size,那么在train时会对大于crop_size的图片进行随机裁剪,而在test时只是截取中间部分(详见/caffe/src/caffe/data_transformer.cpp):
- //We only do random crop when we do training.
- if (phase_ == TRAIN) {
- h_off = Rand(datum_height - crop_size + 1);
- w_off = Rand(datum_width - crop_size + 1);
- } else {
- h_off = (datum_height - crop_size) / 2;
- w_off = (datum_width - crop_size) / 2;
- }
- }
下面是我在网上找到的自己进行图像裁剪的程序:
可对照给出的网址进行详细阅读:http://blog.csdn.NET/u011762313/article/details/48343799
我们可以手动将图片裁剪并导入pycaffe中,这样能够提高识别率(pycaffe利用caffemodel进行分类中:进行分类
这一步改为如下):
-
- pridects = np.zeros((1, CLASS_NUM))
-
-
- img_shape = np.array(img.shape)
-
- crop_dims = (32, 96)
- crop_dims = np.array(crop_dims)
-
-
- w_range = img_shape[1] - crop_dims[1]
-
- for k in range(0, w_range + 1, crop_dims[1] / 4) + range(w_range, 1, -crop_dims[1] / 4):
-
- crop_img = img[:, k:k + crop_dims[1], :]
-
- net.blobs['data'].data[...] = transformer.preprocess('data', crop_img)
-
- out = net.forward()
-
- pridects += out['prob']
-
-
- pridect = pridects.argmax()
- caffe中提供了过采样的方法(oversample),详见/caffe/python/caffe/io.py,裁剪的是图片中央、4个角以及镜像共10张图片。
注:如果图片过大,
需要适当缩小batch_size的值,否则使用GPU时可能超出其缓存大小而报错
- layer {
- name: "data"
- type: "Data"
- top: "data"
- top: "label"
- include {
- phase: TRAIN
- }
- transform_param {
- mirror: true
- crop_size: 600
- mean_file: "examples/images/imagenet_mean.binaryproto"
- }
- data_param {
- source: "examples/images/train_lmdb"
- batch_size: 256
- backend: LMDB
- }
- }
- layer {
- name: "data"
- type: "Data"
- top: "data"
- top: "label"
- include {
- phase: TEST
- }
- transform_param {
- mirror: false
- crop_size: 600
- mean_file: "examples/images/imagenet_mean.binaryproto"
- }
- data_param {
- source: "examples/images/val_lmdb"
- batch_size: 50
- backend: LMDB
- }
- }
从上面的 数据层的定义,看得出用了镜像和crop_size,还定义了 mean_file。
利用crop_size这种方式可以剪裁中心关注点和边角特征,mirror可以产生镜像,弥补小数据集的不足.
这里要重点讲一下crop_size在训练层与测试层的区别:
首先我们需要了解mean_file和crop_size没什么大关系。mean_file是根据训练集图片制作出来的,crop_size是对训练集图像进行裁剪,两个都是对原始的训练集图像进行处理。如果原始训练图像的尺寸大小为800*800,crop_size的图片为600*600,则mean_file与crop_size的图片均为800*800的图像集。
在caffe中,如果定义了crop_size,那么在train时会对大于crop_size的图片进行随机裁剪,而在test时只是截取中间部分(详见/caffe/src/caffe/data_transformer.cpp):
- //We only do random crop when we do training.
- if (phase_ == TRAIN) {
- h_off = Rand(datum_height - crop_size + 1);
- w_off = Rand(datum_width - crop_size + 1);
- } else {
- h_off = (datum_height - crop_size) / 2;
- w_off = (datum_width - crop_size) / 2;
- }
- }
下面是我在网上找到的自己进行图像裁剪的程序:
可对照给出的网址进行详细阅读:http://blog.csdn.NET/u011762313/article/details/48343799
我们可以手动将图片裁剪并导入pycaffe中,这样能够提高识别率(pycaffe利用caffemodel进行分类中:进行分类
这一步改为如下):
-
- pridects = np.zeros((1, CLASS_NUM))
-
-
- img_shape = np.array(img.shape)
-
- crop_dims = (32, 96)
- crop_dims = np.array(crop_dims)
-
-
- w_range = img_shape[1] - crop_dims[1]
-
- for k in range(0, w_range + 1, crop_dims[1] / 4) + range(w_range, 1, -crop_dims[1] / 4):
-
- crop_img = img[:, k:k + crop_dims[1], :]
-
- net.blobs['data'].data[...] = transformer.preprocess('data', crop_img)
-
- out = net.forward()
-
- pridects += out['prob']
-
-
- pridect = pridects.argmax()
- caffe中提供了过采样的方法(oversample),详见/caffe/python/caffe/io.py,裁剪的是图片中央、4个角以及镜像共10张图片。
注:如果图片过大,
需要适当缩小batch_size的值,否则使用GPU时可能超出其缓存大小而报错