ubuntu14.04+caffe 图像数据转换成db(leveldb/lmdb)

本文详细介绍了如何使用Caffe框架创建训练所需的txt文件,并解决在此过程中遇到的路径配置及文件内容错误等问题。

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

首先,问题来自caffe学习系列(12):http://www.cnblogs.com/denny402/p/5082341.html


按照该博客中的教程,在caffe目录下执行:

      

       # sudo vi examples/images/create_filelist.sh


vi表示打开或者新建一个文件,最好先看一下linux基本指令vi的用法。
用vi新建。.sh文件后,按“i”进入编辑模式,复制博客中提到的代码:
       # /usr/bin/env sh
       DATA=examples/images
       echo "Create train.txt..."
       rm -rf $DATA/train.txt
       find $DATA -name *cat.jpg | cut -d '/' -f3 | sed "s/$/ 1/">>$DATA/train.txt
       find $DATA -name *bike.jpg | cut -d '/' -f3 | sed "s/$/ 2/">>$DATA/tmp.txt
       cat $DATA/tmp.txt>>$DATA/train.txt
       rm -rf $DATA/tmp.txt
       echo "Done.."

按ESC退出编辑模式,按“:wq!"退出vi并保存。此时,在caffe/examples/images目录下会生成create_filelist.sh文件
运行:cd caffe/examples/images
     sudo sh create_filelist.sh
运行后会出现以下错误:
       

Create train.txt...

create_filelist.sh: 5: create_filelist.sh: cannot create examples/images/train.txt: Directory nonexistent

find: `examples/images': No such file or directory

create_filelist.sh: 6: create_filelist.sh: cannot create examples/images/tmp.txt: Directory nonexistent

find: `examples/images': No such file or directory

create_filelist.sh: 7: create_filelist.sh: cannot create examples/images/train.txt: Directory nonexistent

Done..

此时,需要更改图片路径:

    DATA=examples/images  -->DATA=/home/xxx/caffe/examples/images    注:xxx是自己电脑名称,如tony
重新执行:
     cd caffe/examples/images
     sudo sh create_filelist.sh
此时会在caffe/examples/images目录下会生成train.txt,但是打开会发现内容是错误的:
     xxx 1
     xxx 2
此时需要将:
     find $DATA -name *cat.jpg | cut -d '/' -f3 | sed "s/$/ 1/">>$DATA/train.txt
     find $DATA -name *bike.jpg | cut -d '/' -f3 | sed "s/$/ 2/">>$DATA/tmp.txt
更改为:
     find $DATA -name *cat.jpg | cut -d '/' -f7 | sed "s/$/ 1/">>$DATA/train.txt
     find $DATA -name *bike.jpg | cut -d '/' -f7 | sed "s/$/ 2/">>$DATA/tmp.txt

此时运行.sh,结果应该正确。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值