sovit-123 / Traffic-Light-Detection-Using-YOLOv3

Traffic light detection using deep learning with the YOLOv3 framework. PyTorch => YOLOv3
GNU General Public License v3.0
59 stars 16 forks source link

RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation. #4

Open abhiagwl4262 opened 2 years ago

abhiagwl4262 commented 2 years ago

https://github.com/sovit-123/Traffic-Light-Detection-Using-YOLOv3/blob/master/models.py#L112-L116 There is an issue with this code which fails with torch=1.8.0

Code need to be updated as follows

            bias_ = module_list[j][0].bias.data  # shape(255,)
            bias = bias_[:modules.no * modules.na].view(modules.na, -1)  # shape(3,85)
            #bias[:, 4] += -4.5  # obj
            bias[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2)  # obj (8 objects per 640 image)
            bias[:, 5:] += math.log(0.6 / (modules.nc - 0.99))  # cls (sigmoid(p) = 1/nc)
            module_list[j][0].bias = torch.nn.Parameter(bias, requires_grad=bias_.requires_grad)