Sharing an easy way to manually change semantic segmentation color label #4615
sy8008
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
What's your question?
I have found an easy way to set semantic segmentation color label, which is useful for getting semantic
segmentation ground truth for network training. Here I will share this method.
Include context on what you are trying to achieve
Generate semantic segmentation ground truth images for training semantic segmentation networks.
Context details
To change the color label of semantic segmentation images, only two things should do.
add the following SegmentationSettings in settings.json:
"SegmentationSettings": {
"InitMethod": "None",
"MeshNamingMethod": "",
"OverrideExisting": true
}
In python scripts, you can use simListSceneObjects() method to get all the objects name in the scene you use, then you can
manually set the color for the objects you are interested in, for example, for setting all the house objects to the same color, using simSetSegmentationObjectID() with regular expression matching:
client.simSetSegmentationObjectID("[\w]house[\w]", 1, True)
Example code
import airsim
client = airsim.VehicleClient()
client.confirmConnection()
objects = client.simListSceneObjects()
for ob in objects:
print(ob)
object_name_list = ["road","building","Landscape","Sky","car","building","vegetation","grass","house","tree","Door","wall"]
print("Reset all object id")
found = client.simSetSegmentationObjectID("[\w]*", 0, True)
print("all object: %r" % (found))
time.sleep(1)
for idx,obj_name in enumerate(object_name_list):
obj_name_reg = r"[\w]" + obj_name + r"[\w]"
found = client.simSetSegmentationObjectID(obj_name_reg, (idx + 1) % 256, True)
print("%s: %r" % (obj_name, found))
Beta Was this translation helpful? Give feedback.
All reactions