Python object_detection.utils.label_map_util.get_label_map_dict() Examples
The following are 30
code examples of object_detection.utils.label_map_util.get_label_map_dict().
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
object_detection.utils.label_map_util
, or try the search function
.
Example #1
Source File: label_map_util_test.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def test_load_label_map_with_background(self): label_map_string = """ item { id:0 name:'background' } item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['background'], 0) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #2
Source File: label_map_util_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #3
Source File: label_map_util_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def test_load_label_map_with_background(self): label_map_string = """ item { id:0 name:'background' } item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['background'], 0) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #4
Source File: label_map_util_test.py From HereIsWally with MIT License | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #5
Source File: label_map_util_test.py From yolo_v2 with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #6
Source File: label_map_util_test.py From yolo_v2 with Apache License 2.0 | 6 votes |
def test_get_label_map_dict_display(self): label_map_string = """ item { id:2 display_name:'cat' } item { id:1 display_name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, use_display_name=True) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #7
Source File: label_map_util_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #8
Source File: label_map_util_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def test_get_label_map_dict_display(self): label_map_string = """ item { id:2 display_name:'cat' } item { id:1 display_name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, use_display_name=True) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #9
Source File: label_map_util_test.py From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #10
Source File: label_map_util_test.py From tensorflow with BSD 2-Clause "Simplified" License | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #11
Source File: label_map_util_test.py From Gun-Detector with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #12
Source File: label_map_util_test.py From Gun-Detector with Apache License 2.0 | 6 votes |
def test_get_label_map_dict_display(self): label_map_string = """ item { id:2 display_name:'cat' } item { id:1 display_name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, use_display_name=True) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #13
Source File: label_map_util_test.py From Gun-Detector with Apache License 2.0 | 6 votes |
def test_load_label_map_with_background(self): label_map_string = """ item { id:0 name:'background' } item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['background'], 0) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #14
Source File: label_map_util_test.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #15
Source File: label_map_util_test.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def test_get_label_map_dict_display(self): label_map_string = """ item { id:2 display_name:'cat' } item { id:1 display_name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, use_display_name=True) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #16
Source File: label_map_util_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #17
Source File: label_map_util_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #18
Source File: label_map_util_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 6 votes |
def test_get_label_map_dict_display(self): label_map_string = """ item { id:2 display_name:'cat' } item { id:1 display_name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, use_display_name=True) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #19
Source File: label_map_util_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 6 votes |
def test_load_label_map_with_background(self): label_map_string = """ item { id:0 name:'background' } item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['background'], 0) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #20
Source File: label_map_util_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 6 votes |
def test_get_label_map_dict_with_fill_in_gaps_and_background(self): label_map_string = """ item { id:3 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, fill_in_gaps_and_background=True) self.assertEqual(label_map_dict['background'], 0) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['class_2'], 2) self.assertEqual(label_map_dict['cat'], 3) self.assertEqual(len(label_map_dict), max(label_map_dict.values()) + 1)
Example #21
Source File: build2_tf_record.py From train_ssd_mobilenet with MIT License | 6 votes |
def main(): if not mkdir(TFRECORD_DIR): return label_map_dict = label_map_util.get_label_map_dict(LABEL_MAP_FILE) logging.info('Reading from dataset.') # shuffle random.seed(42) random.shuffle(trainval_list) num_trainval = len(trainval_list) num_train = int(0.7 * num_trainval) train = trainval_list[:num_train] val = trainval_list[num_train:] logging.info('%d training and %d validation examples.', len(train), len(val)) # create train.record create_tf_record(TRAIN_RECORD_FILE, label_map_dict, train) # create val.record create_tf_record(VAL_RECORD_FILE, label_map_dict, val)
Example #22
Source File: label_map_util_test.py From moveo_ros with MIT License | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #23
Source File: label_map_util_test.py From hands-detection with MIT License | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #24
Source File: create_mask_rcnn_tf_record_cv.py From Custom-Mask-RCNN-Using-Tensorfow-Object-Detection-API with MIT License | 6 votes |
def main(_): data_dir = FLAGS.data_dir train_output_path = FLAGS.output_dir image_dir = os.path.join(data_dir, FLAGS.image_dir) annotations_dir = os.path.join(data_dir, FLAGS.annotations_dir) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) logging.info('Reading from dataset.') examples_list = os.listdir(image_dir) for el in examples_list: if el[-3:] !='jpg': del examples_list[examples_list.index(el)] for el in examples_list: examples_list[examples_list.index(el)] = el[0:-4] create_tf_record(train_output_path, FLAGS.num_shards, label_map_dict, annotations_dir, image_dir, examples_list)
Example #25
Source File: create_mask_rcnn_tf_record.py From Custom-Mask-RCNN-Using-Tensorfow-Object-Detection-API with MIT License | 6 votes |
def main(_): # force to pass bboxes_provided flag if FLAGS.bboxes_provided == None: print("ERROR: Please set bboxes_provided flag to True or False") print("INFO: use xmls flag helps the program know if xmls file bounding boxes annotations is provided or not") sys.exit() # read label mapping print('INFO: Reading label mapping') label_map_dict_path = os.path.join(FLAGS.data_dir_path, 'label.pbtxt') label_map_dict_temp = label_map_util.get_label_map_dict( label_map_dict_path) label_map_dict = label_map_dict_temp.copy() for key in label_map_dict_temp.keys(): label_map_dict[key] = [label_map_dict_temp[key], key[-3:]] label_map_dict[key[:-3]] = label_map_dict.pop(key) print("INFO: Label mapping: {a}".format(a=label_map_dict)) # create tfrecord of data create_tf_record(label_map_dict, FLAGS.images_dir, FLAGS.masks_dir, FLAGS.bboxes_dir, FLAGS.tfrecord_filename)
Example #26
Source File: label_map_util_test.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #27
Source File: label_map_util_test.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def test_get_label_map_dict_display(self): label_map_string = """ item { id:2 display_name:'cat' } item { id:1 display_name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, use_display_name=True) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #28
Source File: label_map_util_test.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def test_load_label_map_with_background(self): label_map_string = """ item { id:0 name:'background' } item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['background'], 0) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)
Example #29
Source File: label_map_util_test.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def test_get_label_map_dict_with_fill_in_gaps_and_background(self): label_map_string = """ item { id:3 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict( label_map_path, fill_in_gaps_and_background=True) self.assertEqual(label_map_dict['background'], 0) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['2'], 2) self.assertEqual(label_map_dict['cat'], 3) self.assertEqual(len(label_map_dict), max(label_map_dict.values()) + 1)
Example #30
Source File: label_map_util_test.py From object_detection_kitti with Apache License 2.0 | 6 votes |
def test_get_label_map_dict(self): label_map_string = """ item { id:2 name:'cat' } item { id:1 name:'dog' } """ label_map_path = os.path.join(self.get_temp_dir(), 'label_map.pbtxt') with tf.gfile.Open(label_map_path, 'wb') as f: f.write(label_map_string) label_map_dict = label_map_util.get_label_map_dict(label_map_path) self.assertEqual(label_map_dict['dog'], 1) self.assertEqual(label_map_dict['cat'], 2)