Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to train the model without ground truth masks? #19

Open
arnabkuw opened this issue Jul 22, 2024 · 0 comments
Open

Is it possible to train the model without ground truth masks? #19

arnabkuw opened this issue Jul 22, 2024 · 0 comments

Comments

@arnabkuw
Copy link

I currently have a dataset of 100 real vs 100 fake images, but I do not have the groundtruths. Generating groundtruth for my dataset is quite difficult since the datasets are not aligned. I was wondering if it's possible to just run phase 2 training (detection) for this model, taking a previous localization checkpoint?

It seems the criterion for ec_phase2.py i.e. TruForLossPhase2 still required the gt_masks to calculate detection loss.

class TruForLossPhase2(torch.nn.Module):
    def __init__(self, lambda_det: float = 0.5, ignore_index: int = -1):
        super().__init__()
        self.lambda_det = lambda_det
        self.ignore_index = ignore_index
        self.criterion_detect = torch.nn.BCEWithLogitsLoss()
        self.criterion_conf = torch.nn.MSELoss(reduction='none')

    def forward(self, anomaly: Tensor, gt_mask: Tensor, conf: Tensor, detect: Tensor, label: Tensor) -> Tensor:
        anomaly = torch.softmax(anomaly, dim=1)[:, 1, :, :]
        t = gt_mask * anomaly + (1 - gt_mask) * (1 - anomaly)

        valid = gt_mask != self.ignore_index
        mse = self.criterion_conf(conf.squeeze(1), t)
        Lconf = mse[valid].mean()

        Ldet = self.criterion_detect(detect.squeeze(1), label.to(torch.float32))

        loss = Lconf + Ldet * self.lambda_det

        return loss

Let me know your thoughts. Any help is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant