Пример #1
0
  /* (non-Javadoc)
   * @see SketchMaster.system.Recogniziers.RecognizierSystem#SaveTrainingSet(java.lang.String)
   */
  @Override
  public void SaveTrainingSet(String FileName) {
    if (svm != null) {
      if (!trained) this.train();

      String s = FileName;
      if (FileName.contains("\\")) {

        int temp = FileName.lastIndexOf(".");
        int temp1 = FileName.lastIndexOf("\\");
        s = FileName.substring(temp1 + 1, temp);

      } else {
        int temp = FileName.lastIndexOf(".");
        s = FileName.substring(0, temp);
      }
      //	int temp=FileName.lastIndexOf(".");
      // remove all the extention from current file name to it form model

      String mod = s + "_model.svt";

      svm.setModelFileName(mod);
      // first create the file object that will rite the file

      FileObjectWriter fileWriter = new FileObjectWriter();
      fileWriter.createFile(FileName);
      fileWriter.WriteObject(svm);
      fileWriter.closeWrite();
    }
  }
Пример #2
0
  public void createClusterFromStrokes() {

    //  only run if strok cound > 0

    //	sheet.getClusterStrokeCounts()
    if (CurrentStrokesCount > 0) {
      // get a list of the storke
      // create symbol
      LastClusterDrawn = sheet.CreateNewSymbol();

      // add to category
      // or add the stroke to the trining set
      if (SystemSettings.CurrentRecognizierOperation == this.RECGONIZE_OPERATION_TRAIN) {
        if (CaptureStrokes) {
          //
          if (logger.isDebugEnabled()) {
            //  logger.debug("createClusterFromStrokes() - adding an example to " + CurrentCat);
            // //$NON-NLS-1$
          }
          if (ExmapleType == EXAMPLE_POS) {

            addCategoryExample(CurrentCat, LastClusterDrawn);

          } else if (ExmapleType == EXAMPLE_NEG)
            addCategoryNegativeExample(CurrentCat, LastClusterDrawn);

          trained = false;
          // CaptureStrokes=false;
        }
      }

      // either classify the stroke
      if ((SystemSettings.CurrentRecognizierOperation == this.RECGONIZE_OPERATION_TEST)
          || (SystemSettings.CurrentRecognizierOperation == this.RECGONIZE_OPERATION_CLASSIFY)) {
        logger.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!classify !!!!!!!!!!!!!!!!!!!!!!!!!!!!");

        SegmentClusterFeatureSet example = new SegmentClusterFeatureSet();
        example.setSegmentCluster(LastClusterDrawn);
        example.initAll();
        LastDrawnfeats = example.computeSVMFeatures();
        SVMCurrentClassification = svm.classify(LastDrawnfeats);
      }

      CurrentStrokesCount = 0;
      setChanged();
      notifyObservers();
    }
  }
Пример #3
0
  /* (non-Javadoc)
   * @see SketchMaster.system.Recogniziers.RecognizierSystem#ReadTrainingSet(java.lang.String)
   */
  @Override
  public void ReadTrainingSet(String FileName) {

    logger.info("reading the training model ......");
    // set current to null
    svm = null;
    FileObjectReader fileReader = new FileObjectReader();
    fileReader.readFile(FileName);
    Object o = fileReader.ReadObject();
    if (o instanceof SVMClassifier) {
      svm = (SVMClassifier) o;
      // trainer.ReadData();
      Categories = new Hashtable<Integer, String>(svm.getLabels());
    }

    fileReader.closeRead();
  }
Пример #4
0
  /* (non-Javadoc)
   * @see SketchMaster.system.Recogniziers.RecognizierSystem#train()
   */
  @Override
  public void train() {

    if (xmlRead) {
      logger.info("----------Reading from xml so segment and create cluster first. -------------");
      // cluster all the reading to file
      SegmentTrainSetStrokes();
      xmlRead = false;
    }

    if (!trained) {
      logger.info("starting to train..........................");
      SegmentClusterFeatureSet example = new SegmentClusterFeatureSet();
      example.setSegmentCluster(LastClusterDrawn);
      example.initAll();
      svm.train(trainSet, example.getCountOfFeatures());
      trained = true;
    }
  }