Skip to content

Commit 1357304

Browse files
anandoleetflite-support-robot
authored andcommitted
Set dtype for numpy binding on protobuf repeated float field to prevent breaks by protobuf numpy change.
PiperOrigin-RevId: 832129663
1 parent 2fc3e0d commit 1357304

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

tensorflow_lite_support/python/task/processor/proto/segmentations_pb2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def to_pb2(self) -> _ConfidenceMaskProto:
5757
def create_from_pb2(cls, pb2_obj: _ConfidenceMaskProto, height: int,
5858
width: int) -> "ConfidenceMask":
5959
"""Creates a `ConfidenceMask` object from the given protobuf and size."""
60-
return ConfidenceMask(value=np.array(pb2_obj.value).reshape(height, width))
60+
return ConfidenceMask(
61+
value=np.array(pb2_obj.value, np.float32).reshape(height, width)
62+
)
6163

6264
def __eq__(self, other: Any) -> bool:
6365
"""Checks if this object is equal to the given object.

tensorflow_lite_support/python/test/task/vision/image_segmenter_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_segmentation_confidence_mask_matches_category_mask(self):
224224
[confidence_mask.value for confidence_mask in confidence_masks])
225225

226226
# Check if data type of `confidence_masks` are correct.
227-
self.assertEqual(confidence_mask_array.dtype, float)
227+
self.assertEqual(confidence_mask_array.dtype, np.float32)
228228

229229
# Compute the category mask from the created confidence mask.
230230
calculated_category_mask = np.argmax(confidence_mask_array, axis=0)

0 commit comments

Comments
 (0)