danielritchie commited on
Commit
d9c6ad3
·
1 Parent(s): 1e02e2d

initializing repo

Browse files
Files changed (3) hide show
  1. test.py +58 -0
  2. test_image.jpg +0 -0
  3. yolov8n_rubberducks.pt +3 -0
test.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from ultralytics import YOLO
3
+
4
+ # Suppress Ultralytics logging
5
+ logging.getLogger('ultralytics').setLevel(logging.WARNING)
6
+
7
+ # Define models and the test image
8
+ models = {
9
+ "yolov8n": "yolov8n.pt", # Pretrained model
10
+ "fine_tuned": "yolov8n_rubberducks.pt" # Fine-tuned model
11
+ }
12
+ image_path = "test_image.jpg"
13
+
14
+ # Initialize a dictionary to store results
15
+ performance = {}
16
+
17
+ # Run inference for each model
18
+ for model_name, model_path in models.items():
19
+ # Load the model
20
+ model = YOLO(model_path)
21
+
22
+ # Run inference on the test image
23
+ results = model(image_path)
24
+ first_result = results[0] # Extract the first result
25
+
26
+ # Count the number of detections (boxes)
27
+ num_detections = len(first_result.boxes) if hasattr(first_result, 'boxes') and first_result.boxes is not None else 0
28
+
29
+ # Calculate total confidence score of detections
30
+ if num_detections > 0:
31
+ total_confidence = sum(float(box.conf) for box in first_result.boxes) # Convert tensor to float
32
+ else:
33
+ total_confidence = 0.0 # No detections
34
+
35
+ # Store performance data
36
+ performance[model_name] = {
37
+ "detections": num_detections,
38
+ "confidence": total_confidence
39
+ }
40
+
41
+ # Extract results for comparison
42
+ yolo_detections = performance['yolov8n']['detections']
43
+ yolo_confidence = performance['yolov8n']['confidence']
44
+ fine_tuned_detections = performance['fine_tuned']['detections']
45
+ fine_tuned_confidence = performance['fine_tuned']['confidence']
46
+
47
+ # Calculate the difference
48
+ diff_detections = fine_tuned_detections - yolo_detections
49
+ diff_confidence = fine_tuned_confidence - yolo_confidence
50
+ detection_diff_word = "more" if diff_detections > 0 else "less"
51
+ confidence_diff_word = "more" if diff_confidence > 0 else "less"
52
+
53
+ # Print streamlined results
54
+ print()
55
+ print(f" YOLOv8n detected {yolo_detections} ducks with a total confidence of {yolo_confidence:.2f}")
56
+ print(f" The fine-tuned model detected {fine_tuned_detections} ducks with a total confidence of {fine_tuned_confidence:.2f}")
57
+ print(f" The fine-tuned model detects ducks with {abs(diff_confidence * 100):.0f}% {confidence_diff_word} confidence.")
58
+ print()
test_image.jpg ADDED
yolov8n_rubberducks.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:530eec1c0e78a72dd9f76b1be67403ec8528d7ad82655510d56930d94ab07cd4
3
+ size 6250531