-
Notifications
You must be signed in to change notification settings - Fork 10
/
Train.java
71 lines (51 loc) · 2.17 KB
/
Train.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Developer: Minhas Kamal (BSSE: 0509, IID, DU)
* Date: 09.Sep.2014
**/
package com.minhaskamal.alphabetRecognizer;
import java.io.File;
import java.util.ArrayList;
import com.minhaskamal.alphabetRecognizer.weightedPixel.WeightedStandardImage;
import com.minhaskamal.alphabetRecognizer.weightedPixel.WeightedStandardPixelTrainer;
import com.minhaskamal.egami.matrix.Matrix;
public class Train {
public static void main(String[] args) throws Exception {
//list of image files//////////////////////////////////////////////////////////////////////////////////////////
int types = 79;
String[] stringFilePaths = new String[types];
for(int i=1; i<=types; i++){
stringFilePaths[i-1] = "src/res/trainingData/" + i;
}
ArrayList<String> filePathList = new ArrayList<String>();
ArrayList<Integer> idList = new ArrayList<Integer>();
int id=1;
for(String stringFilePath: stringFilePaths){
File[] files = new File(stringFilePath).listFiles();
for(File file: files){
filePathList.add(file.getAbsolutePath());
idList.add(id);
}
id++;
}
String[] filePaths = new String[filePathList.size()];
filePathList.toArray(filePaths);
Integer[] ids = new Integer[idList.size()];
idList.toArray(ids);
///test
/*for(int i=filePaths.length-1; i>=0; i--){
System.out.println("filePaths: " + filePaths[i]);
System.out.println("ids: " + ids[i]);
}*/
//train/////////////////////////////////////////////////////////////////////////////////////////////////////////
WeightedStandardPixelTrainer weightedStandardPixelTrainer = new WeightedStandardPixelTrainer(new int[]{45, 45});
weightedStandardPixelTrainer.train(filePaths, ids);
WeightedStandardImage weightedStandardImage = weightedStandardPixelTrainer.getWeightedStandardImage();
weightedStandardImage.saveKnowledge("src/res/knowledge/KnowledgeAlphabet.log");
///test
for(int i=0; i<types; i++){
Matrix mat = weightedStandardImage.getStandardImages(i);
mat.write("src/res/knowledge/imageRepresentation/stdImage " + i + ".png");
}
System.out.println("Operation Successful!!!");
}
}