![]() ![]() Pbox = torch.cat ((pxy, pwh ), 1 ) # predicted box Ps = pi # prediction subset corresponding to targets # Regression Tobj = torch.zeros_like (pi, device =device ) # target obj Tcls, tbox, indices, anchors = self.build_targets (p, targets ) # targets # Losses for i, pi in enumerate (p ): # layer index, layer predictionsī, a, gj, gi = indices # image, anchor, gridy, gridx Lcls, lbox, lobj = torch.zeros ( 1, device =device ), torch.zeros ( 1, device =device ), torch.zeros ( 1, device =device ) Self.BCEcls, self.BCEobj,, self.hyp, tobalance = BCEcls, BCEobj, 1.0, h, autobalanceĭef _call_ (self, p, targets ): # predictions, targets, model Self.ssi = list (det.stride ).index ( 16 ) if autobalance else 0 # stride 16 index Names = # list: only classes that have data Py.append (np.interp (px, mrec, mpre )) # precision at # Compute F1 (harmonic mean of precision and recall) P = np.interp (-px, -conf, precision, left = 1 ) # p at pr_score # AP from recall-precision curve for j in range (tp.shape ):Īp, mpre, mrec = compute_ap (recall, precision ) if plot and j = 0: Precision = tpc / (tpc + fpc ) # precision curve ![]() ![]() R = np.interp (-px, -conf, recall, left = 0 ) # negative x, xp because xp decreases # Precision Recall = tpc / (n_l + 1e-16 ) # recall curve N_p = i.sum ( ) # number of predictions if n_p = 0 or n_l = 0: N_l = (target_cls = c ).sum ( ) # number of labels Px, py = np.linspace ( 0, 1, 1000 ), # for plottingĪp, p, r = np.zeros ((nc, tp.shape )), np.zeros ((nc, 1000 )), np.zeros ((nc, 1000 )) for ci, c in enumerate (unique_classes ): Unique_classes = np.unique (target_cls ) nc = unique_classes.shape # number of classes, number of detections # Create Precision-Recall curve and compute AP for each class Tp, conf, pred_cls = tp, conf, pred_cls # Find unique classes The average precision as computed in py-faster-rcnn. Plot: Plot precision-recall curve at Plot save directory Target_cls: True object classes (nparray ). Pred_cls: Predicted object classes (nparray ). Tp: True positives (nparray, nx1 or nx10 ).Ĭonf: Objectness value from 0-1 (nparray ). """ Compute the average precision, given the recall and precision curves. W = # weights for * w ).sum ( 1 )ĭef ap_per_class (tp, conf, pred_cls, target_cls, plot =False, save_dir = '.', names = ( )): # Model fitness as a weighted combination of metrics 修改metrics.py # YOLOv5 □ by Ultralytics, GPL-3.0 license """ ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |