

(options, args) = parse.parse_args()

(options, args) = parser.parse_args(argv)

eg:
import sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-f','--file',type=str,default='./image',help='file path of images',dest='file_path')
parser.add_option('--weights','-w',type=str,default='./weights_saved',help="file location of the trained network weights")
parser.add_option('--iterations','-i',type=int,default=10000,help='iteration time of CRNN Net')
parser.add_option('--gpu','-g',type=int,default=0,help="gpu id")
def main(argv):
(options, args) = parser.parse_args()
(options, args) = parser.parse_args(argv) # both OK
print 'file path of images: ' + options.file_path
print "file location of the trained network weights: " + options.weights
print 'iteration time of CRNN Net: ' + str(options.iterations)
print 'gpu id: ' + str(options.gpu)
if __name__ == '__main__':
main(sys.argv)


python test.py -f ../tensorflow/train_image -w ../tensorflow/weights -i 5000 -g 2

这段代码演示了如何在Python中使用optparse模块解析命令行参数。它定义了多个选项,包括文件路径、权重文件位置、迭代次数和GPU ID,并在main函数中打印这些参数的值。通过提供-f、-w、-i和-g标志,可以设置相应的参数。

880

被折叠的 条评论
为什么被折叠?



