Skip to content

Commit

Permalink
add: fair pseudo label creator
Browse files Browse the repository at this point in the history
  • Loading branch information
mjq2020 authored and LynnL4 committed Nov 24, 2023
1 parent f373e3c commit 1ce4e0e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions sscma/models/semi/fairpseudolabel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import torch
from mmdet.structures.det_data_sample import SampleList
from mmengine.structures.instance_data import InstanceData
from sscma.models.detectors.base import BasePseudoLabelCreator
from sscma.registry import MODELS


@MODELS.register_module()
class FairPseudoLabel(BasePseudoLabelCreator):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

self.cls_thr = None
self.cls_thr_ig = None

def generate_pseudo_labels_online(
self,
teach_pred,
student_sample: SampleList,
):
if self.cls_thr is not None and self.cls_thr_ig is not None:
for idx_sample, pred in enumerate(teach_pred):
pseudo_bboxs, pseudo_label = [], []
pseudo_bboxs_ig, pseudo_label_ig = [], []
gt = InstanceData()
ignore = InstanceData()
for idx, label in enumerate(pred.pred_instances.labels):
if pred.pred_instances.scores[idx] > self.cls_thr[int(label)]:
pseudo_bboxs.append(pred.pred_instances.bboxes[idx])
pseudo_label.append(label)
elif pred.pred_instances.scores[idx] > self.cls_thr_ig[int(label)]:
pseudo_bboxs_ig.append(pred.pred_instances.bboxes[idx])
pseudo_label_ig.append(label)
if len(pseudo_bboxs):
gt.bboxes = torch.concat([i.unsqueeze(0) for i in pseudo_bboxs], dim=0)
gt.labels = torch.concat([i.unsqueeze(0) for i in pseudo_label], dim=0)
if len(pseudo_bboxs_ig):
ignore.labels = torch.concat([i.unsqueeze(0) for i in pseudo_label_ig], dim=0)
ignore.bboxes = torch.concat([i.unsqueeze(0) for i in pseudo_bboxs_ig], dim=0)
student_sample[idx_sample].gt_instannces = gt
student_sample[idx_sample].ignored_instances = ignore

0 comments on commit 1ce4e0e

Please sign in to comment.