updates
This commit is contained in:
		
							parent
							
								
									9e60e97a6c
								
							
						
					
					
						commit
						8af70386e8
					
				
							
								
								
									
										37
									
								
								test.py
								
								
								
								
							
							
						
						
									
										37
									
								
								test.py
								
								
								
								
							| 
						 | 
				
			
			@ -37,7 +37,7 @@ def test(
 | 
			
		|||
    # dataloader = torch.utils.data.DataLoader(LoadImagesAndLabels(test_path), batch_size=batch_size)  # pytorch
 | 
			
		||||
    dataloader = LoadImagesAndLabels(test_path, batch_size=batch_size, img_size=img_size)
 | 
			
		||||
 | 
			
		||||
    mean_mAP, mean_R, mean_P = 0.0, 0.0, 0.0
 | 
			
		||||
    mean_mAP, mean_R, mean_P, seen = 0.0, 0.0, 0.0, 0
 | 
			
		||||
    print('%11s' * 5 % ('Image', 'Total', 'P', 'R', 'mAP'))
 | 
			
		||||
    outputs, mAPs, mR, mP, TP, confidence, pred_class, target_class = [], [], [], [], [], [], [], []
 | 
			
		||||
    AP_accum, AP_accum_count = np.zeros(nC), np.zeros(nC)
 | 
			
		||||
| 
						 | 
				
			
			@ -47,10 +47,10 @@ def test(
 | 
			
		|||
 | 
			
		||||
        # Compute average precision for each sample
 | 
			
		||||
        for sample_i, (labels, detections) in enumerate(zip(targets, output)):
 | 
			
		||||
            correct = []
 | 
			
		||||
            seen += 1
 | 
			
		||||
 | 
			
		||||
            if detections is None:
 | 
			
		||||
                # If there are no detections but there are labels mask as zero AP
 | 
			
		||||
                # If there are labels but no detections mark as zero AP
 | 
			
		||||
                if labels.size(0) != 0:
 | 
			
		||||
                    mAPs.append(0), mR.append(0), mP.append(0)
 | 
			
		||||
                continue
 | 
			
		||||
| 
						 | 
				
			
			@ -60,6 +60,7 @@ def test(
 | 
			
		|||
            detections = detections[np.argsort(-detections[:, 4])]
 | 
			
		||||
 | 
			
		||||
            # If no labels add number of detections as incorrect
 | 
			
		||||
            correct = []
 | 
			
		||||
            if labels.size(0) == 0:
 | 
			
		||||
                # correct.extend([0 for _ in range(len(detections))])
 | 
			
		||||
                mAPs.append(0), mR.append(0), mP.append(0)
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +87,9 @@ def test(
 | 
			
		|||
                        correct.append(0)
 | 
			
		||||
 | 
			
		||||
            # Compute Average Precision (AP) per class
 | 
			
		||||
            AP, AP_class, R, P = ap_per_class(tp=correct, conf=detections[:, 4], pred_cls=detections[:, 6],
 | 
			
		||||
            AP, AP_class, R, P = ap_per_class(tp=correct,
 | 
			
		||||
                                              conf=detections[:, 4],
 | 
			
		||||
                                              pred_cls=detections[:, 6],
 | 
			
		||||
                                              target_cls=target_cls)
 | 
			
		||||
 | 
			
		||||
            # Accumulate AP per class
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +107,7 @@ def test(
 | 
			
		|||
            mean_P = np.mean(mP)
 | 
			
		||||
 | 
			
		||||
        # Print image mAP and running mean mAP
 | 
			
		||||
        print(('%11s%11s' + '%11.3g' * 3) % (len(mAPs), dataloader.nF, mean_P, mean_R, mean_mAP))
 | 
			
		||||
        print(('%11s%11s' + '%11.3g' * 3) % (seen, dataloader.nF, mean_P, mean_R, mean_mAP))
 | 
			
		||||
 | 
			
		||||
    # Print mAP per class
 | 
			
		||||
    print('%11s' * 5 % ('Image', 'Total', 'P', 'R', 'mAP') + '\n\nmAP Per Class:')
 | 
			
		||||
| 
						 | 
				
			
			@ -141,3 +144,27 @@ if __name__ == '__main__':
 | 
			
		|||
            opt.conf_thres,
 | 
			
		||||
            opt.nms_thres
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
#       Image      Total          P          R        mAP  # YOLOv3 320
 | 
			
		||||
#          32       5000       0.66      0.597      0.591
 | 
			
		||||
#          64       5000      0.664       0.62      0.604
 | 
			
		||||
#          96       5000      0.653      0.627      0.614
 | 
			
		||||
#         128       5000      0.639      0.623      0.607
 | 
			
		||||
#         160       5000      0.642       0.63      0.616
 | 
			
		||||
#         192       5000      0.651      0.636      0.621
 | 
			
		||||
 | 
			
		||||
#       Image      Total          P          R        mAP  # YOLOv3 416
 | 
			
		||||
#          32       5000      0.635      0.581       0.57
 | 
			
		||||
#          64       5000       0.63      0.591      0.578
 | 
			
		||||
#          96       5000      0.661      0.632      0.622
 | 
			
		||||
#         128       5000      0.659      0.632      0.623
 | 
			
		||||
#         160       5000      0.665       0.64      0.633
 | 
			
		||||
#         192       5000       0.66      0.637       0.63
 | 
			
		||||
 | 
			
		||||
#       Image      Total          P          R        mAP  # YOLOv3 608
 | 
			
		||||
#          32       5000      0.653      0.606      0.591
 | 
			
		||||
#          64       5000      0.653      0.635      0.625
 | 
			
		||||
#          96       5000      0.655      0.642      0.633
 | 
			
		||||
#         128       5000      0.667      0.651      0.642
 | 
			
		||||
#         160       5000      0.663      0.645      0.637
 | 
			
		||||
#         192       5000      0.663      0.643      0.634
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue