{"id":265328,"date":"2023-04-01T08:55:33","date_gmt":"2023-04-01T00:55:33","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=265328"},"modified":"2023-02-25T20:56:23","modified_gmt":"2023-02-25T12:56:23","slug":"tensorflow-linux-flags","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/tensorflow-linux-flags.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdTensorFlow\u4e2d\u5173\u4e8etf.app.flags\u547d\u4ee4\u884c\u53c2\u6570\u89e3\u6790\u6a21\u5757"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86TensorFlow\u4e2d\u5173\u4e8etf.app.flags\u547d\u4ee4\u884c\u53c2\u6570\u89e3\u6790\u6a21\u5757\uff0c\u5177\u6709\u5f88\u597d\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002\u5982\u6709\u9519\u8bef\u6216\u672a\u8003\u8651\u5b8c\u5168\u7684\u5730\u65b9\uff0c\u671b\u4e0d\u541d\u8d50\u6559<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n tf.app.flags\u547d\u4ee4\u884c\u53c2\u6570\u89e3\u6790\u6a21\u5757<\/strong><\/div>\n \u8bf4\u9053\u547d\u4ee4\u884c\u53c2\u6570\u89e3\u6790\uff0c\u5c31\u4e0d\u5f97\u4e0d\u63d0\u5230 python \u7684 argparse \u6a21\u5757\uff0c\u8be6\u60c5\u53ef\u53c2\u8003\u6211\u4e4b\u524d\u7684\u4e00\u7bc7\u6587\u7ae0\uff1apython argparse \u6a21\u5757\u547d\u4ee4\u884c\u53c2\u6570\u7528\u6cd5\u53ca\u8bf4\u660e\u3002<\/p>\n \u5728\u9605\u8bfb\u76f8\u5173\u5de5\u7a0b\u7684\u6e90\u7801\u65f6\uff0c\u5f88\u5bb9\u6613\u53d1\u73b0 tf.app.flags \u6a21\u5757\u7684\u8eab\u5f71\u3002\u5176\u4f5c\u7528\u4e0e python \u7684 argparse \u7c7b\u4f3c\u3002<\/p>\n \u76f4\u63a5\u4e0a\u4ee3\u7801\u5b9e\u4f8b\uff0c\u65b0\u5efa\u4e00\u4e2a\u540d\u4e3a test_flags.py \u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n #coding:utf-8\r\nimport tensorflow as tf\r\n \r\nFLAGS = tf.app.flags.FLAGS\r\n# tf.app.flags.DEFINE_string(\"param_name\", \"default_val\", \"description\")\r\ntf.app.flags.DEFINE_string(\"train_data_path\", \"\/home\/feige\", \"training data dir\")\r\ntf.app.flags.DEFINE_string(\"log_dir\", \".\/logs\", \" the log dir\")\r\ntf.app.flags.DEFINE_integer(\"train_batch_size\", 128, \"batch size of train data\")\r\ntf.app.flags.DEFINE_integer(\"test_batch_size\", 64, \"batch size of test data\")\r\ntf.app.flags.DEFINE_float(\"learning_rate\", 0.001, \"learning rate\")\r\n \r\ndef main(unused_argv):\r\n train_data_path = FLAGS.train_data_path\r\n print(\"train_data_path\", train_data_path)\r\n train_batch_size = FLAGS.train_batch_size\r\n print(\"train_batch_size\", train_batch_size)\r\n test_batch_size = FLAGS.test_batch_size\r\n print(\"test_batch_size\", test_batch_size)\r\n size_sum = tf.add(train_batch_size, test_batch_size)\r\n with tf.Session() as sess:\r\n sum_result = sess.run(size_sum)\r\n print(\"sum_result\", sum_result)\r\n \r\n# \u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u4fdd\u8bc1\u4e86\uff0c\u5982\u679c\u6b64\u6587\u4ef6\u88ab\u5176\u4ed6\u6587\u4ef6 import\u7684\u65f6\u5019\uff0c\u4e0d\u4f1a\u6267\u884cmain \u51fd\u6570\r\nif __name__ == '__main__':\r\n tf.app.run() # \u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u8c03\u7528main \u51fd\u6570 main(sys.argv)<\/pre>\n |