Python utils.label_map_util.create_category_index() Examples
The following are 5
code examples of utils.label_map_util.create_category_index().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
utils.label_map_util
, or try the search function
.
Example #1
Source File: app.py From tensorflow-object-detection-example with Apache License 2.0 | 6 votes |
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
Example #2
Source File: model.py From MAX-Object-Detector with Apache License 2.0 | 6 votes |
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
Example #3
Source File: app.py From easy-tensorflow-multimodel-server with MIT License | 5 votes |
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 }
Example #4
Source File: app.py From tensorflow-object-detection-example with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: 06_youtube_ssd_demo.py From Practical-Computer-Vision with MIT License | 5 votes |
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