title: yolov5- how to get confusion matrix results in raw data
body: <p>I have tried everything that I know to get the raw data from the confusion matrix and the P and R values. Basically I want the tp, fp, ect in an array and I'm not sure how to do it. I can however print the results it's just very messy and I'd like to know if there's a simpler way. I'm running jupyter notebook if that matters.</p>
  <p>Right now I changed the val.py doc in the lines specified.</p>
  <p>line 153:</p>
  <pre><code>my_tp, my_fp = confusion_matrix.tp_fp()
  </code></pre>
  <p>line 292:
  I believe this return is from def run(...) on line 80 I just didn't want to post 300 lines of code.</p>
  <pre><code>return (mp, mr, map50, map, *(loss.cpu() / len(dataloader)).tolist()), maps, t, my_tp, my_fp, p, r
  </code></pre>
  <p>line 323:</p>
  <pre><code>def main(opt):
      check_requirements(requirements=ROOT / 'requirements.txt', exclude=('tensorboard', 'thop'))
  
      if opt.task in ('train', 'val', 'test'):  # run normally
          if opt.conf_thres &gt; 0.001:  # https://github.com/ultralytics/yolov5/issues/1466
              LOGGER.info(emojis(f'WARNING: confidence threshold {opt.conf_thres} &gt; 0.001 produces invalid results ⚠️'))
          a, b, c, d, e, f, g = run(**vars(opt))
          print(a, b, c, d, e, f, g, sep = '\n')
          return a, b, c, d, e, f, g
  </code></pre>
  <p>From my jupyter notebook:</p>
  <pre><code>a = !python yolov5/val.py --data yolov5/data/single.yaml --weights yolov5x.pt --task val --save-txt --save-conf
  </code></pre>
  <pre><code>for i in range (len(a)):
      print(a[i])
  </code></pre>
  <p>output:</p>
  <pre><code>val: data=yolov5/data/single.yaml, weights=['yolov5x.pt'], batch_size=32, imgsz=640, conf_thres=0.001, iou_thres=0.6, task=val, device=, workers=8, single_cls=False, augment=False, verbose=False, save_txt=True, save_hybrid=False, save_conf=True, save_json=False, project=yolov5\runs\val, name=exp, exist_ok=False, half=False, dnn=False
  YOLOv5  2022-6-25 Python-3.9.7 torch-1.12.0+cpu CPU
  
  Fusing layers... 
  YOLOv5x summary: 444 layers, 86705005 parameters, 0 gradients
  
  val: Scanning 'E:\Research\image_processing\horses\v5\single.cache' images and labels... 1 found, 0 missing, 0 empty, 0 corrupt: 100%|##########| 1/1 [00:00&lt;?, ?it/s]
  val: Scanning 'E:\Research\image_processing\horses\v5\single.cache' images and labels... 1 found, 0 missing, 0 empty, 0 corrupt: 100%|##########| 1/1 [00:00&lt;?, ?it/s]
  
                 Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95:   0%|          | 0/1 [00:00&lt;?, ?it/s]
                 Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100%|##########| 1/1 [00:02&lt;00:00,  2.56s/it]
                 Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100%|##########| 1/1 [00:02&lt;00:00,  2.56s/it]
                   all          1          1      0.973          1      0.995      0.398
  Speed: 1.0ms pre-process, 2082.7ms inference, 5.5ms NMS per image at shape (32, 3, 640, 640)
  Results saved to yolov5\runs\val\exp
  1 labels saved to yolov5\runs\val\exp\labels
  (0.9727806566317281, 1.0, 0.995, 0.398, 0.0, 0.0, 0.0)
  [      0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398
         0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398
         0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398       0.398
         0.398       0.398]
  (1.0023117065429688, 2082.702398300171, 5.471944808959961)
  [          0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           1           0           0           0           0           0           0           0           0
             0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0
             0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0
             0           0]
  [          0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0
             0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0
             0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0
             0           0]
  [    0.97278]
  [          1]
  </code></pre>
  <p>I would like for me to have x amount of variables and have them store the confusion matrix data, p, r, and the original output.</p>
  <p>Please let me know if you need more information I will be happy to give you anything you need.</p>