【问题标题】:Writing a bash script with file containing tensorflow FLAGS使用包含 tensorflow FLAGS 的文件编写 bash 脚本
【发布时间】:2021-04-25 04:10:20
【问题描述】:

我有一些包含 tensorflow 标志的 tensorflow 代码,如下所示:

from tensorflow.python.platform import flags

FLAGS = flags.FLAGS

## Logging, saving, and testing options
flags.DEFINE_bool('log', True, 'if false, do not log summaries, for debugging code.')
flags.DEFINE_string('logdir', 'trained_mdl/', 'directory for summaries and checkpoints.')
flags.DEFINE_bool('resume', True, 'resume training if there is a model available')
flags.DEFINE_bool('train', False, 'True to train, False to test.')
flags.DEFINE_integer('test_iter', -1, 'iteration to load model (-1 for latest model)')
flags.DEFINE_bool('test_set', True, 'Set to true to test on the the test set, False for the validation set.')
flags.DEFINE_integer('train_update_batch_size', -1, 'number of examples used for gradient update during training (use if you want to test with a different number).')
flags.DEFINE_float('train_update_lr', -1, 'value of inner gradient step step during training. (use if you want to test with a different value)') # 0.1 for omniglot

我想运行几次,为此,我编写了一个 bash 脚本,如下所示:

#!/usr/bin/env bash

  python main.py
  --meta_batch_size 8
  --train True
  --test_set False

  > main1_train.txt

但它重新开始然后永远不会执行。带有张量流标志的 bash 根本不起作用吗?如果是这样,那么我没有其他选择可以使用argparse 而不是FLAGS

更新 1

我收到以下错误:

run_main1.sh: line 5: --meta_batch_size: command not found
run_main1.sh: line 6: --train: command not found
run_main1.sh: line 7: --test_set: command not found

【问题讨论】:

  • 您可以通过shebang#! /bin/bash -x获取更多调试数据。错误输出是什么?
  • @Bayou 不幸的是,bash 窗口在我看到错误之前关闭。它也不会打印到我将输出定向到的输出文件中
  • @Bayou 我已将错误放在更新的问题中

标签: python bash tensorflow


【解决方案1】:

试试:

#!/usr/bin/env bash

python main.py \
    --meta_batch_size 8 \
    --train True \
    --test_set False \
    > main1_train.txt

在 bash 中,换行符就像按下回车键。 “--meta_batch_size 8”被视为一个命令,而是被执行。因此,您必须在行尾使用\ 使其成为脚本的参数。

【讨论】:

  • 你知道如何传递布尔参数吗?答案中的那些没有正确采取
  • 我自己没用过tensorflow。您确定将传入的字符串 False 转换为布尔值吗?见this
猜你喜欢
  • 1970-01-01
  • 2022-12-15
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
  • 1970-01-01
  • 2020-10-13
  • 2013-09-29
  • 2012-06-05
相关资源
最近更新 更多