Skip to content

Evaluation / Testing Step for COCO Object detection #20389

@shanalikhan

Description

@shanalikhan

Outline & Motivation

I've written the code from the link

import numpy as np

class CocoDNN(L.LightningModule):
    def __init__(self):
        super().__init__()
        self.model = models.detection.fasterrcnn_mobilenet_v3_large_fpn(weights="DEFAULT")

    def forward(self, images, targets=None):
        return self.model(images, targets)

    def training_step(self, batch, batch_idx):
        imgs, annot = batch
        #print(f"Batch :{batch_idx}")

        batch_losses = []
        for img_b, annot_b in zip(imgs, annot):
            #print(len(img_b), len(annot_b))
            if len(img_b) == 0:
                continue
            loss_dict = self.model(img_b, annot_b)
            losses = sum(loss for loss in loss_dict.values())
            #print(losses)
            batch_losses.append(losses)

        batch_mean  = torch.mean(torch.stack(batch_losses))
        #print(batch_mean)
        self.log('train_loss', batch_mean)

        #print(imgs[0])
        #print(' ----',annot)
        #loss_dict = self.model(img_b, annot_b)
        #losses = sum(loss for loss in loss_dict.values())
        #self.log('train_loss', losses)
        return batch_mean

    def configure_optimizers(self):
        return optim.SGD(self.parameters(), lr=0.001, momentum=0.9, weight_decay=0.0005)

I want to evaluate it using evaluation_step and testing_step. Can you guide me the code refactor do that

Images are 512x512 and coco format.

Pitch

No response

Additional context

No response

cc @justusschock @awaelchli

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions