• 大小: 23.38MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-15
  • 语言: Java
  • 标签: mnist  

资源简介

自己用java代码写的识别手写数字的全连接的神经网络

资源截图

代码片段和文件信息

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DeepLearn3Test {
static List trains = null ;
static List tests = null;
public static void main(String[] args) {
//load mnist
ReadFile rf1=new ReadFile(“train-labels.idx1-ubyte““train-images.idx3-ubyte“);
ReadFile rf2=new ReadFile(“t10k-labels.idx1-ubyte““t10k-images.idx3-ubyte“);
try {
tests = rf2.loadDigitImages();
trains =rf1.loadDigitImages();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


int size[]={784402010};
NeuralNetwork network = new NeuralNetwork(size);
network.radomInitWandB();

double image[] = new double[784];

for(int kk=0;kk<10;kk++){
//first: set input
for(int count=0;count for(int i=0;i<784;i++){
image[i] = (int)(trains.get(count).imageData[i]&0xff);
}
network.setInput(image);
//second: forward cal output
double[] output = network.forwardProc();
//third: backward cal delta
double[] y = new double[10];
for(int i=0;i if(i==trains.get(count).label){
y[i] = 1;
}else{
y[i] = 0;
}
}
network.backwarkProc(y);
//fouth: update w and b
network.updateWAndB(0.5);
}
System.out.println(“finished train count: “+kk);
}




boolean isTest = true;
//test
if(isTest){
int countCorrect=0;
for(int count=0;count for(int i=0;i<784;i++){
image[i] = (int)(tests.get(count).imageData[i]&0xff);
}
network.setInput(image);
//second: forward cal output
int number = network.testDigitalImage();
if(number==tests.get(count).label)countCorrect++;
//System.out.println(“count is : “+count+“  number is: “+number+“  label is:  “+tests.get(count).label);
}
System.out.println(“countCorrect: “+countCorrect);
}

}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-05-19 19:51  DeepLearn3Test\
     文件         301  2017-05-19 09:18  DeepLearn3Test\.classpath
     目录           0  2017-05-20 16:45  DeepLearn3Test\.git\
     文件          25  2017-05-20 16:44  DeepLearn3Test\.git\COMMIT_EDITMSG
     文件         370  2017-05-20 16:45  DeepLearn3Test\.git\config
     文件          73  2017-05-19 16:36  DeepLearn3Test\.git\description
     文件          23  2017-05-19 16:36  DeepLearn3Test\.git\HEAD
     目录           0  2017-05-19 16:36  DeepLearn3Test\.git\hooks\
     文件         478  2017-05-19 16:36  DeepLearn3Test\.git\hooks\applypatch-msg.sample
     文件         896  2017-05-19 16:36  DeepLearn3Test\.git\hooks\commit-msg.sample
     文件         189  2017-05-19 16:36  DeepLearn3Test\.git\hooks\post-update.sample
     文件         424  2017-05-19 16:36  DeepLearn3Test\.git\hooks\pre-applypatch.sample
     文件        1642  2017-05-19 16:36  DeepLearn3Test\.git\hooks\pre-commit.sample
     文件        1348  2017-05-19 16:36  DeepLearn3Test\.git\hooks\pre-push.sample
     文件        4951  2017-05-19 16:36  DeepLearn3Test\.git\hooks\pre-rebase.sample
     文件         544  2017-05-19 16:36  DeepLearn3Test\.git\hooks\pre-receive.sample
     文件        1239  2017-05-19 16:36  DeepLearn3Test\.git\hooks\prepare-commit-msg.sample
     文件        3610  2017-05-19 16:36  DeepLearn3Test\.git\hooks\update.sample
     文件        2309  2017-05-20 16:44  DeepLearn3Test\.git\index
     目录           0  2017-05-19 16:36  DeepLearn3Test\.git\info\
     文件         240  2017-05-19 16:36  DeepLearn3Test\.git\info\exclude
     目录           0  2017-05-19 16:40  DeepLearn3Test\.git\logs\
     文件         476  2017-05-20 16:44  DeepLearn3Test\.git\logs\HEAD
     目录           0  2017-05-19 16:41  DeepLearn3Test\.git\logs\refs\
     目录           0  2017-05-19 16:40  DeepLearn3Test\.git\logs\refs\heads\
     文件         476  2017-05-20 16:44  DeepLearn3Test\.git\logs\refs\heads\master
     目录           0  2017-05-19 16:41  DeepLearn3Test\.git\logs\refs\remotes\
     目录           0  2017-05-19 16:41  DeepLearn3Test\.git\logs\refs\remotes\origin\
     文件         435  2017-05-20 16:45  DeepLearn3Test\.git\logs\refs\remotes\origin\master
     目录           0  2017-05-20 16:44  DeepLearn3Test\.git\objects\
     目录           0  2017-05-20 16:44  DeepLearn3Test\.git\objects\04\
............此处省略112个文件信息

评论

共有 条评论