Summary: map_semantics_on_vertices uses the enumerate counter as the per-vertex instance id instead of the source segGroup["objectId"]. Combined with init-to-INVALID_ID=0, this causes (a) the first valid instance to alias background, and (b) any annotation indexed by the source objectId to point at the wrong object whenever the source segGroups have gaps or any entry was skipped due to label_ndx == INVALID_ID.
Fix: init with -1, write int(instance["objectId"]).
Summary: map_semantics_on_vertices uses the enumerate counter as the per-vertex instance id instead of the source segGroup["objectId"]. Combined with init-to-INVALID_ID=0, this causes (a) the first valid instance to alias background, and (b) any annotation indexed by the source objectId to point at the wrong object whenever the source segGroups have gaps or any entry was skipped due to label_ndx == INVALID_ID.
Fix: init with -1, write int(instance["objectId"]).