libsvm.svm.svm_load_model()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中libsvm.svm.svm_load_model()方法的一些代码示例,展示了svm.svm_load_model()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。svm.svm_load_model()方法的具体详情如下:
包路径:libsvm.svm
类名称:svm
方法名:svm_load_model

svm.svm_load_model介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

public static SvmRegressor deserialize(byte[] modelData)
{
  // TODO do something with the hyperparameters
  try {
    svm_model model = svm.svm_load_model(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(modelData))));
    return new SvmRegressor(model);
  }
  catch (IOException e) {
    throw new UncheckedIOException(e);
  }
}

代码示例来源:origin: prestodb/presto

public static SvmClassifier deserialize(byte[] modelData)
{
  // TODO do something with the hyperparameters
  try {
    svm_model model = svm.svm_load_model(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(modelData))));
    return new SvmClassifier(model);
  }
  catch (IOException e) {
    throw new UncheckedIOException(e);
  }
}

代码示例来源:origin: DigitalPebble/TextClassification

protected final void loadModel() throws IOException {
 // location of the model
 String modelPath = pathResourceDirectory + java.io.File.separator
     + Parameters.modelName;
 model = svm.svm_load_model(modelPath);
}

代码示例来源:origin: jzy3d/jzy3d-api

public static svm_model loadModel(String filename) throws IOException{
  return svm.svm_load_model(filename);
}

代码示例来源:origin: openimaj/openimaj

/**
 *     Load an existing svm model.
 *
 *    @param loadModel The model to load from
 *     @throws IOException If the loading does not complete
 */
public void loadModel( final File loadModel ) throws IOException
{
  this.model = svm.svm_load_model( loadModel.getAbsolutePath() );
}

代码示例来源:origin: ClearTK/cleartk

@Override
 protected svm_model loadModel(InputStream inputStream) throws IOException {
  File tmpFile = File.createTempFile("tmp", ".mdl");
  FileOutputStream output = new FileOutputStream(tmpFile);
  try {
   IOUtils.copy(inputStream, output);
   return libsvm.svm.svm_load_model(tmpFile.getPath());
  } finally {
   output.close();
   tmpFile.delete();
  }
 }
}

代码示例来源:origin: org.cleartk/cleartk-ml-libsvm

@Override
 protected svm_model loadModel(InputStream inputStream) throws IOException {
  File tmpFile = File.createTempFile("tmp", ".mdl");
  FileOutputStream output = new FileOutputStream(tmpFile);
  try {
   IOUtils.copy(inputStream, output);
   return libsvm.svm.svm_load_model(tmpFile.getPath());
  } finally {
   output.close();
   tmpFile.delete();
  }
 }
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-libsvm

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
  super.initialize(context);
  
  try {
    model = svm.svm_load_model(new File(tcModelLocation, MODEL_CLASSIFIER).getAbsolutePath());
  } catch (Exception e) {
    throw new ResourceInitializationException(e);
  }
}

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_jsre

public static void run(String in, String mdl, String out) throws IOException
{
  int predict_probability=0;
  
  
  //System.out.println("in:" + in);
  //System.out.println("model:" + mdl);
  //System.out.println("out:" + out);
  
  BufferedReader input = new BufferedReader(new FileReader(in));
  DataOutputStream output = new DataOutputStream(new FileOutputStream(out));
  svm_model model = svm.svm_load_model(mdl);
  predict(input,output,model,predict_probability);
} // end

代码示例来源:origin: dkpro/dkpro-tc

@Override
public void initialize(UimaContext context) throws ResourceInitializationException
{
  super.initialize(context);
  try {
    model = svm
        .svm_load_model(new File(tcModelLocation, MODEL_CLASSIFIER).getAbsolutePath());
  }
  catch (Exception e) {
    throw new ResourceInitializationException(e);
  }
}

代码示例来源:origin: prestosql/presto

public static SvmRegressor deserialize(byte[] modelData)
{
  // TODO do something with the hyperparameters
  try {
    svm_model model = svm.svm_load_model(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(modelData))));
    return new SvmRegressor(model);
  }
  catch (IOException e) {
    throw new UncheckedIOException(e);
  }
}

代码示例来源:origin: org.apache.ctakes/ctakes-coreference

public AbstractClassifier(File fn, int len) {
  try{
    svmCls = svm.svm_load_model(fn.getAbsolutePath());
    int[] labels = new int[2];
    svm.svm_get_labels(svmCls, labels);
    clsIndex = labels[0]==1 ? 0 : 1;
  }catch(IOException e){
    e.printStackTrace();
  }
}

代码示例来源:origin: prestosql/presto

public static SvmClassifier deserialize(byte[] modelData)
{
  // TODO do something with the hyperparameters
  try {
    svm_model model = svm.svm_load_model(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(modelData))));
    return new SvmClassifier(model);
  }
  catch (IOException e) {
    throw new UncheckedIOException(e);
  }
}

代码示例来源:origin: apache/ctakes

public AbstractClassifier(File fn, int len) {
  try{
    svmCls = svm.svm_load_model(fn.getAbsolutePath());
    int[] labels = new int[2];
    svm.svm_get_labels(svmCls, labels);
    clsIndex = labels[0]==1 ? 0 : 1;
  }catch(IOException e){
    e.printStackTrace();
  }
}

代码示例来源:origin: eu.fbk.utils/utils-svm

static Classifier doRead(final Parameters parameters, final Path path) throws IOException {
  // Read the dictionary
  final Dictionary<String> dictionary = Dictionary.readFrom(String.class,
      path.resolve("dictionary"));
  // Read the model
  final String modelString = new String(Files.readAllBytes(path.resolve("model")),
      Charsets.UTF_8);
  final svm_model model = svm
      .svm_load_model(new BufferedReader(new StringReader(modelString)));
  // Compute model hash
  final String modelHash = computeHash(dictionary, modelString);
  // Create and return the SVM
  return new LibSvmClassifier(parameters, modelHash, dictionary, model);
}

代码示例来源:origin: jatecs/jatecs

public IClassifier read(String modelDir) throws IOException {
  String vc = modelDir + Os.pathSeparator() + "validCategories.db";
  DataInputStream valid_os = new DataInputStream(new BufferedInputStream(
      new FileInputStream(vc), 4096));
  valid_os.close();
  String fname = modelDir + Os.pathSeparator() + "0.db";
  SvmRegressionClassifier cl = new SvmRegressionClassifier(
      svm.svm_load_model(fname));
  return cl;
}

代码示例来源:origin: dkpro/dkpro-tc

@Override
public List<String> predict(File data, File model) throws Exception
{
  File predTmp = FileUtil.createTempFile("libsvmPrediction", ".txt");
  predTmp.deleteOnExit();
  try (DataOutputStream output = new DataOutputStream(new FileOutputStream(predTmp));
      BufferedReader input = new BufferedReader(
          new InputStreamReader(new FileInputStream(data), UTF_8))) {
    svm_model svmModel = svm.svm_load_model(model.getAbsolutePath());
    _Prediction predictor = new _Prediction();
    predictor.predict(input, output, svmModel, 0);
  }
  List<String> predictions = FileUtils.readLines(predTmp, UTF_8);
  return predictions;
}

代码示例来源:origin: jatecs/jatecs

public IClassifier read(String modelDir) throws IOException {
  SvmClassifier cl = new SvmClassifier();
  String vc = modelDir + Os.pathSeparator() + "validCategories.db";
  DataInputStream valid_os = new DataInputStream(new BufferedInputStream(
      new FileInputStream(vc), 4096));
  int numCats = valid_os.readInt();
  valid_os.close();
  cl._models = new svm_model[numCats];
  for (short catID = 0; catID < numCats; catID++) {
    String fname = modelDir + Os.pathSeparator() + catID + ".db";
    svm_model model = svm.svm_load_model(fname);
    cl._models[catID] = model;
  }
  return cl;
}

代码示例来源:origin: chungkwong/MathOCR

@Override
public SvmModel read(String fileName) throws IOException{
  return new SvmModel(svm.svm_load_model(fileName),readFeatureList(fileName));
}
private void saveFeatureList(List<String> features,String fileName) throws IOException{

代码示例来源:origin: eu.fbk.utils/utils-svm

private static Classifier trainJava(final Parameters parameters,
    final Iterable<LabelledVector> trainingSet) throws IOException {
  // Prepare the svm_parameter object based on supplied parameters
  final svm_parameter parameter = encodeParameters(parameters);
  // Encode the training set as an svm_problem object, filling a dictionary meanwhile
  final Dictionary<String> dictionary = Dictionary.create();
  final svm_problem problem = encodeProblem(dictionary, trainingSet);
  // Perform training
  final svm_model model = svm.svm_train(problem, parameter);
  // Compute model hash, by saving and reloading SVM model
  final File tmpFile = File.createTempFile("svm", ".bin");
  tmpFile.deleteOnExit();
  svm.svm_save_model(tmpFile.getAbsolutePath(), model);
  final String modelString = com.google.common.io.Files.toString(tmpFile,
      Charset.defaultCharset());
  final String modelHash = computeHash(dictionary, modelString);
  final svm_model reloadedModel = svm
      .svm_load_model(new BufferedReader(new StringReader(modelString)));
  tmpFile.delete();
  // Build and return the SVM object
  return new LibSvmClassifier(parameters, modelHash, dictionary, reloadedModel);
}

相关文章