Caffe 使用1:准备数据 Caffe DIY-step1: Prepare Data

本文详细介绍了使用Caffe进行图像分类任务前的数据准备步骤,包括调整图像大小、转换为lmdb格式以及计算平均值等关键操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Before using Caffe, we need to prepare data (mainly pictures)to feed the model.

Execute environment:

All the scripts has been put in the folder ~/caffe/caffe/data/myself

The current path is : ~/caffe/caffe/data/myself$


1. Resize(This has been integrated into the step3 in our new version).

We first resize our pictures to 256x256 by using

resizeImage.sh


for name in /path/to/imagenet/val/*.JPEG; do
convert -resize 256x256\! $name $name
done



2. Convert to lmdbFirstly, We can use the script as follows to create the file list.

File Name: creatFilelist.sh

Code:
#!/usr/bin/env sh
# creat the file list

DATA=.

echo "Create train.txt..."

rm -i $DATA/train.txt
find $DATA/cats/ -name '*.jpg' | cut -d '/' -f3 | sed "s/$/ 1/">>$DATA/train.txt
find $DATA/birds/ -name '*.jpg' | cut -d '/' -f3 | sed "s/$/ 2/">>$DATA/tmp.txt
cat $DATA/tmp.txt>>$DATA/train.txt
rm -i $DATA/tmp.txt

echo "Done.."

whereas the folder containing pictures are in current path, the folder 'cats' contains pictures of cats and the folder 'birds' contains pictures of birds.

Secondly, we can use the following script to convert the images to lmdb

File Name: convertImages.sh

Code:
#!/usr/bin/env sh
# conver pictures to the lmdb file

DATA=.

rm -ri $DATA/img_train_lmdb
../../build/tools/convert_imageset --shuffle \
--resize_height=256 --resize_width=256 \
/home/liu/caffe/caffe/data/myself/ $DATA/train.txt  $DATA/img_train_lmdb


3. Calculate the mean value

By calculating the mean value we can get higher speed and accuracy

File Name:make_myself_mean

Code:

#!/usr/bin/env sh
# Compute the mean image from the imagenet training lmdb
# N.B. this is available in data/ilsvrc12

EXAMPLE=.
DATA=.
TOOLS=../../build/tools

$TOOLS/compute_image_mean $EXAMPLE/img_train_lmdb \
  $DATA/img_mean.binaryproto

echo "Done."

reference:

1. Caffe学习系列(12):训练和测试自己的图片 - denny402 - 博客园  http://www.cnblogs.com/denny402/p/5083300.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值