Caffe:Imagenet
2015-08-01 18:09
1036 查看
Imagenet的数据有点大哦,将近140G,现在还处于下载过程中,下载完了之后我会进行测试的,那么就将就一下用一下自己从imagenet随手下的两个数据,其实步骤差不来多少,主要是数据总感觉有种标题党欺骗大家的嫌疑= =。
一、准备数据
嗯由于是自己的数据,没有对应的namelist,于是只好自己写一个程序来进行相应工作,网上搜了一段代码:
void GetAllFiles(string path, vector<string>& files)
{
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
GetAllFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
大家可以适当进行修改,随手百度应该都有别人写好的程序。然后就会得到两个txt文件,里面是图片的名字。然后将数据转换成leveldb格式,修改create_imagenet.sh文件,我的如下:
#!/usr/bin/env sh
# Create the imagenet lmdb inputs
# N.B. set the path to the imagenet train + val data dirs
cd ../../
</pre><pre name="code" class="cpp">EXAMPLE=examples/test
DATA=data/test
TOOLS=bin
TRAIN_DATA_ROOT=../../../../../Dataset/Train/
# 这里的TRAIN_DATA_ROOT是训练数据所在的文件夹,VAL_DATA_ROOT同理
VAL_DATA_ROOT=../../../../../Dataset/Val/
#图片需要调整大小为256x256
# Set RESIZE=true to resize the images to 256x256. Leave as false if images have
# already been resized using another tool.
RESIZE=true
if $RESIZE; then
RESIZE_HEIGHT=256
RESIZE_WIDTH=256
else
RESIZE_HEIGHT=0
RESIZE_WIDTH=0
fi
# 这里下面两个if是判断数据所在文件夹是否还有子文件夹,有的话就会退出
if [ ! -d "$TRAIN_DATA_ROOT" ]; then
echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT"
echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path" \
"where the ImageNet training data is stored."
exit 1
fi
if [ ! -d "$VAL_DATA_ROOT" ]; then
echo "Error: VAL_DATA_ROOT is not a path to a directory: $VAL_DATA_ROOT"
echo "Set the VAL_DATA_ROOT variable in create_imagenet.sh to the path" \
"where the ImageNet validation data is stored."
exit 1
fi
# 下面运行程序,在运行程序前记得确保有convert_imageset.exe这个程序,没有的话请编译一遍。同时train.txt和val.txt两个文件记得放在相应路径
echo "Creating train leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$TRAIN_DATA_ROOT \
$DATA/train.txt \
$EXAMPLE/ilsvrc12_train_leveldb
echo "Creating val leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$VAL_DATA_ROOT \
$DATA/val.txt \
$EXAMPLE/ilsvrc12_val_leveldb
echo "Done."
二、训练
在训练前,先运行make_imagenet_mean.sh计算数据均值,下面是make_imagenet_mean.sh:(总之路径设对了一般这里没有错)
得到imagenet_mean.binaryproto然后按道理就可以运行train_caffenet.sh,但是我运行时出现了这个错误CHECK failed:error == cudaSuccess(11 vs. 0)
这个问题,说实话,遇到的人比较少,而且网上也没怎么说明白是个什么问题,大概跟gpu有关,我后来把batch_size从256改成30了之后发现这个问题自动解决了。稍后会更新这个bug的原因和解决原理挖坑待填哈哈哈
一、准备数据
嗯由于是自己的数据,没有对应的namelist,于是只好自己写一个程序来进行相应工作,网上搜了一段代码:
void GetAllFiles(string path, vector<string>& files)
{
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
GetAllFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
大家可以适当进行修改,随手百度应该都有别人写好的程序。然后就会得到两个txt文件,里面是图片的名字。然后将数据转换成leveldb格式,修改create_imagenet.sh文件,我的如下:
#!/usr/bin/env sh
# Create the imagenet lmdb inputs
# N.B. set the path to the imagenet train + val data dirs
cd ../../
</pre><pre name="code" class="cpp">EXAMPLE=examples/test
DATA=data/test
TOOLS=bin
TRAIN_DATA_ROOT=../../../../../Dataset/Train/
# 这里的TRAIN_DATA_ROOT是训练数据所在的文件夹,VAL_DATA_ROOT同理
VAL_DATA_ROOT=../../../../../Dataset/Val/
#图片需要调整大小为256x256
# Set RESIZE=true to resize the images to 256x256. Leave as false if images have
# already been resized using another tool.
RESIZE=true
if $RESIZE; then
RESIZE_HEIGHT=256
RESIZE_WIDTH=256
else
RESIZE_HEIGHT=0
RESIZE_WIDTH=0
fi
# 这里下面两个if是判断数据所在文件夹是否还有子文件夹,有的话就会退出
if [ ! -d "$TRAIN_DATA_ROOT" ]; then
echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT"
echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path" \
"where the ImageNet training data is stored."
exit 1
fi
if [ ! -d "$VAL_DATA_ROOT" ]; then
echo "Error: VAL_DATA_ROOT is not a path to a directory: $VAL_DATA_ROOT"
echo "Set the VAL_DATA_ROOT variable in create_imagenet.sh to the path" \
"where the ImageNet validation data is stored."
exit 1
fi
# 下面运行程序,在运行程序前记得确保有convert_imageset.exe这个程序,没有的话请编译一遍。同时train.txt和val.txt两个文件记得放在相应路径
echo "Creating train leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$TRAIN_DATA_ROOT \
$DATA/train.txt \
$EXAMPLE/ilsvrc12_train_leveldb
echo "Creating val leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$VAL_DATA_ROOT \
$DATA/val.txt \
$EXAMPLE/ilsvrc12_val_leveldb
echo "Done."
二、训练
在训练前,先运行make_imagenet_mean.sh计算数据均值,下面是make_imagenet_mean.sh:(总之路径设对了一般这里没有错)
cd ../../ EXAMPLE=examples/test DATA=data/test TOOLS=bin echo "Computing mean of imageset..." $TOOLS/compute_image_mean $EXAMPLE/ilsvrc12_train_leveldb \ $DATA/imagenet_mean.binaryproto echo "Done."
得到imagenet_mean.binaryproto然后按道理就可以运行train_caffenet.sh,但是我运行时出现了这个错误CHECK failed:error == cudaSuccess(11 vs. 0)
这个问题,说实话,遇到的人比较少,而且网上也没怎么说明白是个什么问题,大概跟gpu有关,我后来把batch_size从256改成30了之后发现这个问题自动解决了。稍后会更新这个bug的原因和解决原理挖坑待填哈哈哈
相关文章推荐
- 准确率, 召回率,mAP
- ubuntu 14.04上配置无GPU的Caffe(A卡机适用)
- caffe solver.prototxt文件
- 在Ubuntu中使用Python的matplotlib库时图片不能显示问题的解决方法
- 安装Caffe的Python wrapper时出现问题的解决方法
- 如何针对自己的需要修改caffe的网络(Python)
- caffe安装指南(Ubuntu13.04 x86)
- Caffe+Ubuntu 14.04 + Cuda6.5 新手安装记录
- Caffe:cifar10
- caffe RGB转gay存储为Leveldb 格式(CIFAR10)示例
- 从零单排caffe
- cuda7.0+ caffe 小白安装手记
- Caffe调参相关问题整理
- caffe install at centos 总结
- caffe install at centos 依赖软件包安装
- caffe+Ubuntu14.0.4 64bit 环境配置说明(无CUDA,caffe在CPU下运行)
- caffe中安装python
- 谷歌大脑科学家 Caffe缔造者 贾扬清 微信讲座完整版
- caffe下的base_lr和blobs_lrhttp://www.cnblogs.com/jianyingzhou/p/4389504.html
- 如何快糙好猛地在Windows下编译CAFFE并使用其matlab和python接口