TensorFlow入门教程(十二):利用inception-v3做图像识别

本文介绍了如何利用预训练的inception-v3模型进行图像识别,通过处理imagenet_synset_to_human_label_map.txt和imagenet_2012_challenge_label_map_proto.pbtxt文件建立类别关联,并展示了模型对车辆和狗的识别结果,揭示了模型的预测准确性问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在 inception-v3 中,已经训练出就近千个分类,其标签存在解压目录的 imagenet_synset_to_human_label_map.txt 和 imagenet_2012_challenge_label_map_proto.pbtxt 中,其内容如下:

 

其中 target_class_string 作为连接,将两部分连接起来,所以,程序刚开始,需对这两本文件进行处理,把 target_class 和 目标名称建立联系。程序中,将其封装在一个类里面,具体程序如下:

class NodeLookup(object):
    def __init__(self):
        label_lookup_path = 'inception_model/imagenet_2012_challenge_label_map_proto.pbtxt'
        uid_lookup_path = 'inception_model/imagenet_synset_to_human_label_map.txt'
        self.node_lookup = self.load(label_lookup_path, uid_lookup_path)

    def load(self, label_lookup_path, uid_lookup_path):
        # 加载分类字符串n********对应分类名称的文件
        proto_as_ascii_lines = tf.gfile.GFile(uid_lookup_path).readlines()
        uid_to_human = {}
        # 一行一行读取数据
        for line in proto_as_ascii_lines:
            # 去掉换行符
            line = line.strip('\n')
            # 按照'\t'分割
            parsed_items = line.split('\t')
            # 获取分类编号n********
            uid = parsed_items[0]
            #
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值