action='store_true'

关于parser.add_argument()记录一个特殊的情况:action

栗子1self.parser.add_argument('--lr_use', action='store_true', default=False, help='if or not use lr_loss')

当在终端运行的时候,如果不加入--lr_use, 那么程序running的时候,lr_use的值为default: False

如果加上了--lr_use,不需要指定True/False,那么程序running的时候,lr_use的值为True

栗子2:  self.parser.add_argument('--no_flip', action='store_false', help='.....')

当在终端运行的时候,并没有加入--no_flip, 数据集中的图片并不会翻转,打印出来看到no_flip的值为True

Note:有default值的时候,running时不声明就为默认值,

没有的话,如果是store_false,则默认值是True,如果是store_true,则默认值是False

实在记不住搞混的话,可以每次在run之前print出来看一下值是true还是false,这样比较保险


猜你喜欢

转载自blog.csdn.net/lemontree_summer/article/details/80749359