Hello, i try to implement fastRCNN during getting outputs(forward method) several minipackages are formed from one package (picture) and for each you need to find gradients and update weights, there are tensors at the output where each row is a output of the one mini-batch
def forward:
    cnn_out = self.cnn_block(Ximg)
    ###########################
    ###########################  ROI POOL
    scaled_rois = []
    shape_x, shape_y = cnn_out.size(3), cnn_out.size(2)
    for roi_pack in Xroi:
        roi_pack[:, 0], roi_pack[:, 1], roi_pack[:, 2], roi_pack[:, 3] = torch.floor(roi_pack[:, 0]*shape_x),  \
                                                                         torch.floor(roi_pack[:, 1]*shape_y),  \
                                                                         torch.ceil(roi_pack[:, 2]*shape_x)-1, \
                                                                         torch.ceil(roi_pack[:, 3]*shape_y)-1
        scaled_rois.append(roi_pack)

    roi_out = roi_pool(cnn_out, scaled_rois, output_size=self.rois_output_size)
    ###########################
    ###########################
    fc_inp = roi_out.view(1, Xroi[0].size(0), cnn_out.size(1)*self.rois_output_size[0]*self.rois_output_size[1])
    fc_out = self.fc_block(fc_inp)
    ###########################
    classif_out = self.classifier_output(fc_out)
    ###########################
    regress_out = self.regressor_output(fc_out)
    return classif_out, regress_out

update weights (???):
        loss_clf = -torch.log(out_clf+clip_coef)
        loss_reg = labels[0].flatten()*torch.sum(torch.abs(labels[1] - out_reg), 2)
        losses = (loss_clf.flatten() + loss_reg).flatten()

        # backprop
        for loss in losses:
            optimizer.zero_grad()
            loss.backward()
            optimizer.step()

I founded 1 loss for each row in classif_out and regress_out, how update weights for each loss?
Thanks for you attention!