Unverified Commit e2573a71 authored by F-G Fernandez's avatar F-G Fernandez Committed by GitHub
Browse files

Added __repr__ attribute to GeneralizedRCNNTransform (#1834)

* feat: Added __repr__ attribute to GeneralizedRCNNTransform

Added more details to default __repr__ attribute for printing.

* fix: Put back relative imports

* style: Fixed pep8 compliance

Switched strings with  syntax to f-strings.

* test: Added test for GeneralizedRCNNTransform __repr__

Checked integrity of __repr__ attribute

* test: Fixed unittest for __repr__

Fixed the formatted strings in the __repr__ integrity check for GeneralizedRCNNTransform

* fix: Fixed f-strings for earlier python versions

Switched back f-strings to .format syntax for Python3.5 compatibility.

* fix: Fixed multi-line string

Fixed multiple-line string syntax for compatibility

* fix: Fixed GeneralizedRCNNTransform unittest

Fixed formatting of min_size argument of the resizing part
parent 2ca3279c
...@@ -248,6 +248,25 @@ class ModelTester(TestCase): ...@@ -248,6 +248,25 @@ class ModelTester(TestCase):
self.assertTrue("scores" in out_cpu[0]) self.assertTrue("scores" in out_cpu[0])
self.assertTrue("labels" in out_cpu[0]) self.assertTrue("labels" in out_cpu[0])
def test_generalizedrcnn_transform_repr(self):
min_size, max_size = 224, 299
image_mean = [0.485, 0.456, 0.406]
image_std = [0.229, 0.224, 0.225]
t = models.detection.transform.GeneralizedRCNNTransform(min_size=min_size,
max_size=max_size,
image_mean=image_mean,
image_std=image_std)
# Check integrity of object __repr__ attribute
expected_string = 'GeneralizedRCNNTransform('
_indent = '\n '
expected_string += '{0}Normalize(mean={1}, std={2})'.format(_indent, image_mean, image_std)
expected_string += '{0}Resize(min_size=({1},), max_size={2}, '.format(_indent, min_size, max_size)
expected_string += "mode='bilinear')\n)"
self.assertEqual(t.__repr__(), expected_string)
for model_name in get_available_classification_models(): for model_name in get_available_classification_models():
# for-loop bodies don't define scopes, so we have to save the variables # for-loop bodies don't define scopes, so we have to save the variables
......
...@@ -181,6 +181,15 @@ class GeneralizedRCNNTransform(nn.Module): ...@@ -181,6 +181,15 @@ class GeneralizedRCNNTransform(nn.Module):
result[i]["keypoints"] = keypoints result[i]["keypoints"] = keypoints
return result return result
def __repr__(self):
format_string = self.__class__.__name__ + '('
_indent = '\n '
format_string += "{0}Normalize(mean={1}, std={2})".format(_indent, self.image_mean, self.image_std)
format_string += "{0}Resize(min_size={1}, max_size={2}, mode='bilinear')".format(_indent, self.min_size,
self.max_size)
format_string += '\n)'
return format_string
def resize_keypoints(keypoints, original_size, new_size): def resize_keypoints(keypoints, original_size, new_size):
# type: (Tensor, List[int], List[int]) # type: (Tensor, List[int], List[int])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment