我正在使用https://github.com/tensorflow/models/blob/master/tutorials/image/imagenet/classify_image.py中的教程imagenet图像识别代码>
到目前为止,我已经设法使所有功能正常运行,但是我想知道如何在末尾将参数作为列表或字符串而不是解析后的参数,因此我可以在命令中使用常规的if。
def main(_): maybe_download_and_extract() image = (FLAGS.image_file if FLAGS.image_file else os.path.join(FLAGS.model_dir, 'cropped_panda.jpg')) run_inference_on_image(image) if __name__ == '__main__': parser = argparse.ArgumentParser() # classify_image_graph_def.pb: # Binary representation of the GraphDef protocol buffer. # imagenet_synset_to_human_label_map.txt: # Map from synset ID to a human readable string. # imagenet_2012_challenge_label_map_proto.pbtxt: # Text representation of a protocol buffer mapping a label to synset ID. parser.add_argument( '--model_dir', type=str, default='/tmp/imagenet', help="""\ Path to classify_image_graph_def.pb, imagenet_synset_to_human_label_map.txt, and imagenet_2012_challenge_label_map_proto.pbtxt.\ """ ) parser.add_argument( '--image_file', type=str, default='', help='Absolute path to image file.' ) parser.add_argument( '--num_top_predictions', type=int, default=5, help='Display this many predictions.' ) #how do i get a variable that i can interact with from this: FLAGS, unparsed = parser.parse_known_args() tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
任何帮助将不胜感激。
我正在使用来自https://github.com/tensorflow/models/blob/master/tutorials/image/imagenet/classify_image.py的教程imagenet图像识别代码,我已经设法使所有工作正常进行...] >
您可以使用vars
获得参数的字典视图。
来自argparse文档(https://docs.python.org/3/library/argparse.html)的示例: