验证码识别之模型训练

该博客介绍了如何使用Caffe进行验证码识别的模型训练,包括数据集准备、转化为lmdb格式、计算均值文件、编写配置文件以及训练与测试的步骤。作者提供了数据集链接和相关代码示例。
摘要由CSDN通过智能技术生成

参考:(http://www.cnblogs.com/louyihang-loves-baiyan/p/5038758.html)
整个思路大致如下:
这里写图片描述
Step 1: 数据集准备:http://pan.baidu.com/s/1gfBrmGb 密码:ql14
Step 2: 转化为lmdb数据集
Caffe的数据格式采用leveldb或者lmdb格式的,第一步要做的就是数据的格式转换了;首先将图片分成trainpicture和testpicture,然后作者用matlab生成train.txt和test.txt
准备两个txt文件,放成list的形式,图像路径之后一个空格之后跟着类别的ID,如下,这里记住ID必须从0开始,要连续,否则会出错,loss不下降,按照要求写就OK。这个是训练的图像label,测试的也同理
这里写图片描述
test.txt 亦如

生成train.txt 和 test.txt代码如下:

clc
clear all
%% 读取文件夹里的图片名称,且将图片名保存到txt
file_path = '../SinImage2/';
img_path_list = dir(strcat(file_path,'*.bmp'));
mkdir('../trainpicture1'); 
mkdir('../testpicture1'); 

img_num = length(img_path_list);
img_path_list = img_path_list(randperm(img_num )) ;
img_path_train = img_path_list(1:12000) ;
img_path_test = img_path_list(12001:img_num) ;
img_num = length(img_path_train) ;

fp = fopen('../train.txt','wt');
if img_num > 0 %有满足条件的图像
        for j = 1:img_num %逐一读取图像
            image_name = img_path_train(j).name;% 图像名

            copyfile([file_path image_name] ,'../trainpicture1'); 

            outdata = abs(image_name(8))-48;
            if (abs(image_name(8))>60)
                outdata = abs(image_name(8))-55;
            end

            fprintf(fp,'%s %d\n',image_name,outdata);
            end
end
fclose(fp)


% test data prepare 
img_num = length(img_path_test);
fp = fopen('../test.txt','wt')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值