问题
I am using libsvm in java and am experiencing similar issues as described here for python.
I am getting a lot of console output during training and prediction and would like to disable it. Sadly, due to a "Service Temporary Unavaiable" I can't access the website, where it might be described (here). I couldn't find a java related way to disable this warnings (If I did oversee something I apologize)
The Output always looks quite similar to this:
optimization finished, #iter = 10000000 nu = 0.013178458659415372 obj = -11.005078334927212, rho = -2.1799731001804696 nSV = 20, nBSV = 5 Total nSV = 20
Do you know how I can disable this kind of output in java?
Thanks a lot for your help.
回答1:
To disable output programmatically you need to do the following:
svm.svm_set_print_string_function(new libsvm.svm_print_interface(){
@Override public void print(String s) {} // Disables svm output
});
回答2:
At the command line just use the -q option.
$ ./svm-train
Usage: svm-train [options] training_set_file [model_file]
options:
-s svm_type : set type of SVM (default 0)
*** lots of stuff cut out...
-q : quiet mode (no outputs)
If you have your own java trainer, set the print_func for you svm_print_null. (I think the only way to do this is to with the svm_train class is by passing "-q" with your other parameters into the main method).
Hope it helps
回答3:
To disable libsvm output in terminal for Java I use:
import java.io.PrintStream;
import java.io.OutputStream;
System.setOut(new PrintStream(new OutputStream() {
@Override public void write(int b) throws IOException {}
}));
Keep in mind the output to the terminal is disabled, but a logger can be used instead which does output:
import org.apache.log4j.Logger;
private static final Logger LOG = Logger.getLogger(YourClass.class);
Place the log4j.properties file in your resources folder.
The log4j.properties file may look like the following:
#info,debug, error,fatal ...
log4j.rootLogger=debug,stdout
#console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
来源:https://stackoverflow.com/questions/24370987/how-to-disable-the-console-output-in-libsvm-java