在 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]
#