!44 修改切割

Merge pull request !44 from 逐光/test
pull/44/MERGE
逐光 5 years ago committed by Gitee
commit f74d96139e

@ -62,26 +62,17 @@ public class Convolution extends Frequency {
return threeChannelMatrixList; return threeChannelMatrixList;
} }
public List<List<Double>> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub public List<List<Double>> kAvg(ThreeChannelMatrix threeMatrix, int sqNub
, int regionSize) throws Exception { , int regionSize) throws Exception {
RGBSort rgbSort = new RGBSort(); RGBSort rgbSort = new RGBSort();
List<List<Double>> features = new ArrayList<>(); List<List<Double>> features = new ArrayList<>();
Matrix matrixR = threeMatrix.getMatrixR();
Matrix matrixG = threeMatrix.getMatrixG();
Matrix matrixB = threeMatrix.getMatrixB();
matrixR = late(matrixR, poolSize);
matrixG = late(matrixG, poolSize);
matrixB = late(matrixB, poolSize);
threeMatrix.setMatrixR(matrixR);
threeMatrix.setMatrixG(matrixG);
threeMatrix.setMatrixB(matrixB);
List<ThreeChannelMatrix> threeChannelMatrixList = regionThreeChannelMatrix(threeMatrix, regionSize); List<ThreeChannelMatrix> threeChannelMatrixList = regionThreeChannelMatrix(threeMatrix, regionSize);
for (ThreeChannelMatrix threeChannelMatrix : threeChannelMatrixList) { for (ThreeChannelMatrix threeChannelMatrix : threeChannelMatrixList) {
List<Double> feature = new ArrayList<>(); List<Double> feature = new ArrayList<>();
MeanClustering meanClustering = new MeanClustering(sqNub); MeanClustering meanClustering = new MeanClustering(sqNub);
matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixR = threeChannelMatrix.getMatrixR();
matrixG = threeChannelMatrix.getMatrixG(); Matrix matrixG = threeChannelMatrix.getMatrixG();
matrixB = threeChannelMatrix.getMatrixB(); Matrix matrixB = threeChannelMatrix.getMatrixB();
int x = matrixR.getX(); int x = matrixR.getX();
int y = matrixR.getY(); int y = matrixR.getY();
for (int i = 0; i < x; i++) { for (int i = 0; i < x; i++) {
@ -93,14 +84,12 @@ public class Convolution extends Frequency {
meanClustering.start(); meanClustering.start();
List<RGBNorm> rgbNorms = meanClustering.getMatrices(); List<RGBNorm> rgbNorms = meanClustering.getMatrices();
Collections.sort(rgbNorms, rgbSort); Collections.sort(rgbNorms, rgbSort);
double[] dm = new double[sqNub];
for (RGBNorm rgbNorm : rgbNorms) { for (RGBNorm rgbNorm : rgbNorms) {
feature.add(rgbNorm.getNorm()); double[] rgb = rgbNorm.getRgb();
} for (int i = 0; i < rgb.length; i++) {
for (int t = 0; t < dm.length; t++) { feature.add(rgb[i]);
dm[t] = rgbNorms.get(t).getNorm(); }
} }
//System.out.println(Arrays.toString(dm));
features.add(feature); features.add(feature);
} }
return features; return features;

@ -58,6 +58,17 @@ public class Operation {//进行计算
return sub(matrix1); return sub(matrix1);
} }
private void cutPic(ThreeChannelMatrix threeChannelMatrix, int x, int y, int xSize, int ySize) {
Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG();
Matrix matrixB = threeChannelMatrix.getMatrixB();
Matrix matrixRGB = threeChannelMatrix.getMatrixRGB();
threeChannelMatrix.setMatrixR(matrixR.getSonOfMatrix(x, y, xSize, ySize));
threeChannelMatrix.setMatrixG(matrixG.getSonOfMatrix(x, y, xSize, ySize));
threeChannelMatrix.setMatrixB(matrixB.getSonOfMatrix(x, y, xSize, ySize));
threeChannelMatrix.setMatrixRGB(matrixRGB.getSonOfMatrix(x, y, xSize, ySize));
}
public void colorStudy(ThreeChannelMatrix threeChannelMatrix, int tag, List<Specifications> specificationsList) throws Exception { public void colorStudy(ThreeChannelMatrix threeChannelMatrix, int tag, List<Specifications> specificationsList) throws Exception {
Watershed watershed = new Watershed(threeChannelMatrix.getMatrixRGB(), specificationsList, templeConfig); Watershed watershed = new Watershed(threeChannelMatrix.getMatrixRGB(), specificationsList, templeConfig);
List<RegionBody> regionBodies = watershed.rainfall(); List<RegionBody> regionBodies = watershed.rainfall();
@ -226,41 +237,40 @@ public class Operation {//进行计算
return id; return id;
} }
public void coverStudy(Map<Integer, ThreeChannelMatrix> matrixMap, int poolSize, int sqNub, int regionSize, public void coverStudy(Map<Integer, ThreeChannelMatrix> matrixMap, int sqNub, int regionSize) throws Exception {
int times) throws Exception {
if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) { if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) {
int size = 0; int size = 0;
List<CoverBody> coverBodies = new ArrayList<>(); List<CoverBody> coverBodies = new ArrayList<>();
for (Map.Entry<Integer, ThreeChannelMatrix> entry : matrixMap.entrySet()) { for (Map.Entry<Integer, ThreeChannelMatrix> entry : matrixMap.entrySet()) {
//先进行切图
CoverBody coverBody = new CoverBody(); CoverBody coverBody = new CoverBody();
Map<Integer, Double> tag = new HashMap<>(); Map<Integer, Double> tag = new HashMap<>();
tag.put(entry.getKey(), 1.0); tag.put(entry.getKey(), 1.0);
List<List<Double>> lists = convolution.kAvg(entry.getValue(), poolSize, sqNub, regionSize); List<List<Double>> lists = convolution.kAvg(entry.getValue(), sqNub, regionSize);
size = lists.size(); size = lists.size();
coverBody.setFeature(lists); coverBody.setFeature(lists);
coverBody.setTag(tag); coverBody.setTag(tag);
coverBodies.add(coverBody); coverBodies.add(coverBody);
} }
//特征塞入容器完毕 //特征塞入容器完毕
for (int j = 0; j < times; j++) { for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++) { for (CoverBody coverBody : coverBodies) {
for (CoverBody coverBody : coverBodies) { List<Double> list = coverBody.getFeature().get(i);
List<Double> list = coverBody.getFeature().get(i); if (templeConfig.isShowLog()) {
if (templeConfig.isShowLog()) { System.out.println("feature:" + list);
System.out.println("feature:" + list);
}
intoDnnNetwork(1, list, templeConfig.getSensoryNerves(), true, coverBody.getTag(), null);
} }
intoDnnNetwork(1, list, templeConfig.getSensoryNerves(), true, coverBody.getTag(), null);
} }
} }
} }
} }
public Map<Integer, Double> coverPoint(ThreeChannelMatrix matrix, int poolSize, int sqNub, int regionSize) throws Exception { public Map<Integer, Double> coverPoint(ThreeChannelMatrix matrix, int sqNub, int regionSize) throws Exception {
if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) { if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) {
Map<Integer, Double> coverMap = new HashMap<>(); Map<Integer, Double> coverMap = new HashMap<>();
Map<Integer, Integer> typeNub = new HashMap<>(); Map<Integer, Integer> typeNub = new HashMap<>();
List<List<Double>> lists = convolution.kAvg(matrix, poolSize, sqNub, regionSize); List<List<Double>> lists = convolution.kAvg(matrix, sqNub, regionSize);
//特征塞入容器完毕 //特征塞入容器完毕
int size = lists.size(); int size = lists.size();
int all = 0; int all = 0;

@ -25,6 +25,8 @@ public class Watershed {
private int xMax; private int xMax;
private int yMax; private int yMax;
private double maxRain; private double maxRain;
private double width;
private double height;
private List<Specifications> specifications; private List<Specifications> specifications;
public Watershed(Matrix matrix, List<Specifications> specifications, TempleConfig templeConfig) throws Exception { public Watershed(Matrix matrix, List<Specifications> specifications, TempleConfig templeConfig) throws Exception {
@ -35,6 +37,8 @@ public class Watershed {
maxRain = cutting.getMaxRain(); maxRain = cutting.getMaxRain();
this.matrix = matrix; this.matrix = matrix;
this.specifications = specifications; this.specifications = specifications;
width = matrix.getY();
height = matrix.getX();
xSize = matrix.getX() / regionNub; xSize = matrix.getX() / regionNub;
ySize = matrix.getY() / regionNub; ySize = matrix.getY() / regionNub;
// System.out.println("xSize===" + xSize + ",ysize===" + ySize); // System.out.println("xSize===" + xSize + ",ysize===" + ySize);
@ -212,6 +216,9 @@ public class Watershed {
for (Specifications specification : specifications) { for (Specifications specification : specifications) {
int width = maxY - minY; int width = maxY - minY;
int height = maxX - minX; int height = maxX - minX;
// double h = this.height / 8;
// double w = this.width / 8;
// boolean isCenter = minX > h && minY > w && minX < (h * 4.5) && minY < (w * 4.5);
if (width >= specification.getMinWidth() && height >= specification.getMinHeight() if (width >= specification.getMinWidth() && height >= specification.getMinHeight()
&& width <= specification.getMaxWidth() && height <= specification.getMaxHeight()) { && width <= specification.getMaxWidth() && height <= specification.getMaxHeight()) {
isRight = true; isRight = true;
@ -301,7 +308,7 @@ public class Watershed {
} }
createMerge(); createMerge();
merge(); merge();
// System.out.println(regionMap.getString()); // System.out.println(regionMap.getString());
} }
private int getMinIndex(double[] array, double mySelf) {//获取最小值 private int getMinIndex(double[] array, double mySelf) {//获取最小值

@ -13,9 +13,17 @@ import java.util.List;
* @date 4:14 2020/2/23 * @date 4:14 2020/2/23
*/ */
public class Talk { public class Talk {
private List<WorldBody> allWorld = WordTemple.get().getAllWorld();//所有词集合 private List<WorldBody> allWorld;//所有词集合
private RandomForest randomForest = WordTemple.get().getRandomForest();//获取随机森林模型 private RandomForest randomForest;//获取随机森林模型
private List<List<String>> wordTimes = WordTemple.get().getWordTimes(); private List<List<String>> wordTimes;
private WordTemple wordTemple;
public Talk(WordTemple wordTemple) {
this.wordTemple = wordTemple;
allWorld = wordTemple.getAllWorld();//所有词集合
randomForest = wordTemple.getRandomForest();//获取随机森林模型
wordTimes = wordTemple.getWordTimes();
}
public List<Integer> talk(String sentence) throws Exception { public List<Integer> talk(String sentence) throws Exception {
List<Integer> typeList = new ArrayList<>(); List<Integer> typeList = new ArrayList<>();
@ -69,7 +77,7 @@ public class Talk {
features.add(nub); features.add(nub);
} }
int type = 0; int type = 0;
if (ArithUtil.div(wrong, wordNumber) < WordTemple.get().getGarbageTh()) { if (ArithUtil.div(wrong, wordNumber) < wordTemple.getGarbageTh()) {
LangBody langBody = new LangBody(); LangBody langBody = new LangBody();
langBody.setA1(features.get(0)); langBody.setA1(features.get(0));
langBody.setA2(features.get(1)); langBody.setA2(features.get(1));
@ -135,7 +143,7 @@ public class Talk {
listWord = body.getWorldBodies();//这个body报了一次空指针 listWord = body.getWorldBodies();//这个body报了一次空指针
word.setWordFrequency(body.getWordFrequency()); word.setWordFrequency(body.getWordFrequency());
} }
Tokenizer tokenizer = new Tokenizer(); Tokenizer tokenizer = new Tokenizer(wordTemple);
tokenizer.radiation(words); tokenizer.radiation(words);
} }

@ -20,7 +20,7 @@ public class TemplateReader {//模板读取类
* @param charsetName (使UTF-8) * @param charsetName (使UTF-8)
* @throws Exception * @throws Exception
*/ */
public void read(String url, String charsetName) throws Exception { public void read(String url, String charsetName, WordTemple wordTemple) throws Exception {
this.charsetName = charsetName; this.charsetName = charsetName;
File file = new File(url); File file = new File(url);
InputStream is = new FileInputStream(file); InputStream is = new FileInputStream(file);
@ -68,11 +68,12 @@ public class TemplateReader {//模板读取类
} }
} }
} }
word(); word(wordTemple);
} }
public void word() throws Exception { public void word(WordTemple wordTemple) throws Exception {
Tokenizer tokenizer = new Tokenizer(); //将模版注入分词器进行分词
Tokenizer tokenizer = new Tokenizer(wordTemple);
tokenizer.start(model); tokenizer.start(model);
} }

@ -13,10 +13,18 @@ import java.util.*;
* @date 7:42 2020/2/23 * @date 7:42 2020/2/23
*/ */
public class Tokenizer extends Frequency { public class Tokenizer extends Frequency {
private List<Sentence> sentences = WordTemple.get().getSentences();//所有断句 private List<Sentence> sentences;//所有断句
private List<WorldBody> allWorld = WordTemple.get().getAllWorld();//所有词集合 private List<WorldBody> allWorld;//所有词集合
private List<List<String>> wordTimes = WordTemple.get().getWordTimes();//所有词编号 private List<List<String>> wordTimes;//所有词编号
private Word nowWord;//上一次出现的关键字 private Word nowWord;//上一次出现的关键字
private WordTemple wordTemple;
public Tokenizer(WordTemple wordTemple) {
this.wordTemple = wordTemple;
sentences = wordTemple.getSentences();//所有断句
allWorld = wordTemple.getAllWorld();//所有词集合
wordTimes = wordTemple.getWordTimes();//所有词编号
}
public void start(Map<Integer, List<String>> model) throws Exception { public void start(Map<Integer, List<String>> model) throws Exception {
//model的主键是类别值是该类别语句的集合 //model的主键是类别值是该类别语句的集合
@ -59,7 +67,7 @@ public class Tokenizer extends Frequency {
} }
private void number() {//分词编号 private void number() {//分词编号
System.out.println("开始编码:" + sentences.size()); System.out.println("开始编码:" + (sentences.size() + 1));
for (Sentence sentence : sentences) { for (Sentence sentence : sentences) {
List<Integer> features = sentence.getFeatures(); List<Integer> features = sentence.getFeatures();
List<String> sentenceList = sentence.getKeyWords(); List<String> sentenceList = sentence.getKeyWords();
@ -85,10 +93,12 @@ public class Tokenizer extends Frequency {
} }
column.add("key"); column.add("key");
DataTable dataTable = new DataTable(column); DataTable dataTable = new DataTable(column);
dataTable.setKey("key"); dataTable.setKey("key");//确认结果集主键
//初始化随机森林 //初始化随机森林
RandomForest randomForest = new RandomForest(11); RandomForest randomForest = new RandomForest(wordTemple.getTreeNub());
WordTemple.get().setRandomForest(randomForest);//保存随机森林到模版 randomForest.setTrustTh(wordTemple.getTrustTh());
randomForest.setTrustPunishment(wordTemple.getTrustPunishment());
wordTemple.setRandomForest(randomForest);//保存随机森林到模版
randomForest.init(dataTable); randomForest.init(dataTable);
for (Sentence sentence : sentences) { for (Sentence sentence : sentences) {
LangBody langBody = new LangBody(); LangBody langBody = new LangBody();

@ -11,33 +11,30 @@ import java.util.List;
* @date 4:15 2020/2/23 * @date 4:15 2020/2/23
*/ */
public class WordTemple { public class WordTemple {
private static WordTemple Word_Temple = new WordTemple();
private List<Sentence> sentences = new ArrayList<>();//所有断句 private List<Sentence> sentences = new ArrayList<>();//所有断句
private List<WorldBody> allWorld = new ArrayList<>();//所有词集合 private List<WorldBody> allWorld = new ArrayList<>();//所有词集合
private List<List<String>> wordTimes = new ArrayList<>();//词编号 private List<List<String>> wordTimes = new ArrayList<>();//词编号
private RandomForest randomForest;//保存的随机森林模型 private RandomForest randomForest;//保存的随机森林模型
//四大参数
private double garbageTh = 0.5;//垃圾分类的阈值默认0.5 private double garbageTh = 0.5;//垃圾分类的阈值默认0.5
private double trustPunishment = 0.1;//信任惩罚 private double trustPunishment = 0.1;//信任惩罚
private double trustTh = 0.1;//信任阈值,相当于一次信任惩罚的数值
private int treeNub = 11;//丛林里面树的数量
public WordModel getModel() {//获取模型 public int getTreeNub() {
WordModel wordModel = new WordModel(); return treeNub;
wordModel.setAllWorld(allWorld);
wordModel.setWordTimes(wordTimes);
wordModel.setGarbageTh(garbageTh);
wordModel.setTrustPunishment(trustPunishment);
wordModel.setTrustTh(randomForest.getTrustTh());
wordModel.setRfModel(randomForest.getModel());
return wordModel;
} }
public void insertModel(WordModel wordModel) throws Exception {//注入模型 public void setTreeNub(int treeNub) {
allWorld = wordModel.getAllWorld(); this.treeNub = treeNub;
wordTimes = wordModel.getWordTimes(); }
garbageTh = wordModel.getGarbageTh();
trustPunishment = wordModel.getTrustPunishment(); public double getTrustTh() {
randomForest = new RandomForest(); return trustTh;
randomForest.setTrustTh(wordModel.getTrustTh()); }
randomForest.insertModel(wordModel.getRfModel());
public void setTrustTh(double trustTh) {
this.trustTh = trustTh;
} }
public double getTrustPunishment() { public double getTrustPunishment() {
@ -64,9 +61,6 @@ public class WordTemple {
this.randomForest = randomForest; this.randomForest = randomForest;
} }
private WordTemple() {
}
public List<List<String>> getWordTimes() { public List<List<String>> getWordTimes() {
return wordTimes; return wordTimes;
} }
@ -75,10 +69,6 @@ public class WordTemple {
this.wordTimes = wordTimes; this.wordTimes = wordTimes;
} }
public static WordTemple get() {
return Word_Temple;
}
public List<Sentence> getSentences() { public List<Sentence> getSentences() {
return sentences; return sentences;
} }

@ -13,6 +13,15 @@ public class RandomForest {
private Random random = new Random(); private Random random = new Random();
private Tree[] forest; private Tree[] forest;
private double trustTh = 0.1;//信任阈值 private double trustTh = 0.1;//信任阈值
private double trustPunishment = 0.1;//信任惩罚
public double getTrustPunishment() {
return trustPunishment;
}
public void setTrustPunishment(double trustPunishment) {
this.trustPunishment = trustPunishment;
}
public double getTrustTh() { public double getTrustTh() {
return trustTh; return trustTh;
@ -33,21 +42,6 @@ public class RandomForest {
} }
} }
public void insertModel(RfModel rfModel) throws Exception {//注入模型
if (rfModel != null) {
Map<Integer, Node> nodeMap = rfModel.getNodeMap();
forest = new Tree[nodeMap.size()];
for (Map.Entry<Integer, Node> entry : nodeMap.entrySet()) {
int key = entry.getKey();
Tree tree = new Tree();
forest[key] = tree;
tree.setRootNode(entry.getValue());
}
} else {
throw new Exception("model is null");
}
}
public RfModel getModel() {//获取模型 public RfModel getModel() {//获取模型
RfModel rfModel = new RfModel(); RfModel rfModel = new RfModel();
Map<Integer, Node> nodeMap = new HashMap<>(); Map<Integer, Node> nodeMap = new HashMap<>();
@ -89,6 +83,7 @@ public class RandomForest {
return type; return type;
} }
//rf初始化
public void init(DataTable dataTable) throws Exception { public void init(DataTable dataTable) throws Exception {
//一棵树属性的数量 //一棵树属性的数量
if (dataTable.getSize() > 4) { if (dataTable.getSize() > 4) {
@ -96,7 +91,7 @@ public class RandomForest {
//int kNub = dataTable.getSize() - 1; //int kNub = dataTable.getSize() - 1;
// System.out.println("knNub==" + kNub); // System.out.println("knNub==" + kNub);
for (int i = 0; i < forest.length; i++) { for (int i = 0; i < forest.length; i++) {
Tree tree = new Tree(getRandomData(dataTable, kNub)); Tree tree = new Tree(getRandomData(dataTable, kNub), trustPunishment);
forest[i] = tree; forest[i] = tree;
} }
} else { } else {
@ -119,6 +114,7 @@ public class RandomForest {
} }
} }
//从总属性列表中随机挑选属性kNub个属性数量
private DataTable getRandomData(DataTable dataTable, int kNub) throws Exception { private DataTable getRandomData(DataTable dataTable, int kNub) throws Exception {
Set<String> attr = dataTable.getKeyType(); Set<String> attr = dataTable.getKeyType();
Set<String> myName = new HashSet<>(); Set<String> myName = new HashSet<>();

@ -18,6 +18,7 @@ public class Tree {//决策树
private List<Integer> endList;//最终结果分类 private List<Integer> endList;//最终结果分类
private List<Node> lastNodes = new ArrayList<>();//最后一层节点集合 private List<Node> lastNodes = new ArrayList<>();//最后一层节点集合
private Random random = new Random(); private Random random = new Random();
private double trustPunishment;//信任惩罚
public Node getRootNode() { public Node getRootNode() {
return rootNode; return rootNode;
@ -36,11 +37,13 @@ public class Tree {//决策树
private double gainRatio;//信息增益率 private double gainRatio;//信息增益率
} }
public Tree() { public Tree(double trustPunishment) {
this.trustPunishment = trustPunishment;
} }
public Tree(DataTable dataTable) throws Exception { public Tree(DataTable dataTable, double trustPunishment) throws Exception {
if (dataTable != null && dataTable.getKey() != null) { if (dataTable != null && dataTable.getKey() != null) {
this.trustPunishment = trustPunishment;
this.dataTable = dataTable; this.dataTable = dataTable;
} else { } else {
throw new Exception("dataTable is empty"); throw new Exception("dataTable is empty");
@ -221,7 +224,7 @@ public class Tree {//决策树
private void punishment(TreeWithTrust treeWithTrust) {//信任惩罚 private void punishment(TreeWithTrust treeWithTrust) {//信任惩罚
//System.out.println("惩罚"); //System.out.println("惩罚");
double trust = treeWithTrust.getTrust();//获取当前信任值 double trust = treeWithTrust.getTrust();//获取当前信任值
trust = ArithUtil.mul(trust, WordTemple.get().getTrustPunishment()); trust = ArithUtil.mul(trust, trustPunishment);
treeWithTrust.setTrust(trust); treeWithTrust.setTrust(trust);
} }

@ -24,7 +24,7 @@ import java.util.Map;
public class CoverTest { public class CoverTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
//cover(); cover();
} }
public static void insertModel(String model) throws Exception {//注入模型 public static void insertModel(String model) throws Exception {//注入模型
@ -52,18 +52,18 @@ public class CoverTest {
return new Operation(templeConfig);//初始化运算类 return new Operation(templeConfig);//初始化运算类
} }
public static void test(Operation operation, int poolSize, int sqlNub, int regionSize, public static void test(Operation operation, int sqlNub, int regionSize,
String name, int t) throws Exception { String name, int t) throws Exception {
Picture picture = new Picture(); Picture picture = new Picture();
int wrong = 0; int wrong = 0;
if (operation == null) { if (operation == null) {
operation = getModel(); operation = getModel();
} }
for (int i = 1; i < 100; i++) { for (int i = 1; i < 20; i++) {
String na = "D:\\share\\cai/" + name + i + ".jpg"; String na = "/Users/lidapeng/Desktop/myDocument/food/" + name + i + ".jpg";
//System.out.println("name======================" + na); //System.out.println("name======================" + na);
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(na); ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(na);
Map<Integer, Double> map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize); Map<Integer, Double> map1 = operation.coverPoint(threeChannelMatrix, sqlNub, regionSize);
int id = 0; int id = 0;
double point = 0; double point = 0;
for (Map.Entry<Integer, Double> entry : map1.entrySet()) { for (Map.Entry<Integer, Double> entry : map1.entrySet()) {
@ -90,6 +90,8 @@ public class CoverTest {
} }
public static void cover() throws Exception { public static void cover() throws Exception {
int sqNub = 1;
int regionSize = 20;
//创建图片解析类 桔梗覆盖,桔梗焚烧,土壤扰动 //创建图片解析类 桔梗覆盖,桔梗焚烧,土壤扰动
Picture picture = new Picture(); Picture picture = new Picture();
//创建模版类参数选false就可以 //创建模版类参数选false就可以
@ -97,35 +99,36 @@ public class CoverTest {
//初始化模板 注意 width height参数是你训练图片的实际尺寸需要改其他不用动 //初始化模板 注意 width height参数是你训练图片的实际尺寸需要改其他不用动
//创建运算类进行标注 //创建运算类进行标注
templeConfig.isShowLog(true); templeConfig.isShowLog(true);
templeConfig.setStudyPoint(0.01);//不动 templeConfig.setStudyPoint(0.005);//不动
templeConfig.setSoftMax(true); //templeConfig.setSoftMax(true);
//templeConfig.setDeep(2); templeConfig.setDeep(2);
//templeConfig.setHiddenNerveNub(9); templeConfig.setHiddenNerveNub(9);
templeConfig.setSensoryNerveNub(3);//多出来的 templeConfig.setSensoryNerveNub(sqNub);//多出来的
templeConfig.setRzType(RZ.L1);//不动//3 18 templeConfig.setRzType(RZ.L1);//不动//3 18
templeConfig.setlParam(0.015);//不动 templeConfig.setlParam(0.015);//不动
templeConfig.setClassifier(Classifier.DNN); templeConfig.setClassifier(Classifier.DNN);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 4); templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 4);
Operation operation = new Operation(templeConfig); Operation operation = new Operation(templeConfig);
for (int i = 1; i < 100; i++) { for (int i = 1; i < 20; i++) {
System.out.println("i====================================" + i);
Map<Integer, ThreeChannelMatrix> matrixMap = new HashMap<>(); Map<Integer, ThreeChannelMatrix> matrixMap = new HashMap<>();
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai/a" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\cai/b" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\share\\cai/c" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/c" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\cai/d" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/d" + i + ".jpg");
matrixMap.put(1, threeChannelMatrix1);//桔梗覆盖 matrixMap.put(1, threeChannelMatrix1);//桔梗覆盖
matrixMap.put(2, threeChannelMatrix2);//土地 matrixMap.put(2, threeChannelMatrix2);//土地
matrixMap.put(3, threeChannelMatrix3);//桔梗覆盖 matrixMap.put(3, threeChannelMatrix3);//桔梗覆盖
matrixMap.put(4, threeChannelMatrix4);//土地 matrixMap.put(4, threeChannelMatrix4);//土地
operation.coverStudy(matrixMap, 2, 3, 18, 2); operation.coverStudy(matrixMap, sqNub, regionSize);
} }
ModelParameter modelParameter = templeConfig.getModel(); // ModelParameter modelParameter = templeConfig.getModel();
String model = JSON.toJSONString(modelParameter); // String model = JSON.toJSONString(modelParameter);
System.out.println(model); // System.out.println(model);
test(operation, 2, 3, 18, "a", 1); test(operation, sqNub, regionSize, "a", 1);
test(operation, 2, 3, 18, "b", 2); test(operation, sqNub, regionSize, "b", 2);
test(operation, 2, 3, 18, "c", 3); test(operation, sqNub, regionSize, "c", 3);
test(operation, 2, 3, 18, "d", 4); test(operation, sqNub, regionSize, "d", 4);
} }
} }

@ -3,6 +3,7 @@ package coverTest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.wlld.MatrixTools.Matrix; import org.wlld.MatrixTools.Matrix;
import org.wlld.ModelData;
import org.wlld.config.Classifier; import org.wlld.config.Classifier;
import org.wlld.config.RZ; import org.wlld.config.RZ;
import org.wlld.config.StudyPattern; import org.wlld.config.StudyPattern;
@ -20,6 +21,12 @@ import java.util.List;
public class FoodTest { public class FoodTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// ModelParameter parameter = JSON.parseObject(ModelData.DATA, ModelParameter.class);
// if (parameter.getKnnVector() != null) {
// System.out.println("空的");
// } else {
// System.out.println("不是空===");
// }
test(); test();
} }
@ -40,19 +47,20 @@ public class FoodTest {
public static void test2(TempleConfig templeConfig) throws Exception { public static void test2(TempleConfig templeConfig) throws Exception {
if (templeConfig == null) { if (templeConfig == null) {
ModelParameter parameter = JSON.parseObject(ModelData.DATA, ModelParameter.class);
templeConfig = getTemple(null); templeConfig = getTemple(null);
} }
Picture picture = new Picture(); Picture picture = new Picture();
List<Specifications> specificationsList = new ArrayList<>(); List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications(); Specifications specifications = new Specifications();
specifications.setMinWidth(250); specifications.setMinWidth(400);
specifications.setMinHeight(250); specifications.setMinHeight(400);
specifications.setMaxWidth(750); specifications.setMaxWidth(950);
specifications.setMaxHeight(750); specifications.setMaxHeight(950);
specificationsList.add(specifications); specificationsList.add(specifications);
Operation operation = new Operation(templeConfig); Operation operation = new Operation(templeConfig);
for (int i = 1; i <= 28; i++) { for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai\\g/g" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/c" + i + ".jpg");
List<RegionBody> regionBody = operation.colorLook(threeChannelMatrix1, specificationsList); List<RegionBody> regionBody = operation.colorLook(threeChannelMatrix1, specificationsList);
for (int j = 0; j < regionBody.size(); j++) { for (int j = 0; j < regionBody.size(); j++) {
RegionBody regionBody1 = regionBody.get(j); RegionBody regionBody1 = regionBody.get(j);
@ -70,17 +78,17 @@ public class FoodTest {
Cutting cutting = templeConfig.getCutting(); Cutting cutting = templeConfig.getCutting();
Food food = templeConfig.getFood(); Food food = templeConfig.getFood();
//切割 //切割
cutting.setMaxRain(320);//切割阈值 cutting.setMaxRain(310);//切割阈值
cutting.setTh(0.88); cutting.setTh(0.8);
cutting.setRegionNub(200); cutting.setRegionNub(200);
//knn参数 //knn参数
templeConfig.setKnnNub(3); templeConfig.setKnnNub(1);
//池化比例 //池化比例
templeConfig.setPoolSize(2);//缩小比例 templeConfig.setPoolSize(2);//缩小比例
//聚类 //聚类
templeConfig.setFeatureNub(3);//聚类特征数量 templeConfig.setFeatureNub(3);//聚类特征数量
//菜品识别实体类 //菜品识别实体类
food.setShrink(60);//缩紧像素 food.setShrink(5);//缩紧像素
food.setTimes(2);//聚类数据增强 food.setTimes(2);//聚类数据增强
templeConfig.setClassifier(Classifier.KNN); templeConfig.setClassifier(Classifier.KNN);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3); templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
@ -96,35 +104,30 @@ public class FoodTest {
Operation operation = new Operation(templeConfig); Operation operation = new Operation(templeConfig);
List<Specifications> specificationsList = new ArrayList<>(); List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications(); Specifications specifications = new Specifications();
specifications.setMinWidth(250); specifications.setMinWidth(400);
specifications.setMinHeight(250); specifications.setMinHeight(400);
specifications.setMaxWidth(750); specifications.setMaxWidth(950);
specifications.setMaxHeight(750); specifications.setMaxHeight(950);
specificationsList.add(specifications); specificationsList.add(specifications);
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai\\a/a" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\cai\\b/b" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\share\\cai\\c/c" + i + ".jpg"); operation.colorStudy(threeChannelMatrix1, 83, specificationsList);
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\cai\\d/d" + i + ".jpg"); System.out.println("=======================================");
ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix("D:\\share\\cai\\e/e" + i + ".jpg"); operation.colorStudy(threeChannelMatrix2, 86, specificationsList);
ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix("D:\\share\\cai\\f/f" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix("D:\\share\\cai\\h/h" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix("D:\\share\\cai\\i/i" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix9 = picture.getThreeMatrix("D:\\share\\cai\\j/j" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix10 = picture.getThreeMatrix("D:\\share\\cai\\k/k" + i + ".jpg");
operation.colorStudy(threeChannelMatrix1, 1, specificationsList);
operation.colorStudy(threeChannelMatrix2, 2, specificationsList);
operation.colorStudy(threeChannelMatrix3, 3, specificationsList);
operation.colorStudy(threeChannelMatrix4, 4, specificationsList);
operation.colorStudy(threeChannelMatrix5, 5, specificationsList);
operation.colorStudy(threeChannelMatrix6, 6, specificationsList);
operation.colorStudy(threeChannelMatrix7, 7, specificationsList);
operation.colorStudy(threeChannelMatrix8, 8, specificationsList);
operation.colorStudy(threeChannelMatrix9, 9, specificationsList);
operation.colorStudy(threeChannelMatrix10, 10, specificationsList);
System.out.println("=======================================" + i); System.out.println("=======================================" + i);
} }
test2(templeConfig); ModelParameter modelParameter = templeConfig.getModel();
if (modelParameter.getKnnVector() != null) {
System.out.println("not null 1");
}
String tr = JSON.toJSONString(modelParameter);
System.out.println(tr);
ModelParameter modelParameter1 = JSON.parseObject(tr, ModelParameter.class);
if (modelParameter1.getKnnVector() != null) {
System.out.println("not null 2");
}
//test2(templeConfig);
} }
public static void study() throws Exception { public static void study() throws Exception {

@ -36,14 +36,8 @@ public class PicTest {
//testImage(right, wrong, a, b); //testImage(right, wrong, a, b);
//test(); //test();
tm();
} }
public static void tm() {
String model = ModelData.DATA4;
int index = model.indexOf("knnVector");
}
public static void test() throws Exception {//对图像进行识别测试 public static void test() throws Exception {//对图像进行识别测试
Picture picture = new Picture(); Picture picture = new Picture();

@ -70,17 +70,15 @@ public class LangTest {
public static void test() throws Exception { public static void test() throws Exception {
//创建模板读取累 //创建模板读取累
TemplateReader templateReader = new TemplateReader(); TemplateReader templateReader = new TemplateReader();
WordTemple wordTemple = new WordTemple();//初始化语言模版
wordTemple.setTreeNub(9);
//读取语言模版,第一个参数是模版地址,第二个参数是编码方式 (教程里的第三个参数已经省略) //读取语言模版,第一个参数是模版地址,第二个参数是编码方式 (教程里的第三个参数已经省略)
//同时也是学习过程 //同时也是学习过程
templateReader.read("D:\\b/a.txt", "UTF-8"); templateReader.read("/Users/lidapeng/Desktop/myDocument/model.txt", "UTF-8", wordTemple);
//学习结束获取模型参数 Talk talk = new Talk(wordTemple);
// WordModel wordModel = WordTemple.get().getModel();
//不用学习注入模型参数
// WordTemple.get().insertModel(wordModel);
Talk talk = new Talk();
//输入语句进行识别若有标点符号会形成LIST中的每个元素 //输入语句进行识别若有标点符号会形成LIST中的每个元素
//返回的集合中每个值代表了输入语句,每个标点符号前语句的分类 //返回的集合中每个值代表了输入语句,每个标点符号前语句的分类
List<Integer> list = talk.talk("有个快递尽快代我邮寄出去"); List<Integer> list = talk.talk("空调坏了");
System.out.println(list); System.out.println(list);
} }
} }

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save