clc; clear all; close all;
warning off all;
% 获取字符集
fd = fullfile(pwd, 'images', 'dbx');
imds = imageDatastore(fd, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
classes = categories(imds.Labels);
[imdsTrain,imdsValidation] = splitEachLabel(imds,rateTrainFiles,'randomize');
% 输入输出设置
image_size = [117 117 1];
class_number = length(classes);
% 数据维数对应
inputSize = layers(1).InputSize;
imdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain,'ColorPreprocessing','rgb2gray');
augimdsValidation = augmentedImageDatastore(inputSize(1:2),imdsValidation,'ColorPreprocessing','rgb2gray');
% 设置训练参数
MaxEpochs = 10;
InitialLearnRate = 0.001;
MiniBatchSize = 50;
% 设置训练环境
ExecutionEnvironment = 'auto';
options_train = trainingOptions('sgdm',...
'MaxEpochs',MaxEpochs,...
'Verbose',true,'MiniBatchSize', MiniBatchSize,...
'Plots','training-progress',...
'ValidationData',augimdsValidation , ...
'ValidationFrequency',10, ...
'ExecutionEnvironment', ExecutionEnvironment);
net_file = 'cnn_net.mat';
if exist(net_file, 'file')
load(net_file);
else
% 训练保存
net = trainNetwork(imdsTrain, layers, options_train);
% 存储网络
save(net_file, 'net');
end
% 测试
while 1
filePath = OpenImageFile();
if isequal(filePath, 0)
break;
end
im = imread(filePath);
x = im;
% 维度对应
inputSize = layers(1).InputSize;
if ~isequal(size(x), inputSize(1:2))
x = imresize(x, inputSize(1:2), 'bilinear');
end
xw = zeros(inputSize(1),inputSize(2), 1, 1);
xw(:,:,1,1) = x(:,:,1);
t1 = cputime;
% 评测
yw = classify(net,xw);
t2 = cputime;
res = sprintf('\s\n识别结果为%s', t2-t1, char(yw));
figure(1); clf; imshow(im); title(res, 'FontSize', 16);
pause(1);
end
%% 欢迎沟通交流Q:3752243968
%% 欢迎沟通交流Q:3752243968
%% 欢迎沟通交流Q:3752243968
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
matlab 基于卷积神经网络手写数字识别.zip代码33 (516个子文件)
0_453.bmp 2KB
0_472.bmp 2KB
0_143.bmp 2KB
0_427.bmp 2KB
0_397.bmp 2KB
0_105.bmp 2KB
0_404.bmp 2KB
0_72.bmp 2KB
0_93.bmp 2KB
8.bmp 2KB
6.bmp 2KB
9.bmp 2KB
3.bmp 2KB
0.bmp 2KB
5.bmp 2KB
1.bmp 2KB
2.bmp 2KB
0_409.bmp 2KB
0_98.bmp 2KB
0_96.bmp 2KB
0_436.bmp 2KB
0_131.bmp 2KB
0_196.bmp 2KB
0_410.bmp 2KB
0_233.bmp 2KB
0_117.bmp 2KB
0_435.bmp 2KB
0_394.bmp 2KB
0_161.bmp 2KB
0_244.bmp 2KB
0_158.bmp 2KB
0_298.bmp 2KB
0_27.bmp 2KB
0_445.bmp 2KB
0_330.bmp 2KB
0_417.bmp 2KB
0_110.bmp 2KB
0_164.bmp 2KB
0_320.bmp 2KB
0_471.bmp 2KB
0_38.bmp 2KB
0_42.bmp 2KB
0_133.bmp 2KB
0_50.bmp 2KB
0_405.bmp 2KB
0_419.bmp 2KB
0_300.bmp 2KB
0_308.bmp 2KB
0_102.bmp 2KB
0_111.bmp 2KB
0_197.bmp 2KB
0_446.bmp 2KB
0_448.bmp 2KB
0_146.bmp 2KB
0_173.bmp 2KB
0_114.bmp 2KB
0_52.bmp 2KB
0_17.bmp 2KB
0_31.bmp 2KB
0_463.bmp 2KB
0_264.bmp 2KB
0_184.bmp 2KB
0_387.bmp 2KB
0_22.bmp 2KB
0_468.bmp 2KB
0_2.bmp 2KB
0_166.bmp 2KB
0_35.bmp 2KB
0_186.bmp 2KB
0_367.bmp 2KB
0_488.bmp 2KB
0_169.bmp 2KB
0_215.bmp 2KB
0_151.bmp 2KB
0_369.bmp 2KB
0_461.bmp 2KB
0_358.bmp 2KB
0_354.bmp 2KB
0_492.bmp 2KB
0_314.bmp 2KB
0_84.bmp 2KB
0_332.bmp 2KB
0_307.bmp 2KB
0_286.bmp 2KB
0_478.bmp 2KB
0_426.bmp 2KB
0_23.bmp 2KB
0_248.bmp 2KB
0_41.bmp 2KB
0_206.bmp 2KB
0_433.bmp 2KB
0_311.bmp 2KB
0_267.bmp 2KB
0_309.bmp 2KB
0_312.bmp 2KB
0_139.bmp 2KB
0_204.bmp 2KB
0_329.bmp 2KB
0_412.bmp 2KB
0_107.bmp 2KB
共 516 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Matlab程序设计
- 粉丝: 15
- 资源: 105
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功