不使用命令行训练 Tensorflow 模型

Train Tensorflow model without using command line

我想从另一个 Python 脚本调用 this main(_) function,而不生成新进程(这样更容易调试)。但是,该函数是为使用命令行参数而编写的。直接从另一个函数调用该函数的最简洁方法是什么?

您可以导入 FLAGS,然后定义所需的参数(train_data、eval_data、save_path)。

In [13]: from tensorflow.models.embedding.word2vec_optimized import FLAGS
In [14]: from tensorflow.models.embedding.word2vec_optimized import main
In [16]: main(_)
--train_data --eval_data and --save_path must be specified.
An exception has occurred, use %tb to see the full traceback.
In [17]: FLAGS.train_data = "this"
In [18]: FLAGS.eval_data = "that"
In [19]: FLAGS.save_path = "some_path"
In [20]: main(_)
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 8