版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
参考文献刘辰雨.基于卷积神经网络的手写数字识别研究与设计[D].成都理工大学,2018.陈鸿宇.基于KNN算法手写数字识别技术的研究与实现[J].信息通信,2020(12):28-32.杨栩.基于卷积神经网络的手写数字图像识别方法[J].绵阳师范学院学报,2020,39(02):35-39.DOI:10.16276/51-1670/g.2020.02.008.汪愿.基于神经网络的手写数字图像识别研究设计[J].电工材料,2021(06):46-48.DOI:10.16786/ki.1671-8887.eem.2021.06.012.HongmeiWang,PengzhongLiu.Imagerecognitionbasedonimprovedconvolutionaldeepbeliefnetworkmodel[J].MultimediaToolsandApplications,2020,80(2):SavitaAhlawat,AmitChoudhary,AnandNayyar,SaurabhSingh,ByungunYoon.ImprovedHandwrittenDigitRecognitionUsingConvolutionalNeuralNetworks(CNN)[J].Sensors,2020,20(12):AliSaqib,LiJianqiang,PeiYan,AslamMuhammadSaqlain,ShaukatZeeshan,AzeemMuhammad.AnEffectiveandImprovedCNN-ELMClassifierforHandwrittenDigitsRecognitionandClassification[J].Symmetry,2020,12(10):翟高粤.基于卷积神经网络的手写数字识别应用[J].甘肃科技纵横,2021,50(01):1-3.安丽娜,蒋锐鹏.基于卷积神经网络的手写数字识别研究[J].无线互联科技,2019,16(20):31-32.余圣新.基于卷积神经网络的手写体实验数字识别[D].贵州大学,2020.DOI:10.27047/ki.ggudu.2020.000967.李晶晶.基于神经网络的图像识别方法研究[D].华北电力大学,2018.附录:相关代码代码SEQ代码\*ARABIC1加载数据类exportclassMnistData{
constructor(){
this.shuffledTrainIndex=0;
this.shuffledTestIndex=0;
}
//*对Minst数据的异步加载
asyncload(){
constimg=newImage();
constcanvas=document.createElement('canvas');
constctx=canvas.getContext('2d');
constimgRequest=newPromise((resolve,reject)=>{
img.crossOrigin='';
img.onload=()=>{
img.width=img.naturalWidth;
img.height=img.naturalHeight;
constdatasetBytesBuffer=
newArrayBuffer(NUM_DATASET_ELEMENTS*IMAGE_SIZE*4);
constchunkSize=5000;
canvas.width=img.width;
canvas.height=chunkSize;
for(leti=0;i<NUM_DATASET_ELEMENTS/chunkSize;i++){
constdatasetBytesView=newFloat32Array(
datasetBytesBuffer,i*IMAGE_SIZE*chunkSize*4,
IMAGE_SIZE*chunkSize);
ctx.drawImage(
img,0,i*chunkSize,img.width,chunkSize,0,0,img.width,
chunkSize);
constimageData=ctx.getImageData(0,0,canvas.width,canvas.height);
for(letj=0;j<imageData.data.length/4;j++){
datasetBytesView[j]=imageData.data[j*4]/255;
}
}
this.datasetImages=newFloat32Array(datasetBytesBuffer);
resolve();
};
img.src=MNIST_IMAGES_SPRITE_PATH;
});
constlabelsRequest=fetch(MNIST_LABELS_PATH)
const[imgResponse,labelsResponse]=
awaitPromise.all([imgRequest,labelsRequest]);
this.datasetLabels=newUint8Array(awaitlabelsResponse.arrayBuffer());
//当我们选择一个随机数据集元素进行训练/验证时,在训练/测试集中创建随机索引。
this.trainIndices=tf.util.createShuffledIndices(NUM_TRAIN_ELEMENTS);
this.testIndices=tf.util.createShuffledIndices(NUM_TEST_ELEMENTS);
//将图像和标签切片为训练集和测试集。
this.trainImages=
this.datasetImages.slice(0,IMAGE_SIZE*NUM_TRAIN_ELEMENTS);
this.testImages=this.datasetImages.slice(IMAGE_SIZE*NUM_TRAIN_ELEMENTS);
this.trainLabels=
this.datasetLabels.slice(0,NUM_CLASSES*NUM_TRAIN_ELEMENTS);
this.testLabels=
this.datasetLabels.slice(NUM_CLASSES*NUM_TRAIN_ELEMENTS);
}
//*从训练集返回随机批次的图片及其标签。
nextTrainBatch(batchSize){
returnthis.nextBatch(
batchSize,[this.trainImages,this.trainLabels],()=>{
this.shuffledTrainIndex=
(this.shuffledTrainIndex+1)%this.trainIndices.length;
returnthis.trainIndices[this.shuffledTrainIndex];
});
}
//*从测试集中返回一批图片及其标签
nextTestBatch(batchSize){
returnthis.nextBatch(batchSize,[this.testImages,this.testLabels],()=>{
this.shuffledTestIndex=
(this.shuffledTestIndex+1)%this.testIndices.length;
returnthis.testIndices[this.shuffledTestIndex];
});
}
nextBatch(batchSize,data,index){
constbatchImagesArray=newFloat32Array(batchSize*IMAGE_SIZE);
constbatchLabelsArray=newUint8Array(batchSize*NUM_CLASSES);
for(leti=0;i<batchSize;i++){
constidx=index();
constimage=
data[0].slice(idx*IMAGE_SIZE,idx*IMAGE_SIZE+IMAGE_SIZE);
batchImagesArray.set(image,i*IMAGE_SIZE);
constlabel=
data[1].slice(idx*NUM_CLASSES,idx*NUM_CLASSES+NUM_CLASSES);
batchLabelsArray.set(label,i*NUM_CLASSES);
}
constxs=tf.tensor2d(batchImagesArray,[batchSize,IMAGE_SIZE]);
constlabels=tf.tensor2d(batchLabelsArray,[batchSize,NUM_CLASSES]);
return{xs,labels};
}}代码2定义网络模型函数exportfunctiongetModel(){
constmodel=tf.sequential();
constIMAGE_WIDTH=28;
constIMAGE_HEIGHT=28;
constIMAGE_CHANNELS=1;
model.add(tf.layers.conv2d({
inputShape:[IMAGE_WIDTH,IMAGE_HEIGHT,IMAGE_CHANNELS],//28*28*1的图片
kernelSize:5,//卷积核大小5*5
filters:12,//卷积核数量
strides:1,//步长
padding:'valid',//边缘填充
activation:'relu',//激活函数
kernelInitializer:'heNormal'//随机初始化模型权重
}));
model.add(tf.layers.maxPooling2d({poolSize:[2,2],strides:[2,2]}));
model.add(tf.layers.conv2d({
kernelSize:5,
filters:32,
strides:1,
padding:'valid',//边缘填充
activation:'relu',
kernelInitializer:'heNormal'
}));
model.add(tf.layers.maxPooling2d({poolSize:[2,2],strides:[2,2]}));
model.add(tf.layers.flatten());
model.add(tf.layers.dropout(0.25))
model.add(tf.layers.dense({
units:256,//输出空间的维数
kernelInitializer:'heNormal',//权重矩阵的初始值设定项
activation:'relu'//激活函数
}));
model.add(tf.layers.dropout(0.25))
model.add(tf.layers.dense({
units:128,//输出空间的维数
kernelInitializer:'heNormal',//权重矩阵的初始值设定项
activation:'relu'//激活函数
}));
model.add(tf.layers.dropout(0.25))
constNUM_OUTPUT_CLASSES=10;
//全连接层
model.add(tf.layers.dense({
units:NUM_OUTPUT_CLASSES,//输出空间的维数
kernelInitializer:'varianceScaling',//权重矩阵的初始值设定项
activation:'softmax'//激活函数
}));
constoptimizer=tf.train.adam();
//constoptimizer=tf.train.sgd(0.01);
pile({
optimizer:optimizer,//Adam方式更新参数,优化器
loss:'categoricalCrossentropy',//交叉熵损失函数
metrics:['accuracy'],
});
console.log('getmodel完毕');
returnmodel;}代码3对模型训练函数exportasyncfunctiontrain(model,data){
constBATCH_SIZE=512;
constTRAIN_DATA_SIZE=5500;
constTEST_DATA_SIZE=1000;
const[trainXs,trainYs]=tf.tidy(()=>{
constd=data.nextTrainBatch(TRAIN_DATA_SIZE);
return[
d.xs.reshape([TRAIN_DATA_SIZE,28,28,1]),
d.labels
];
});
const[testXs,testYs]=tf.tidy(()=>{
constd=data.nextTestBatch(TEST_DATA_SIZE);
return[
d.xs.reshape([TEST_DATA_SIZE,28,28,1]),
d.labels
];
});
consth=awaitmodel.fit(trai
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026-2030湿巾市场前景分析及投资策略与风险管理研究报告
- 2026年中国女童半袖项目投资可行性研究报告
- 水利国际营销策划协议
- 永德县2027届六年级数学第一学期期末考试模拟试题含解析
- 吉林省白山市临江市2026-2027学年三年级数学第一学期期末达标检测试题含解析
- 智能化保险产品设计方法-第9篇
- 具身智能在金融风控中的应用研究-第4篇
- 发电厂应急预案准则
- 某钢厂环境保护制度
- 建筑项目施工现场班组标准化管理
- 绿化养护工人安全培训资料
- T/CACM 1056.92-2019中药材种子种苗天南星种子
- JJF(陕) 104-2023 裂隙灯显微镜校准规范
- 竞聘静脉治疗专科护士
- 2024年管道燃气客服员(中级)技能鉴定考试复习题库(含答案)
- 急性胰腺炎的护理查房模板
- (新版)铁路机车车辆制动钳工(中级)职业鉴定考试题库(含答案)
- 伦理审查表(一式三份)
- 人体艺术欣赏
- 化工节能原理与技术课件-XXXX09
- 大学生仓库管理员暑期社会实践报告
评论
0/150
提交评论