本文整理汇总了Python中utils.label_map_util.convert_label_map_to_categories方法的典型用法代码示例。如果您正苦于以下问题:Python label_map_util.convert_label_map_to_categories方法的具体用法?Python label_map_util.convert_label_map_to_categories怎么用?Python label_map_util.convert_label_map_to_categories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.label_map_util
的用法示例。
在下文中一共展示了label_map_util.convert_label_map_to_categories方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import convert_label_map_to_categories [as 别名]
def __init__(self):
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(
label_map, max_num_classes=90, use_display_name=True)
self.category_index = label_map_util.create_category_index(categories)
model_url = MODEL_URL
base_url = os.path.dirname(model_url)+"/"
model_file = os.path.basename(model_url)
model_name = os.path.splitext(os.path.splitext(model_file)[0])[0]
model_dir = tf.keras.utils.get_file(
fname=model_name, origin=base_url + model_file, untar=True)
model_dir = pathlib.Path(model_dir)/"saved_model"
model = tf.saved_model.load(str(model_dir))
model = model.signatures['serving_default']
self.model = model
示例2: __init__
# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import convert_label_map_to_categories [as 别名]
def __init__(self, model_file=PATH_TO_CKPT, label_file=PATH_TO_LABELS):
logger.info('Loading model from: {}...'.format(model_file))
detection_graph = tf.Graph()
graph = tf.Graph()
with tf.Session(graph=detection_graph):
# load the graph ===
# loading a (frozen) TensorFlow model into memory
with graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(model_file, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
# loading a label map
label_map = label_map_util.load_labelmap(label_file)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES,
use_display_name=True)
category_index = label_map_util.create_category_index(categories)
# set up instance variables
self.graph = graph
self.category_index = category_index
self.categories = categories
示例3: load_model
# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import convert_label_map_to_categories [as 别名]
def load_model(model_dir, model_prefix):
label_map = label_map_util.load_labelmap('{}/{}{}'.format(model_dir, model_prefix, LABEL_MAP_SUFFIX))
categories = label_map_util.convert_label_map_to_categories(
label_map, max_num_classes=90, use_display_name=True)
category_index = label_map_util.create_category_index(categories)
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile('{}/{}{}'.format(model_dir, model_prefix, MODEL_SUFFIX), 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
# Get handles to input and output tensors
ops = tf.get_default_graph().get_operations()
all_tensor_names = {
output.name
for op in ops for output in op.outputs
}
tensor_dict = {}
for key in [
'num_detections', 'detection_boxes', 'detection_scores',
'detection_classes'
]:
tensor_name = key + ':0'
if tensor_name in all_tensor_names:
tensor_dict[key] = tf.get_default_graph(
).get_tensor_by_name(tensor_name)
image_tensor = tf.get_default_graph().get_tensor_by_name(
'image_tensor:0')
sess = tf.Session(graph=detection_graph)
return {
'session': sess,
'image_tensor': image_tensor,
'tensor_dict': tensor_dict,
'category_index': category_index
}
示例4: __init__
# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import convert_label_map_to_categories [as 别名]
def __init__(self):
self.detection_graph = self._build_graph()
self.sess = tf.Session(graph=self.detection_graph)
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(
label_map, max_num_classes=90, use_display_name=True)
self.category_index = label_map_util.create_category_index(categories)
示例5: load_label_dict
# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import convert_label_map_to_categories [as 别名]
def load_label_dict(PATH_TO_LABELS):
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)
#print(category_index)
return category_index