SparseR-CNN icon indicating copy to clipboard operation
SparseR-CNN copied to clipboard

how to do Grid and Rondom proposal boxes initialization?

Open liz6688 opened this issue 4 years ago • 5 comments

Thanks for your code. Can you provide the code of Grid and Random initialization method? For example, the specific mean and std paramter of the Gaussian distribution. Thank you very much.

liz6688 avatar Feb 24 '21 12:02 liz6688

        self.init_proposal_boxes = nn.Embedding(self.num_proposals, 4)
        if self.init_type == "img":
            nn.init.constant_(self.init_proposals.weight[:, :2], 0.5)
            nn.init.constant_(self.init_proposals.weight[:, 2:], 1.0)
        elif self.init_type == "center":
            nn.init.constant_(self.init_proposals.weight[:, :2], 0.5)
            nn.init.constant_(self.init_proposals.weight[:, 2:], 0.1)
        elif self.init_type == "grid":
            scale = math.sqrt(1. / self.num_queries)
            steps = int(math.sqrt(self.num_queries)) + 1
            x_range = torch.linspace(0., 1., steps)[:-1] + scale / 2
            y_range = torch.linspace(0., 1., steps)[:-1] + scale / 2
            y_range, x_range = torch.meshgrid(y_range, x_range)
            centers = torch.cat([x_range.reshape(-1, 1), y_range.reshape(-1, 1)], 1)
            nn.init.constant_(self.init_proposals.weight[:, 2:], scale)
            for i in range(self.num_queries):
                nn.init.constant_(self.init_proposals.weight[i, 0], centers[i, 0])
                nn.init.constant_(self.init_proposals.weight[i, 1], centers[i, 1])
        elif self.init_type == "random":
            pass

PeizeSun avatar Feb 25 '21 02:02 PeizeSun

@liz6688 If you find any bug when using different initializations, please remind me, thanks~

PeizeSun avatar Feb 25 '21 02:02 PeizeSun

Got it. Thanks.

liz6688 avatar Feb 25 '21 12:02 liz6688

Hi! Thanks for the code.

When I used the "Random" initialization to do the training, the program reported error "assert (boxes[:, 2:] >= boxes1[:, :2]).all()" for the "generalized_box_iou" function in util/box_ops.py. I suppose the error comes from the situation that the box at some time gets a negative width or height. May I know if the "Random" intialization is responsible for this phenomenon? How could we do the "Random" initialization safety and avoid this problem? Are there any extra constraints needed?

Thank you in advance.

wzic avatar Nov 08 '21 09:11 wzic

How could we do the "Random" initialization safety and avoid this problem? Are there any extra constraints needed?

I followed the way in the above code to random initialize proposal boxes with mmdetection but the loss became very big and cannot train. Have you solved the "Random" initialization problem? :)

luzibuye avatar May 30 '22 09:05 luzibuye