當前位置: 首頁>>代碼示例>>Python>>正文


Python label_map_util.create_category_index方法代碼示例

本文整理匯總了Python中utils.label_map_util.create_category_index方法的典型用法代碼示例。如果您正苦於以下問題:Python label_map_util.create_category_index方法的具體用法?Python label_map_util.create_category_index怎麽用?Python label_map_util.create_category_index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在utils.label_map_util的用法示例。


在下文中一共展示了label_map_util.create_category_index方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from utils import label_map_util [as 別名]
# 或者: from utils.label_map_util import create_category_index [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 create_category_index [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 create_category_index [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 create_category_index [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 create_category_index [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.create_category_index方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。