我正在使用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',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)
我完全没有解析经验,因此将不胜感激。