Skip to content

Commit e7c9280

Browse files
committed
fixed segmentation and added more feature tests
1 parent 3a392bc commit e7c9280

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

hub/schema/segmentation.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ def get_attr_dict(self):
6363
def __str__(self):
6464
out = super().__str__()
6565
out = "Segmentation" + out[6:-1]
66-
out = out + ", names=" + self.names if self.names is not None else out
6766
out = (
68-
out + ", num_classes=" + self.num_classes
69-
if self.num_classes is not None
67+
out + ", names=" + str(self.class_labels._names)
68+
if self.class_labels._names is not None
69+
else out
70+
)
71+
out = (
72+
out + ", num_classes=" + str(self.class_labels._num_classes)
73+
if self.class_labels._num_classes is not None
7074
else out
7175
)
7276
out += ")"

hub/schema/tests/test_features.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from hub.schema import Segmentation
12
from hub.schema.class_label import ClassLabel, _load_names_from_file
23
from hub.schema.features import HubSchema, SchemaDict
34
import pytest
@@ -49,9 +50,31 @@ def test_feature_dict_repr():
4950
assert expected_output == feature_dict_object.__repr__()
5051

5152

53+
def test_segmentation_repr():
54+
seg1 = Segmentation(shape=(3008, 3008), dtype="uint8", num_classes=5)
55+
seg2 = Segmentation(shape=(3008, 3008), dtype="uint8", names=["apple", "orange", "banana"])
56+
57+
text1 = "Segmentation(shape=(3008, 3008), dtype='uint8', num_classes=5)"
58+
text2 = "Segmentation(shape=(3008, 3008), dtype='uint8', names=['apple', 'orange', 'banana'], num_classes=3)"
59+
assert seg1.__repr__() == text1
60+
assert seg2.__repr__() == text2
61+
62+
63+
def test_classlabel_repr():
64+
cl1 = ClassLabel(num_classes=5)
65+
cl2 = ClassLabel(names=["apple", "orange", "banana"])
66+
67+
text1 = "ClassLabel(shape=(), dtype='int64', num_classes=5)"
68+
text2 = "ClassLabel(shape=(), dtype='int64', names=['apple', 'orange', 'banana'], num_classes=3)"
69+
assert cl1.__repr__() == text1
70+
assert cl2.__repr__() == text2
71+
72+
5273
if __name__ == "__main__":
5374
test_load_names_from_file()
5475
test_class_label()
5576
test_hub_feature_flatten()
5677
test_feature_dict_str()
5778
test_feature_dict_repr()
79+
test_classlabel_repr()
80+
test_segmentation_repr()

0 commit comments

Comments
 (0)