运行fully_connected_feed.py报错问题conflicting option string以及sys.exit(main(sys.argv[:1] + flags_passthrou

我的小程序:

待办计划:卷起来吧,少年!
我们记账:年薪50w够花么?

 

在玩tensorflow时,按照官方教程,用到fully_connected_feed.py这个文件。运行时发生错误:

ArgumentError: argument --positive_data_file: conflicting option string: --positive_data_file

可以定位到是因为以下代码造成的:

    flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
    flags.DEFINE_integer('max_steps', 3000, 'Number of steps to run trainer.')    
    flags.DEFINE_integer('hidden1', 128, 'Number of units in hidden layer 1.')
    flags.DEFINE_integer('hidden2', 32, 'Number of units in hidden layer 2.')
    flags.DEFINE_integer('batch_size', 100, 'Batch size.  '
                     'Must divide evenly into the dataset sizes.')
    flags.DEFINE_string('train_dir', '../material/mnist/', 'Directory to put the training data.')
    flags.DEFINE_boolean('fake_data', False, 'If true, uses fake data '
                     'for unit testing.')

大概意思可以看出是什么重复了的意思,把所有这些定义改成如下的try/except模块就没问题了:

try:
    flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
except:
    print('except')

然后继续运行,控制台输出了如下的内容:

有点奇怪,突然冒出个SystemExit,于是就输入%tb看了下:

其实这是正常输出,并没有异常,因为tf.app.run()函数如下:


"""Generic entry point script."""

from __future__ import absolute_import

from __future__ import division

from __future__ import print_function

import sys

from tensorflow.python.platform import flags

def run(main=None, argv=None):

  """Runs the program with an optional 'main' function and 'argv' list."""

  f = flags.FLAGS

 

  # Extract the args from the optional `argv` list.

  args = argv[1:] if argv else None

 

  # Parse the known flags from that list, or from the command

  # line otherwise.

  # pylint: disable=protected-access

  flags_passthrough = f._parse_flags(args=args)

  # pylint: enable=protected-access

 

  main = main or sys.modules['__main__'].main

 

  # Call the main function, passing through any arguments

  # to the final program.

  sys.exit(main(sys.argv[:1] + flags_passthrough))

代码最后就是调用的sys.exit(main(sys.argv[:1] + flags_passthrough)),于是就退出了。

其实反过来再看打印的正确率的信息,因为代码里设置的最大迭代次数是2000次,而打印信息是每1000次打印一次,正好打印了两次。所以是正常输出啦~/尴尬脸

待办计划:卷起来吧,少年!
我们记账:年薪50w够花么?

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值