Skip to content

Commit

Permalink
debug in Segmap
Browse files Browse the repository at this point in the history
  • Loading branch information
HanxSmile committed Apr 12, 2023
1 parent 198bcc8 commit 2fbb649
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions dsdl/fields/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,35 @@ def setup(self):

def strict_setup(self):
kwargs = self._raw_dict
keys = list(kwargs.keys())
extra_keys = list(kwargs.keys())
missing_fields = list()
missing_structs = list()
for k in self.namespace.__required__:
if k not in kwargs:
raise FieldNotFoundError(f"Required field {k} is missing.")
setattr(self, k, kwargs[k])
keys.remove(k)
missing_fields.append(k)
else:
setattr(self, k, kwargs[k])
extra_keys.remove(k)
for k in self.namespace.__optional__:
if k in kwargs:
setattr(self, k, kwargs[k])
keys.remove(k)
extra_keys.remove(k)
for k in self.namespace.get_struct_mapping():
if k not in kwargs:
raise FieldNotFoundError(f"Required struct instance {k} is missing.")
setattr(self, k, kwargs[k])
keys.remove(k)

if keys:
raise InterruptError(
f"Not defined keys {keys} found in sample, which is not permitted in strict init mode.")
missing_structs.append(k)
else:
setattr(self, k, kwargs[k])
extra_keys.remove(k)

if extra_keys or missing_structs or missing_fields:
msg = f"Interrupt happens when initial the struct, "
if extra_keys:
msg += f"the keys {extra_keys} in the sample are redundant, please remove them. "
if missing_structs:
msg += f"the required structs {missing_structs} should be defined in the sample. "
if missing_fields:
msg += f"the required fields {missing_fields} should be defined in the sample. "
raise InterruptError(msg)

def __getattr__(self, key):
try:
Expand Down
2 changes: 1 addition & 1 deletion dsdl/geometry/segmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ def visualize(self, image, palette, **kwargs):
color_seg[seg == category_id, :] = np.array(palette[category_name])
overlay = Image_.fromarray(color_seg).convert("RGBA")
overlayed = Image_.blend(image, overlay, 0.5)
LabelList(label_lst).visualize(image=overlayed, palette=palette, bbox={"temp": BBox([0, 0, 0, 0])})
LabelList(label_lst).visualize(image=overlayed, palette=palette, bbox={"temp": BBox([0, 0, 0, 0], mode="xywh")})
return overlayed

0 comments on commit 2fbb649

Please sign in to comment.