| | |
| | |
| | |
| | |
| |
|
| | from collections import namedtuple |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | |
| | Label = namedtuple( 'Label' , [ |
| |
|
| | 'name' , |
| | |
| |
|
| | 'id' , |
| | |
| | |
| | |
| |
|
| | 'trainId' , |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | 'category' , |
| |
|
| | 'categoryId' , |
| | |
| |
|
| | 'hasInstances', |
| |
|
| | 'ignoreInEval', |
| | |
| |
|
| | 'color' , |
| | ] ) |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | labels = [ |
| | |
| | Label( 'unlabeled' , 0 , 0 , False , True , ( 0, 0, 0) ), |
| | Label( 'ego vehicle' , 0 , 0 , False , True , ( 0, 0, 0) ), |
| | Label( 'rectification border' , 0 , 0 , False , True , ( 0, 0, 0) ), |
| | Label( 'out of roi' , 0 , 0 , False , True , ( 0, 0, 0) ), |
| | Label( 'background' , 0 , 0 , False , False , ( 0, 0, 0) ), |
| | Label( 'free' , 1 , 1 , False , False , (128, 64,128) ), |
| | Label( '01' , 2 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '02' , 3 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '03' , 4 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '04' , 5 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '05' , 6 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '06' , 7 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '07' , 8 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '08' , 9 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '09' , 10 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '10' , 11 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '11' , 12 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '12' , 13 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '13' , 14 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '14' , 15 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '15' , 16 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '16' , 17 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '17' , 18 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '18' , 19 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '19' , 20 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '20' , 21 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '21' , 22 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '22' , 23 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '23' , 24 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '24' , 25 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '25' , 26 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '26' , 27 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '27' , 28 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '28' , 29 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '29' , 30 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '30' , 31 , 0 , True , False , ( 0, 0, 0) ), |
| | Label( '31' , 32 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '32' , 33 , 0 , True , False , ( 0, 0, 0) ), |
| | Label( '33' , 34 , 0 , True , False , ( 0, 0, 0) ), |
| | Label( '34' , 35 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '35' , 36 , 0 , True , False , ( 0, 0, 0) ), |
| | Label( '36' , 37 , 0 , True , False , ( 0, 0, 0) ), |
| | Label( '37' , 38 , 0 , True , False , ( 0, 0, 0) ), |
| | Label( '38' , 39 , 0 , True , False , ( 0, 0, 0) ), |
| | Label( '39' , 40 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '40' , 41 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '41' , 42 , 2 , True , False , ( 0, 0,142) ), |
| | Label( '42' , 43 , 2 , True , False , ( 0, 0,142) ), |
| |
|
| | ] |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | name2label = { label.name : label for label in labels } |
| | id2label = { label.id : label for label in labels } |
| | trainId2label = { label.trainId : label for label in reversed(labels) } |
| | category2labels = {} |
| | for label in labels: |
| | category = label.category |
| | if category in category2labels: |
| | category2labels[category].append(label) |
| | else: |
| | category2labels[category] = [label] |
| |
|
| | |
| | |
| | |
| |
|
| | def assureSingleInstanceName( name ): |
| | |
| | if name in name2label: |
| | return name |
| | |
| | if not name.endswith("group"): |
| | return name |
| | |
| | name = name[:-len("group")] |
| | |
| | if not name in name2label: |
| | return None |
| | |
| | if not name2label[name].hasInstances: |
| | return None |
| | |
| | return name |
| |
|
| | |
| | |
| | |
| |
|
| | if __name__ == "__main__": |
| | |
| | print "List of cityscapes labels:" |
| | print |
| | print " {:>13} | {:>3} | {:>7} | {:>14} | {:>7} | {:>12} | {:>12}".format( 'name', 'id', 'trainId', 'category', 'categoryId', 'hasInstances', 'ignoreInEval' ) |
| | print " " + ('-' * 88) |
| | for label in labels: |
| | print " {:>13} | {:>3} | {:>7} | {:>14} | {:>7} | {:>12} | {:>12}".format( label.name, label.id, label.trainId, label.category, label.categoryId, label.hasInstances, label.ignoreInEval ) |
| | print |
| |
|
| | print "Example usages:" |
| |
|
| | |
| | name = 'car' |
| | id = name2label[name].id |
| | print "ID of label '{name}': {id}".format( name=name, id=id ) |
| |
|
| | |
| | category = id2label[id].category |
| | print "Category of label with ID '{id}': {category}".format( id=id, category=category ) |
| |
|
| | |
| | trainId = 0 |
| | name = trainId2label[trainId].name |
| | print "Name of label with trainID '{id}': {name}".format( id=trainId, name=name ) |
| |
|
| | |
| | print "Labels for train IDs: ", trainId2label.keys() |
| | print " ", |
| | for trainId in trainId2label: |
| | print trainId2label[trainId].name + "," , |
| | print |
| |
|