【发布时间】:2020-04-01 20:25:00
【问题描述】:
我正在使用来自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)
我对解析完全没有经验,因此将不胜感激。
【问题讨论】:
标签: python tensorflow parsing image-recognition