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

栗子1:self.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,这样比较保险 

 

参考链接:argparse.add_argument中的action为‘store_true’使用说明_伊的博客-CSDN博客

相关文章:

  • 2021-04-06
  • 2022-01-02
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2022-01-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-18
  • 1970-01-01
  • 2021-05-07
  • 2022-01-12
  • 2022-03-08
  • 2022-12-23
相关资源
相似解决方案