Skip to content

Commit dfbc4d7

Browse files
rentainhentianhe ren
andauthored
refine criterion and matcher logging (#151)
Co-authored-by: ntianhe ren <[email protected]>
1 parent c0b3582 commit dfbc4d7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

detrex/modeling/criterion/criterion.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,20 @@ def forward(self, outputs, targets, return_indices=False):
245245
return losses, indices_list
246246

247247
return losses
248+
249+
250+
def __repr__(self):
251+
head = "Criterion " + self.__class__.__name__
252+
body = [
253+
"matcher: {}".format(self.matcher.__repr__(_repr_indent=8)),
254+
"losses: {}".format(self.losses),
255+
"loss_class_type: {}".format(self.loss_class_type),
256+
"weight_dict: {}".format(self.weight_dict),
257+
"num_classes: {}".format(self.num_classes),
258+
"eos_coef: {}".format(self.eos_coef),
259+
"focal loss alpha: {}".format(self.alpha),
260+
"focal loss gamma: {}".format(self.gamma),
261+
]
262+
_repr_indent = 4
263+
lines = [head] + [" " * _repr_indent + line for line in body]
264+
return "\n".join(lines)

detrex/modeling/matcher/matcher.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,16 @@ def forward(self, outputs, targets):
149149
(torch.as_tensor(i, dtype=torch.int64), torch.as_tensor(j, dtype=torch.int64))
150150
for i, j in indices
151151
]
152+
153+
def __repr__(self, _repr_indent=4):
154+
head = "Matcher " + self.__class__.__name__
155+
body = [
156+
"cost_class: {}".format(self.cost_class),
157+
"cost_bbox: {}".format(self.cost_bbox),
158+
"cost_giou: {}".format(self.cost_giou),
159+
"cost_class_type: {}".format(self.cost_class_type),
160+
"focal cost alpha: {}".format(self.alpha),
161+
"focal cost gamma: {}".format(self.gamma),
162+
]
163+
lines = [head] + [" " * _repr_indent + line for line in body]
164+
return "\n".join(lines)

0 commit comments

Comments
 (0)