当前位置: 首页>>代码示例>>Python>>正文


Python label_map_util.load_labelmap方法代码示例

本文整理汇总了Python中utils.label_map_util.load_labelmap方法的典型用法代码示例。如果您正苦于以下问题:Python label_map_util.load_labelmap方法的具体用法?Python label_map_util.load_labelmap怎么用?Python label_map_util.load_labelmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.label_map_util的用法示例。


在下文中一共展示了label_map_util.load_labelmap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import load_labelmap [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 
开发者ID:GoogleCloudPlatform,项目名称:tensorflow-object-detection-example,代码行数:20,代码来源:app.py

示例2: __init__

# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import load_labelmap [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 
开发者ID:IBM,项目名称:MAX-Object-Detector,代码行数:27,代码来源:model.py

示例3: load_model

# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import load_labelmap [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
    } 
开发者ID:noodlefrenzy,项目名称:easy-tensorflow-multimodel-server,代码行数:40,代码来源:app.py

示例4: __init__

# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import load_labelmap [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) 
开发者ID:GoogleCloudPlatform,项目名称:tensorflow-object-detection-example,代码行数:10,代码来源:app.py

示例5: load_label_dict

# 需要导入模块: from utils import label_map_util [as 别名]
# 或者: from utils.label_map_util import load_labelmap [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 
开发者ID:PacktPublishing,项目名称:Practical-Computer-Vision,代码行数:8,代码来源:06_youtube_ssd_demo.py


注:本文中的utils.label_map_util.load_labelmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。