求助大神,刚入手java,最近在做一个jar包,要调用之前写好的python脚本,有一些问题不会。
python脚本中的命令行参数在训练时部分需要不断的修改,用java调用时如何传递给python脚本这些命令行参数?下面是调用我这个python工程的train.py文件的部分命令行参数和写的调用这个train.py的java方法。
parser.add_argument(
'--experiment_root', default='./zcheckpoints', type=common.writeable_directory,
help='Location used to store checkpoints and dumped data.')
parser.add_argument(
'--train_set',default = 'data/mnist_train.csv',
help='Path to the train_set csv file.')
parser.add_argument(
'--image_root', default = '/home/dl/triplet-reid1/data/mnist',type=common.readable_directory,
help='Path that will be pre-pended to the filenames in the train_set csv.')
java调用的函数:
public static void train(String Epath,String Tpath,String Ipath,int batchp,int TI,int DI,int CF){
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("/home/dl/triplet-reid1/train.py");
PyFunction function = (PyFunction)interpreter.get("main");
PyObject pyobject = function.__call__(new PyString(Epath),new PyString(Tpath),new PyString(Ipath),new PyInteger(batchp),new PyInteger(TI),new PyInteger(DI),new PyInteger(CF));
System.out.println(pyobject);
}而且这个call函数的参数还报错。
求大神指教,新手,之前都没接触过java,周围貌似也没人会。